diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..489fda8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/fakeinit diff --git a/README.md b/README.md index a7e7eec..50d6b5a 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,10 @@ handholding, this script is not for you. ## Compatibility -This script is designed for systems using sysvinit that support the `telinit u` -command to reload `/sbin/init`. If your system uses something else, you will -have to adapt it, or this might not work at all. You're on your own here. +This script is designed for init systems that support the `telinit u` command to +reload the init binary. This includes sysvinit and systemd. If your init system +works a different way, you will have to adapt it, or this might not work at +all. You're on your own here. You should always test this in a VM first. You can grab a tarball of your live root filesystem, extract it into a VM image, get your VM up and running (boot diff --git a/takeover.sh b/takeover.sh index 7c04fb2..784b142 100755 --- a/takeover.sh +++ b/takeover.sh @@ -2,7 +2,7 @@ set -e TO=/takeover -OLD_TELINIT=/sbin/telinit +OLD_INIT=$(readlink /proc/1/exe) PORT=80 cd "$TO" @@ -47,8 +47,7 @@ if [ "$a" != "OK" ] ; then fi ./busybox echo "Preparing init..." -./busybox cp $OLD_TELINIT tmp/telinit -./busybox cat >tmp/init <tmp/${OLD_INIT##*/} <"${TO}/${TTY}" 2>"${TO}/${TTY}" @@ -56,11 +55,12 @@ cd "${TO}" ./busybox echo "Init takeover successful" ./busybox echo "Pivoting root..." +./busybox mount --make-rprivate / ./busybox pivot_root . old_root ./busybox echo "Chrooting and running init..." exec ./busybox chroot . /fakeinit EOF -./busybox chmod +x tmp/init +./busybox chmod +x tmp/${OLD_INIT##*/} ./busybox echo "Starting secondary sshd" @@ -80,9 +80,9 @@ fi ./busybox echo "You may then kill the remnants of this session and any remaining" ./busybox echo "processes from your new SSH session, and umount the old root filesystem." -./busybox mount --bind tmp /sbin +./busybox mount --bind tmp/${OLD_INIT##*/} ${OLD_INIT} -./tmp/telinit u +telinit u ./busybox sleep 10