#!/bin/sh -x
#
# Find the CD-ROM and copy the root to ramdisk
#

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/
export PATH

ldconfig

umask 022
mkdir -p /ram /proc

mount -t proc none /proc

if ! find-cd; then
    echo "Unable to find CD-ROM" 1>&2
    bash -i
fi

mount -t ramfs none /ram
cd /ram
mkdir -p usr proc initrd
mount -r -t iso9660 /dev/cdrom /ram/usr
tar xfpz /ram/usr/root.tar.gz 2>/dev/null
cd /
cp -af /dev/cdrom /ram/dev

for arg in `cat /proc/cmdline`; do
    if [ "$arg" = initsh ]; then
	bash -i
    fi
done

umount /proc

# Switch roots and run init
cd /ram
pivot_root /ram /ram/initrd
exec /sbin/init "$@"
