mirror of
https://github.com/pygos/build.git
synced 2024-11-25 12:20:42 +01:00
e61ca9decf
- Directly pass the device type to the mount command - Use the special default type "hwdevice" to wait for a device node before mounting it - Initialize the overlay partition from the initrd script - Do the bind mount setup as document Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
114 lines
2.2 KiB
Bash
114 lines
2.2 KiB
Bash
#!/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=""
|
|
root_type="hwdevice"
|
|
overlay_dev=""
|
|
overlay_type="hwdevice"
|
|
singleuser=0
|
|
|
|
for param in `cat /proc/cmdline`; do
|
|
case $param in
|
|
root=*)
|
|
root="${param##root=}"
|
|
;;
|
|
root_type=*)
|
|
root_type="${param##root_type=}"
|
|
;;
|
|
root_sfs=*)
|
|
root_sfs="${param##root_sfs=}"
|
|
;;
|
|
overlay_dev=*)
|
|
overlay_dev="${param##overlay_dev=}"
|
|
;;
|
|
overlay_type=*)
|
|
overlay_type="${param##overlay_type=}"
|
|
;;
|
|
single*)
|
|
singleuser=1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [ -z "${root}" ]; then
|
|
echo "No root drive specified!"
|
|
exec /bin/busybox sh
|
|
fi
|
|
|
|
# file system setup
|
|
mount_device() {
|
|
local device="$1"
|
|
local mountpoint="$2"
|
|
local type="$3"
|
|
|
|
case $type in
|
|
qemu)
|
|
mount -t 9p -o trans=virtio -oversion=9p2000.L $device $mountpoint
|
|
;;
|
|
hwdevice)
|
|
while [ ! -e $device ]; do
|
|
echo "Waiting for device $device"
|
|
busybox sleep 1
|
|
done
|
|
|
|
mount $device $mountpoint
|
|
;;
|
|
*)
|
|
mount -t $type $device $mountpoint
|
|
;;
|
|
esac
|
|
}
|
|
|
|
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
|
|
|
|
mount -t squashfs /images/${root_sfs} /newroot
|
|
umount -l /images
|
|
else
|
|
mount_device "$root" "/newroot" "$root_type"
|
|
fi
|
|
|
|
if [ ! -z "$overlay_dev" ]; then
|
|
mount_device "$overlay_dev" "/newroot/cfg/overlay" "$overlay_type"
|
|
|
|
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
|
|
|
|
chroot /newroot mount -n -t overlay overlay -olowerdir=/cfg/preserve/etc,upperdir=/cfg/overlay/etc,workdir=/cfg/overlay/etc_work /etc
|
|
else
|
|
chroot /newroot mount --bind "/cfg/preserve/etc" "/etc"
|
|
fi
|
|
|
|
# cleanup mounts
|
|
umount -l /dev
|
|
umount /sys
|
|
umount /proc
|
|
|
|
# switch_root
|
|
unset -v overlay_dev root root_sfs overlay_type root_type
|
|
|
|
if [ "$singleuser" == "1" ]; then
|
|
unset -v singleuser
|
|
exec /bin/busybox switch_root /newroot /bin/bash
|
|
fi
|
|
|
|
unset -v singleuser
|
|
exec /bin/busybox switch_root /newroot /bin/init
|