Last active
August 16, 2024 14:01
-
-
Save natanael-b/3f30eda5094e825de3e80e128b666d79 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
[ ! "${EUID}" = "0" ] && { | |
echo "Migration must be done as roor" | |
exit | |
} | |
HERE="$(mktemp -d)" | |
# Install BusyBox toolchain | |
( | |
mkdir -p "${HERE}/system/bin/" | |
cd "${HERE}/system/bin/" | |
wget "https://www.busybox.net/downloads/binaries/1.35.0-x86_64-linux-musl/busybox" | |
chmod +x "busybox" | |
busybox --install . | |
) | |
# We will only use busybox | |
export PATH="${HERE}/system/bin/" | |
echo "Preparing current system..." | |
( | |
cd / | |
mkdir -p "/system/system.old" | |
for dir in var etc; do | |
echo " Binding /${dir}" | |
mv "/${dir}" "/usr" | |
rm -rf "/${dir}" | |
ln -fs "/usr/${dir}" "/${dir}" | |
done | |
echo " Binding /usr" | |
mv "/usr" "/system/system.old" | |
rm -rf "/usr" | |
ln -fs "/system/system.old/usr" "/usr" | |
# Resolve relative symlinks | |
for dir in proc run sys; do | |
ln -fs "/${dir}" "/system/system.old/usr/${dir}" | |
done | |
) | |
echo "Splitiog common directories..." | |
echo " Kernel" | |
( | |
cd "/system" | |
mkdir -p "system.common/etc" | |
mkdir -p "system.common/usr/lib" | |
mv "system.old/usr/etc/modprobe.d" "system.common/etc" | |
ln -s "/system/system.common/etc/modprobe.d/" "system.old/usr/etc/modprobe.d" | |
mv "system.old/usr/etc/modules-load.d" "system.common/etc" | |
ln -s "/system/system.common/etc/modules-load.d/" "system.old/usr/etc/modules-load.d" | |
mv "system.old/usr/lib/modules/" "system.common/usr/lib" | |
ln -s "/system/system.common/usr/lib/modules/" "system.old/usr/lib/" | |
) | |
echo " User and group metadata" | |
( | |
cd "/system" | |
mkdir -p "system.common/etc" | |
for file in passwd shadow group gshadow; do | |
echo " Binding /etc/${file}" | |
mv "system.old/usr/etc/${file}" "system.common/etc" | |
ln -s "/system/system.common/etc/${file}" "system.old/usr/etc/${file}" | |
done | |
) | |
echo " Flatpak" | |
( | |
cd "/system" | |
mkdir -p "system.common/var/lib" | |
mkdir -p "system.old/usr/var/lib/flatpak" | |
mv "system.old/usr/var/lib/flatpak" "system.common/var/lib" | |
ln -s "/system/system.common/var/lib/flatpak" "/system/system.old/usr/var/lib/flatpak" | |
) | |
rm -rf "${HERE}/system/bin/" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment