#!/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 -p /proc
mount /proc
mkdir -p /sys
mount /sys
/lib/debian-installer/start-udev

# 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
