Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tried this on debian 10 #12

Open
fivethreeo opened this issue Jun 20, 2024 · 3 comments
Open

Tried this on debian 10 #12

fivethreeo opened this issue Jun 20, 2024 · 3 comments

Comments

@fivethreeo
Copy link

fivethreeo commented Jun 20, 2024

rm -rf takeover
rm systemrescue.iso

wget https://downloads.sourceforge.net/project/systemrescuecd/sysresccd-x86/11.01/systemrescue-11.01-amd64.iso -O systemrescue.iso 
mount systemrescue.iso /mnt/
unsquashfs -f -d takeover/ /mnt/sysresccd/x86_64/airootfs.sfs
umount /mnt
rm systemrescue.iso
wget https://raw.githubusercontent.com/fivethreeo/takeover.sh/master/fakeinit.c -O takeover/fakeinit.c
wget https://raw.githubusercontent.com/fivethreeo/takeover.sh/master/takeover.sh -O takeover/takeover.sh
wget https://www.busybox.net/downloads/binaries/1.35.0-x86_64-linux-musl/busybox -O takeover/busybox
chmod u+x takeover/busybox
cp /etc/resolv.conf takeover/etc/
gcc takeover/fakeinit.c -o takeover/fakeinit
systemctl isolate rescue-ssh.target
sh takeover/takeover.sh

But I get

Init takeover successful
Pivoting root...
pivot_root: (null): Resource busy
Chrooting and running init...

@fivethreeo
Copy link
Author

Changed

./busybox echo "Pivoting root..."
./busybox mount --make-rprivate /
./busybox pivot_root . old_root
./busybox echo "Chrooting and running init..."

to

./busybox echo "Pivoting root..."
./busybox mount --make-rprivate /
./busybox unshare -m
./busybox pivot_root . old_root
./busybox echo "Chrooting and running init..."

@fivethreeo
Copy link
Author

cd /
sudo bash
rm -rf takeover
rm systemrescue.iso

wget https://downloads.sourceforge.net/project/systemrescuecd/sysresccd-x86/11.01/systemrescue-11.01-amd64.iso -O systemrescue.iso 
mount systemrescue.iso /mnt/
unsquashfs -f -d takeover/ /mnt/sysresccd/x86_64/airootfs.sfs
umount /mnt
rm systemrescue.iso
wget https://raw.githubusercontent.com/fivethreeo/takeover.sh/master/fakeinit.c -O takeover/fakeinit.c
wget https://raw.githubusercontent.com/fivethreeo/takeover.sh/master/takeover.sh -O takeover/takeover.sh
wget https://www.busybox.net/downloads/binaries/1.35.0-x86_64-linux-musl/busybox -O takeover/busybox
chmod u+x takeover/busybox
cp /etc/resolv.conf takeover/etc/
gcc takeover/fakeinit.c -o takeover/fakeinit
systemctl isolate rescue-ssh.target
sh takeover/takeover.sh

# Login on new sshd root@host

cd /
mkdir -p installer/tmp
cd installer/tmp
wget https://deb.debian.org/debian/dists/bookworm/main/installer-amd64/current/images/netboot/netboot.tar.gz
tar xzfv netboot.tar.gz
cd ..
zcat tmp/debian-installer/amd64/initrd | cpio -idmv
mount -t proc /proc proc/
mount --rbind /sys sys/
mount --rbind /dev dev/
killall -s SIGKILL agetty
killall -s SIGKILL dhclient
kill -9 `pgrep sshd | head -1` # other sshd
cp /etc/resolv.conf etc/

cat <<- EOF > preseed.cfg
d-i netcfg/enable boolean false
EOF

busybox chroot . /sbin/debian-installer-startup
busybox chroot . /sbin/debian-installer

Partitioning fails because of lvm modules

@fivethreeo
Copy link
Author

fivethreeo commented Jun 22, 2024

How far I got

cd /
sudo bash
rm -rf takeover
rm systemrescue.iso

wget https://downloads.sourceforge.net/project/systemrescuecd/sysresccd-x86/11.01/systemrescue-11.01-amd64.iso -O systemrescue.iso 
mount systemrescue.iso /mnt/
unsquashfs -f -d takeover/ /mnt/sysresccd/x86_64/airootfs.sfs
umount /mnt
rm systemrescue.iso
cp -R /lib/modules/`uname -r` takeover/lib/modules/`uname -r`
wget https://raw.githubusercontent.com/fivethreeo/takeover.sh/master/fakeinit.c -O takeover/fakeinit.c
wget https://raw.githubusercontent.com/fivethreeo/takeover.sh/master/takeover.sh -O takeover/takeover.sh
wget https://www.busybox.net/downloads/binaries/1.35.0-x86_64-linux-musl/busybox -O takeover/busybox
chmod u+x takeover/busybox
cp /etc/resolv.conf takeover/etc/
gcc takeover/fakeinit.c -o takeover/fakeinit
systemctl isolate rescue-ssh.target
sh takeover/takeover.sh

# Login on new sshd root@host

cd /
mkdir -p installer/tmp
cd installer/tmp
wget https://deb.debian.org/debian/dists/bookworm/main/installer-amd64/current/images/netboot/netboot.tar.gz
tar xzfv netboot.tar.gz
cd ..
zcat tmp/debian-installer/amd64/initrd | cpio -idmv

busybox rm -f etc/mtab
busybox ln -s /etc/mtab etc/mtab

busybox mount -t tmpfs tmp tmp
busybox mount -t proc proc proc
busybox mount -t sysfs sys sys

if ! busybox mount -t devtmpfs dev dev; then
    busybox mount -t tmpfs dev dev
    busybox cp -a /dev/* dev/
    busybox rm -rf dev/pts
    busybox mkdir dev/pts
fi
busybox mount --bind /dev/pts dev/pts

find /lib/modules/`uname -r`/kernel/drivers/block -type f -print0 | xargs -0 -I {} echo insmod {} >> blockmodules.sh

cat <<- EOF > preseed.cfg
d-i netcfg/enable boolean false
EOF

cp -R /lib/modules/`uname -r` lib/modules/`uname -r`

busybox chroot . /bin/sh
sh blockmodules.sh
/sbin/debian-installer-startup
/sbin/debian-installer

# open another ssh
cp /etc/resolv.conf /installer/etc/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant