mirror of
https://github.com/pygos/build.git
synced 2024-11-22 02:59:47 +01:00
More sophisticated filesystem setup from initrd
- Let us specify the "type" of the root and overlay filesystem. At the moment we have raw device that we wait for (default) and qemu virtio 9pfs. - If no squasfs image is specified, mount the root partition as root filesystem. - If no overlay device is specified, don't touch the new root filesystem. Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
This commit is contained in:
parent
2d74caf06b
commit
59d01432b1
1 changed files with 46 additions and 27 deletions
|
@ -10,7 +10,9 @@ busybox mount -t devtmpfs none /dev
|
||||||
|
|
||||||
root_sfs=""
|
root_sfs=""
|
||||||
root=""
|
root=""
|
||||||
|
root_type=""
|
||||||
overlay_dev=""
|
overlay_dev=""
|
||||||
|
overlay_type=""
|
||||||
singleuser=0
|
singleuser=0
|
||||||
|
|
||||||
for param in `cat /proc/cmdline`; do
|
for param in `cat /proc/cmdline`; do
|
||||||
|
@ -18,12 +20,18 @@ for param in `cat /proc/cmdline`; do
|
||||||
root=*)
|
root=*)
|
||||||
root="${param##root=}"
|
root="${param##root=}"
|
||||||
;;
|
;;
|
||||||
|
root_type=*)
|
||||||
|
root_type="${param##root_type=}"
|
||||||
|
;;
|
||||||
root_sfs=*)
|
root_sfs=*)
|
||||||
root_sfs="${param##root_sfs=}"
|
root_sfs="${param##root_sfs=}"
|
||||||
;;
|
;;
|
||||||
overlay_dev=*)
|
overlay_dev=*)
|
||||||
overlay_dev="${param##overlay_dev=}"
|
overlay_dev="${param##overlay_dev=}"
|
||||||
;;
|
;;
|
||||||
|
overlay_type=*)
|
||||||
|
overlay_type="${param##overlay_type=}"
|
||||||
|
;;
|
||||||
single*)
|
single*)
|
||||||
singleuser=1
|
singleuser=1
|
||||||
;;
|
;;
|
||||||
|
@ -35,49 +43,60 @@ if [ -z "${root}" ]; then
|
||||||
exec /bin/busybox sh
|
exec /bin/busybox sh
|
||||||
fi
|
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
|
|
||||||
|
|
||||||
# file system setup
|
# file system setup
|
||||||
mount ${root} /images
|
mount_device() {
|
||||||
|
local device="$1"
|
||||||
|
local mountpoint="$2"
|
||||||
|
local type="$3"
|
||||||
|
|
||||||
if [ ! -e /images/${root_sfs} ]; then
|
case $type in
|
||||||
echo "${root_sfs} not found!"
|
qemu)
|
||||||
exec /bin/busybox sh
|
mount -t 9p -o trans=virtio -oversion=9p2000.L $device $mountpoint
|
||||||
exit 1
|
;;
|
||||||
fi
|
*)
|
||||||
|
while [ ! -e $device ]; do
|
||||||
mount -t squashfs /images/${root_sfs} /newroot
|
echo "Waiting for device $device"
|
||||||
|
|
||||||
if [ ! -z "$overlay_dev" ]; then
|
|
||||||
while [ ! -e ${overlay_dev} ]; do
|
|
||||||
echo "Waiting for overlay device"
|
|
||||||
busybox sleep 1
|
busybox sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
mount ${overlay_dev} /newroot/cfg/overlay
|
mount $device $mountpoint
|
||||||
chroot /newroot mount -n -t overlay overlay -olowerdir=/cfg/preserve/etc,upperdir=/cfg/overlay/etc,workdir=/cfg/overlay/etc_work /etc
|
;;
|
||||||
|
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
|
else
|
||||||
chroot /newroot mount -n --bind /cfg/preserve/etc /etc
|
mount_device "$root" "/newroot" "$root_type"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -z "$overlay_dev" ]; then
|
||||||
|
mount_device "$overlay_dev" "/newroot/cfg/overlay" "$overlay_type"
|
||||||
|
|
||||||
|
chroot /newroot mount -n -t overlay overlay -olowerdir=/cfg/preserve/etc,upperdir=/cfg/overlay/etc,workdir=/cfg/overlay/etc_work /etc
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# cleanup mounts
|
# cleanup mounts
|
||||||
umount -l /images
|
|
||||||
umount -l /dev
|
umount -l /dev
|
||||||
umount /sys
|
umount /sys
|
||||||
umount /proc
|
umount /proc
|
||||||
|
|
||||||
|
# switch_root
|
||||||
|
unset -v overlay_dev root root_sfs overlay_type root_type
|
||||||
|
|
||||||
if [ "$singleuser" == "1" ]; then
|
if [ "$singleuser" == "1" ]; then
|
||||||
unset -v singleuser overlay_dev root root_sfs
|
unset -v singleuser
|
||||||
exec /bin/busybox switch_root /newroot /bin/bash
|
exec /bin/busybox switch_root /newroot /bin/bash
|
||||||
fi
|
fi
|
||||||
|
|
||||||
unset -v singleuser overlay_dev root root_sfs
|
unset -v singleuser
|
||||||
exec /bin/busybox switch_root /newroot /bin/init
|
exec /bin/busybox switch_root /newroot /bin/init
|
||||||
|
|
Loading…
Reference in a new issue