2017-12-09 21:51:48 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
PATH=/bin
|
|
|
|
|
|
|
|
/bin/busybox --install
|
|
|
|
busybox sleep 1
|
|
|
|
busybox mount -t proc proc /proc
|
|
|
|
busybox mount -t sysfs sysfs /sys
|
|
|
|
busybox mount -t devtmpfs none /dev
|
|
|
|
|
|
|
|
root_sfs=""
|
|
|
|
root=""
|
2018-10-01 17:35:46 +02:00
|
|
|
root_type="hwdevice"
|
2018-01-18 14:23:48 +01:00
|
|
|
overlay_dev=""
|
2018-10-01 17:35:46 +02:00
|
|
|
overlay_type="hwdevice"
|
2017-12-09 21:51:48 +01:00
|
|
|
singleuser=0
|
|
|
|
|
|
|
|
for param in `cat /proc/cmdline`; do
|
|
|
|
case $param in
|
|
|
|
root=*)
|
|
|
|
root="${param##root=}"
|
|
|
|
;;
|
2018-09-29 18:03:22 +02:00
|
|
|
root_type=*)
|
|
|
|
root_type="${param##root_type=}"
|
|
|
|
;;
|
2017-12-09 21:51:48 +01:00
|
|
|
root_sfs=*)
|
|
|
|
root_sfs="${param##root_sfs=}"
|
|
|
|
;;
|
2018-01-18 14:23:48 +01:00
|
|
|
overlay_dev=*)
|
|
|
|
overlay_dev="${param##overlay_dev=}"
|
|
|
|
;;
|
2018-09-29 18:03:22 +02:00
|
|
|
overlay_type=*)
|
|
|
|
overlay_type="${param##overlay_type=}"
|
|
|
|
;;
|
2017-12-09 21:51:48 +01:00
|
|
|
single*)
|
|
|
|
singleuser=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z "${root}" ]; then
|
|
|
|
echo "No root drive specified!"
|
|
|
|
exec /bin/busybox sh
|
|
|
|
fi
|
|
|
|
|
2018-09-29 18:03:22 +02:00
|
|
|
# file system setup
|
|
|
|
mount_device() {
|
|
|
|
local device="$1"
|
|
|
|
local mountpoint="$2"
|
|
|
|
local type="$3"
|
2017-12-09 21:51:48 +01:00
|
|
|
|
2018-09-29 18:03:22 +02:00
|
|
|
case $type in
|
|
|
|
qemu)
|
|
|
|
mount -t 9p -o trans=virtio -oversion=9p2000.L $device $mountpoint
|
|
|
|
;;
|
2018-10-01 17:35:46 +02:00
|
|
|
hwdevice)
|
2018-09-29 18:03:22 +02:00
|
|
|
while [ ! -e $device ]; do
|
|
|
|
echo "Waiting for device $device"
|
|
|
|
busybox sleep 1
|
|
|
|
done
|
2017-12-09 21:51:48 +01:00
|
|
|
|
2018-09-29 18:03:22 +02:00
|
|
|
mount $device $mountpoint
|
|
|
|
;;
|
2018-10-01 17:35:46 +02:00
|
|
|
*)
|
|
|
|
mount -t $type $device $mountpoint
|
|
|
|
;;
|
2018-09-29 18:03:22 +02:00
|
|
|
esac
|
|
|
|
}
|
2017-12-09 21:51:48 +01:00
|
|
|
|
2018-09-29 18:03:22 +02:00
|
|
|
if [ ! -z "$root_sfs" ]; then
|
|
|
|
mount_device "$root" "/images" "$root_type"
|
|
|
|
|
|
|
|
if [ ! -e /images/${root_sfs} ]; then
|
|
|
|
echo "${root_sfs} not found!"
|
|
|
|
exec /bin/busybox sh
|
|
|
|
exit 1
|
|
|
|
fi
|
2017-12-09 21:51:48 +01:00
|
|
|
|
2018-09-29 18:03:22 +02:00
|
|
|
mount -t squashfs /images/${root_sfs} /newroot
|
|
|
|
umount -l /images
|
|
|
|
else
|
|
|
|
mount_device "$root" "/newroot" "$root_type"
|
|
|
|
fi
|
2017-12-09 21:51:48 +01:00
|
|
|
|
2018-01-18 14:23:48 +01:00
|
|
|
if [ ! -z "$overlay_dev" ]; then
|
2018-09-29 18:03:22 +02:00
|
|
|
mount_device "$overlay_dev" "/newroot/cfg/overlay" "$overlay_type"
|
2018-01-18 14:23:48 +01:00
|
|
|
|
2018-10-01 17:35:46 +02:00
|
|
|
mkdir -p /newroot/cfg/overlay/etc
|
|
|
|
mkdir -p /newroot/cfg/overlay/etc_work
|
|
|
|
mkdir -p /newroot/cfg/overlay/var_lib
|
|
|
|
mkdir -p /newroot/cfg/overlay/var_lib_work
|
|
|
|
mkdir -p /newroot/cfg/overlay/usr
|
|
|
|
mkdir -p /newroot/cfg/overlay/usr_work
|
|
|
|
|
2018-04-06 23:27:26 +02:00
|
|
|
chroot /newroot mount -n -t overlay overlay -olowerdir=/cfg/preserve/etc,upperdir=/cfg/overlay/etc,workdir=/cfg/overlay/etc_work /etc
|
2018-10-01 17:35:46 +02:00
|
|
|
else
|
|
|
|
chroot /newroot mount --bind "/cfg/preserve/etc" "/etc"
|
2018-01-18 14:23:48 +01:00
|
|
|
fi
|
|
|
|
|
2017-12-09 21:51:48 +01:00
|
|
|
# cleanup mounts
|
|
|
|
umount -l /dev
|
|
|
|
umount /sys
|
|
|
|
umount /proc
|
|
|
|
|
2018-09-29 18:03:22 +02:00
|
|
|
# switch_root
|
|
|
|
unset -v overlay_dev root root_sfs overlay_type root_type
|
|
|
|
|
2018-03-04 16:35:28 +01:00
|
|
|
if [ "$singleuser" == "1" ]; then
|
2018-09-29 18:03:22 +02:00
|
|
|
unset -v singleuser
|
2018-03-04 16:35:28 +01:00
|
|
|
exec /bin/busybox switch_root /newroot /bin/bash
|
|
|
|
fi
|
2018-02-08 20:44:18 +01:00
|
|
|
|
2018-09-29 18:03:22 +02:00
|
|
|
unset -v singleuser
|
2018-03-04 16:35:28 +01:00
|
|
|
exec /bin/busybox switch_root /newroot /bin/init
|