#!/bin/sh -e
# Set up filesystem as root and pivot into it.
export PATH
. /lib/debian-installer/init-debug
debugshell "just booted"

echo "Setting up filesystem, please wait ..."

mount /proc
umount initrd 2>/dev/null || true
if mount -t tmpfs -o size=100M tmpfs /mnt ; then
	:
elif mount -t shm shm mnt; then
	:
else
	mount -t ramfs ramfs /mnt
fi
umount /proc
cp -a $(ls -1 / | grep -v '\(lost+found\|mnt\|proc\)') /mnt
cd /mnt
pivot_root . initrd
mkdir proc
if [ -x /sbin/udevd ]; then
	/lib/debian-installer/init-udev-devices
else
	echo "udev is missing. Giving up!" >&2
	sleep 5000
	exit
fi
mount /proc

# Close all open files on the initrd, and run busybox init.
debugshell "before init"
exec /usr/sbin/chroot . /bin/busybox init < /dev/console > /dev/console 2>&1
