1
0
Fork 0
mirror of https://github.com/pygos/build.git synced 2024-11-22 19:19:46 +01:00
build/pkg/initrd/initrd.skel

84 lines
1.5 KiB
Text
Raw Normal View History

#!/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=""
overlay_dev=""
singleuser=0
for param in `cat /proc/cmdline`; do
case $param in
root=*)
root="${param##root=}"
;;
root_sfs=*)
root_sfs="${param##root_sfs=}"
;;
overlay_dev=*)
overlay_dev="${param##overlay_dev=}"
;;
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
# file system setup
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
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
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 -n --bind /cfg/preserve/etc /etc
fi
# cleanup mounts
umount -l /images
umount -l /dev
umount /sys
umount /proc
if [ "$singleuser" == "1" ]; then
unset -v singleuser overlay_dev root root_sfs
exec /bin/busybox switch_root /newroot /bin/bash
fi
unset -v singleuser overlay_dev root root_sfs
exec /bin/busybox switch_root /newroot /bin/init