#!/bin/sh

. /dfs_startup_funcs
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export PATH
rootmnt=/realroot

echo "------------------------------------------------------------"
echo " *** Welcome to Debian From Scratch (DFS) ***"
echo "Initial RAM disk (format 2, without initramfs-tools) booting."
echo "------------------------------------------------------------"

echo Mounting proc
mount -n -t proc none /proc
echo Mounting sys
mount -n -t sysfs none /sys

sleep 5

while true; do
        if scandevices; then 
            sleep 5
            umount /sys
            umount /proc
            cd $rootmnt
            pivot_root . initrd
            echo " *** Now booting system from $DFSDEVICE ***"
            exec chroot . /sbin/init "$@"
        else
            echo "Could not find DFS CD.  Sleeping 10 seconds to let"
            echo "devices settle, then will try again."
            sleep 10
        fi
done
