#!/bin/sh -e
# Set up filesystem as root and pivot into it.
echo "Setting up filesystem, please wait ..."

if [ "`uname -r | grep '^2.2.'`" = "" ]; then
	mount /proc
	umount initrd 2>/dev/null || true
	if mount -t tmpfs -o size=100M tmpfs /mnt ; then
		:
	else
		mount -t shm shm mnt
	fi
	umount /proc
	cp -a $(ls -1 / |grep -v '\(dev\|lost+found\|mnt\|proc\)') /mnt
	cd /mnt
	pivot_root . initrd
	mkdir proc dev
	mount /dev
	mount /dev/pts
	mount /proc

	# Close all open files on the initrd, and run busybox init.
	exec /usr/sbin/chroot . /bin/busybox init < /dev/console > /dev/console 2>&1
else
	rm /sbin/init
	mount /proc
	if grep VME /proc/hardware; then
		. /lib/debian-installer/detect-console
        if [ $TERM_TYPE = "serial" ]; then
                for i in 2 3 4 5; do
                        rm -f /dev/vc/$i
                done
        fi
	fi
	exec /usr/sbin/chroot . /bin/busybox init < /dev/console > /dev/console 2>&1
fi
