test v1 WIP

This commit is contained in:
root 2020-10-23 20:54:49 +00:00
commit 5192e2b062
1 changed files with 15 additions and 0 deletions

15
prepare_switch_root.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash
mkdir /tmp/tmproot && mount none /tmp/tmproot -t tmpfs
mkdir /tmp/tmproot/{proc,sys,usr,var,run,oldroot,root}
cp -ax /{bin,etc,mnt,sbin,lib} /tmp/tmproot/
cp -a /dev /tmp/tmproot/dev
lsof -Fn / | grep ^n/ | cut -c2- | sort -u | grep /usr | rsync -v --files-from=- / /tmp/tmproot/
NEEDED_BINARIES=(/usr/bin/wget /usr/bin/gzip /usr/bin/dd /usr/bin/mount /usr/bin/ls /usr/bin/cp /usr/bin/cat /usr/sbin/sshd /usr/bin/systemctl /lib/systemd/systemd)
for binary_path in "${NEEDED_BINARIES[@]}"
do
ldd $binary_path | grep -o '/lib[^ ]*' | sed 's/^/\/usr/' | xargs -n1 readlink -f | rsync -v --files-from=- / /tmp/tmproot/
ldd $binary_path | grep -o '/lib[^ ]*' | sed 's/^/\/usr/' | rsync -lv --files-from=- / /tmp/tmproot/
rsync -v $binary_path /tmp/tmproot$binary_path
done
rsync -lv /sbin/init /tmp/tmproot/sbin/init