116 lines
2.1 KiB
Plaintext
Executable File
116 lines
2.1 KiB
Plaintext
Executable File
#!/busybox sh
|
|
|
|
die() {
|
|
echo ""
|
|
echo "Shit broke! Panic shell!"
|
|
echo ""
|
|
/busybox --install -s
|
|
exec /bin/sh
|
|
}
|
|
|
|
|
|
info() {
|
|
echo -n "-|-" ${@} "... "
|
|
}
|
|
|
|
isok() {
|
|
if [[ $1 -eq 0 ]]; then
|
|
echo "[ OK ]"
|
|
else
|
|
echo "[ FUCK ]"
|
|
die
|
|
fi
|
|
}
|
|
|
|
info "disabling console blanking, hopefully"
|
|
echo -e '\033[9;0]\033[14;0]' > /dev/console
|
|
|
|
info "waiting for usb devices to settle"
|
|
echo ""
|
|
for i in 10 9 8 7 6 5 4 3 2 1 0; do
|
|
echo -en ${i}'\r'
|
|
/busybox sleep 1
|
|
done
|
|
echo ""
|
|
isok 0
|
|
|
|
info "mounting devtmpfs"
|
|
/busybox mount -n -t devtmpfs devtmpfs ./dev
|
|
isok $?
|
|
|
|
info "mounting proc"
|
|
/busybox mount -n -t proc proc ./proc
|
|
isok $?
|
|
|
|
# rootfs_location_uuid=f822d881-d88a-4200-a9cf-6986c5a3e69a
|
|
info "looking for device with rootfs"
|
|
for var in $(cat /proc/cmdline); do
|
|
if [[ ${var/=*} = rootfs_location_uuid ]]; then
|
|
uuid="${var/*=}"
|
|
fi
|
|
done
|
|
device=$(findfs UUID=${uuid})
|
|
isok $?
|
|
|
|
# rootfs_filename=rootfs.tar.xz
|
|
info "getting rootfs filename"
|
|
for var in $(cat /proc/cmdline); do
|
|
if [[ ${var/=*} = rootfs_filename ]]; then
|
|
filename="${var/*=}"
|
|
fi
|
|
done
|
|
if [[ -z ${filename} ]]; then
|
|
info "going with default: rootfs.tar.xz"
|
|
filename="rootfs.tar.xz"
|
|
fi
|
|
isok 0
|
|
|
|
info "getting root tmpfs size"
|
|
for var in $(cat /proc/cmdline); do
|
|
if [[ ${var/=*} = rootfs_size ]]; then
|
|
size=${var/*=}
|
|
fi
|
|
done
|
|
if [[ -z ${size} ]]; then
|
|
info "going with default: 4G"
|
|
size="4G"
|
|
fi
|
|
isok 0
|
|
|
|
info "trying to mount ${device}"
|
|
/busybox mount -n -o ro ${device} /mnt
|
|
isok $?
|
|
|
|
info "trying to mount root tmpfs"
|
|
/busybox mount -n -o size=${size} -t tmpfs roottmpfs /roottmpfs
|
|
isok $?
|
|
|
|
info "checking if ${filename} exists"
|
|
[[ -e /mnt/${filename} ]]
|
|
isok $?
|
|
|
|
info "unpacking; will take some time"
|
|
/pv /mnt/${filename} | /busybox tar -C /roottmpfs -xJf -
|
|
|
|
info "unmounting rootfs package location"
|
|
/busybox umount -n /mnt
|
|
isok $?
|
|
|
|
info "unmounting /dev"
|
|
/busybox umount -n /dev
|
|
isok $?
|
|
|
|
info "unmounting /proc"
|
|
/busybox umount -n /proc
|
|
isok $?
|
|
|
|
info "trying to switch root"
|
|
exec /busybox switch_root /roottmpfs /sbin/init
|
|
|
|
echo ""
|
|
echo "we should not reach this place! here be dragons!"
|
|
echo ""
|
|
|
|
die
|
|
|