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-01-18 14:23:48 +01:00
|
|
|
overlay_dev=""
|
2017-12-09 21:51:48 +01:00
|
|
|
singleuser=0
|
|
|
|
|
|
|
|
for param in `cat /proc/cmdline`; do
|
|
|
|
case $param in
|
|
|
|
root=*)
|
|
|
|
root="${param##root=}"
|
|
|
|
;;
|
|
|
|
root_sfs=*)
|
|
|
|
root_sfs="${param##root_sfs=}"
|
|
|
|
;;
|
2018-01-18 14:23:48 +01:00
|
|
|
overlay_dev=*)
|
|
|
|
overlay_dev="${param##overlay_dev=}"
|
|
|
|
;;
|
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
|
|
|
|
|
|
|
|
if [ -z "${root_sfs}" ]; then
|
|
|
|
echo "No squashfs image specified!"
|
|
|
|
exec /bin/busybox sh
|
|
|
|
fi
|
|
|
|
|
|
|
|
while [ ! -e ${root} ]; do
|
|
|
|
echo "Waiting for root"
|
|
|
|
busybox sleep 1
|
|
|
|
done
|
|
|
|
|
2018-01-18 14:23:48 +01:00
|
|
|
# file system setup
|
|
|
|
overlay_mount() {
|
|
|
|
local lower=/newroot/${1}
|
|
|
|
local upper=/newroot/${2}
|
|
|
|
local work=/newroot/${2}_work
|
|
|
|
local target=/newroot/${3}
|
|
|
|
|
|
|
|
mount -t overlay overlay -olowerdir=${lower},upperdir=${upper},workdir=${work} ${target}
|
|
|
|
}
|
|
|
|
|
|
|
|
bind_mount() {
|
|
|
|
mount --bind /newroot/${1} /newroot/${2}
|
|
|
|
}
|
|
|
|
|
2017-12-09 21:51:48 +01:00
|
|
|
mount ${root} /images
|
|
|
|
|
|
|
|
if [ ! -e /images/${root_sfs} ]; then
|
|
|
|
echo "${root_sfs} not found!"
|
|
|
|
exec /bin/busybox sh
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
mount -t squashfs /images/${root_sfs} /newroot
|
|
|
|
mount -t devtmpfs none /newroot/dev
|
|
|
|
mount -t proc proc /newroot/proc
|
|
|
|
mount -t sysfs sysfs /newroot/sys
|
|
|
|
mount -t tmpfs none /newroot/tmp
|
|
|
|
mount -t tmpfs none /newroot/var
|
|
|
|
mount -t tmpfs none /newroot/run
|
|
|
|
|
|
|
|
chmod 755 /newroot/var
|
|
|
|
mkdir -p /newroot/run/log/journal
|
|
|
|
mkdir -p /newroot/var/log/fsck
|
|
|
|
mkdir -p /newroot/var/log/nginx
|
|
|
|
mkdir -p /newroot/var/log/mpd
|
|
|
|
mkdir -p /newroot/var/spool/
|
|
|
|
mkdir -p /newroot/var/lib/
|
|
|
|
mkdir -p /newroot/var/tmp
|
|
|
|
ln -s /run /newroot/var/run
|
|
|
|
ln -s /run/lock /newroot/var/lock
|
|
|
|
|
2018-01-18 14:23:48 +01:00
|
|
|
if [ ! -z "$overlay_dev" ]; then
|
|
|
|
while [ ! -e ${overlay_dev} ]; do
|
|
|
|
echo "Waiting for overlay device"
|
|
|
|
busybox sleep 1
|
|
|
|
done
|
|
|
|
|
|
|
|
mount ${overlay_dev} /newroot/cfg/overlay
|
|
|
|
|
|
|
|
overlay_mount "cfg/preserve/etc" "cfg/overlay/etc" "etc"
|
|
|
|
overlay_mount "cfg/preserve/var_lib" "cfg/overlay/var_lib" "var/lib"
|
|
|
|
else
|
|
|
|
bind_mount "cfg/preserve/etc" "etc"
|
|
|
|
bind_mount "cfg/preserve/var_lib" "var/lib"
|
|
|
|
fi
|
|
|
|
|
2017-12-09 21:51:48 +01:00
|
|
|
# cleanup mounts
|
|
|
|
umount -l /images
|
|
|
|
umount -l /dev
|
|
|
|
umount /sys
|
|
|
|
umount /proc
|
|
|
|
|
2018-01-18 21:22:09 +01:00
|
|
|
unset -v singleuser overlay_dev root root_sfs
|
|
|
|
|
|
|
|
exec /bin/busybox switch_root /newroot /bin/bash --login
|