cat <<E_O_F >> $ROOT/etc/uniontab
/etc
/home
/root
/var/mail
E_O_F


cat <<E_O_F >> $ROOT/etc/hotplug/usb/usb-storage
#!/bin/sh

cd /etc/hotplug
. ./hotplug.functions

mesg Found USB storage, waiting 10 seconds for device ready...
/bin/sleep 10
mesg Trying to mount partition with label \"usbroot\"...
/bin/mount -L usbroot /mnt/usbroot && mesg "Mounted successfully." || mesg "Mount failed."
grep -ve '^\(#\|\$\)' /etc/uniontab |while read mntpt; do
    if [ -d \$mntpt ] && [ -d /mnt/usbroot/\$mntpt ]; then
	mesg "Adding unionfs rw branch for \$mntpt on usb..."
	/usr/sbin/unionctl \$mntpt --add --mode rw /mnt/usbroot/\$mntpt && mesg "success." || mesg "failed."
    fi
done

mesg "Trying set up clock with usb overlay settings (if any)..."
/etc/init.d/clock start && mesg "success." || mesg "failed."
mesg "Trying restart network with usb overlay settings (if any)..."
/etc/init.d/network restart && mesg "success." || mesg "failed."

E_O_F

$in_chroot /bin/chmod 755 /etc/hotplug/usb/usb-storage
$in_chroot /bin/mkdir /mnt/usbroot
