A minimal init script
[Posted November 17, 2006 by corbet]
Here is a minimal init script, part of Michael Hammel's
article on small root
filesystems.
#!/bin/sh
LABEL="MYTHBOX_CD"
DEVS=`echo /dev/hd* /dev/sr*`
while [ -z "$CDROM" ] && [ "$TIMEOUT" != "..............." ] ; do
for DEV in $DEVS ; do
if [ "`isoinfo -V $DEV 2>/dev/null`" = "$LABEL" ] ; then
CDROM=$DEV
fi
done
if [ -z "$CDROM" ] ; then
echo -n "."
TIMEOUT=".$TIMEOUT"
sleep 1
fi
done
if [ -z "$CDROM" ] ; then
echo "Cannot find MythBox Live CD."
echo "This probably means that your IDE or SCSI controller is not supported."
exit 1
else
echo "MythBox Live CD is $CDROM"
fi
mount -w -t tmpfs -o size=90% tmpfs /.tmpfs
mkdir /.tmpfs/.overlay
# Probably redundant, but might be useful in the future for ejecting the CD
mkdir -p /.tmpfs/.overlay/dev/shm /.tmpfs/.overlay/proc
mkdir -m1777 /.tmpfs/.overlay/tmp
mkdir /.tmpfs/.cdrom
mkdir /.tmpfs/.sqfs
# Work around unionfs bug that causes tst-cancel16 glibc test to fail in Ch5
mkdir -m1777 /.tmpfs/.tmp
mount -r -t iso9660 $CDROM /.tmpfs/.cdrom
losetup /dev/loop0 /.tmpfs/.cdrom/.root.sqfs
mount -r -t squashfs /dev/loop0 /.tmpfs/.sqfs
# Load the UnionFS module from the LiveCD.
insmod /lib/unionfs.ko
# Join the overlay, cdrom and squashfs directories as a single directory
# under /.union
mount -w -t unionfs -o dirs=/.tmpfs/.overlay=rw:/.tmpfs/.cdrom=ro:/.tmpfs/.sqfs=ro unionfs /.union
# Then move the tmpfs directory (why?)
mount -o move /.tmpfs /.union/dev/shm
# Make the cdrom accessible as a device under the unionfs mount point.
ln -s $CDROM /.union/dev/MythBox-cd
# Make the tmp directory on the tmpfs accessible as tmp under the unionfs
# mount point.
mount -o bind /.union/dev/shm/.tmp /.union/tmp
# Now make the unionfs mount point the new root directory
# LFS LiveCD used to use klibc's "run-init"
# exec run-init /.union /sbin/init
# Busybox uses switch_root
exec switch_root /.union /sbin/init 3
echo ""
echo "### switch_root failed - falling back to shell. ###"
echo ""
exec /bin/sh
(
Log in to post comments)