exec &> /chroot_boot.log

# Kill all other processes
PIDS=` ps --no-headers -o pid= -N -s $(ps -p $$ --no-headers -o sid )  `
kill -9 $PIDS

init U

echo Running processes:
ps aux
echo

(
# Wait for processes to release resources
sleep 4

# Unmount old root
for mount_point in `cat /proc/mounts | grep old_root | awk '{ print length($2) " " $2; }' $file | sort -r -n | cut -d ' ' -f 2-` ; do
	[ -d $mount_point ] || continue
	umount -n $mount_point
	if [ $? -ne 0 ]; then
		echo WARNING: Failed to unmount $mount_point
		echo lsof $mount_point :
		lsof $mount_point
		umount -nl $mount_point
	fi
done

if [ "$( ls /old_root | wc -l )" == "0" ]; then
	rm -r /old_root || echo WARNING: Failed to remove old root mount point
else
	echo WARNING: old_root directory was not empty
fi

) &

# Make sure the watchdog won't trigger
[ -e "/dev/watchdog" ] && echo V > /dev/watchdog

# /proc will be remounted by rcS
umount /proc

echo Booting rootfs...

# Boot-time system configuration/initialization script
# We currently don't have a vt, we need to allocate one
deallocvt 1
openvt -c 1 -w -- /etc/init.d/rcS

# Force reload of runlevel 5
init S
init 5
