2006-11-02 23:48:01 +01:00
|
|
|
#! @shell@
|
|
|
|
|
2006-11-10 15:38:15 +01:00
|
|
|
fail() {
|
|
|
|
# If starting stage 2 failed, start an interactive shell.
|
|
|
|
echo "Stage 2 failed, starting emergency shell..."
|
|
|
|
exec @shell@
|
|
|
|
}
|
|
|
|
|
2006-11-12 19:48:47 +01:00
|
|
|
|
2006-11-02 23:48:01 +01:00
|
|
|
# Print a greeting.
|
2006-11-02 23:50:30 +01:00
|
|
|
echo
|
|
|
|
echo "<<< NixOS Stage 1 >>>"
|
|
|
|
echo
|
2006-11-02 23:48:01 +01:00
|
|
|
|
2006-11-12 19:48:47 +01:00
|
|
|
|
2006-11-02 23:48:01 +01:00
|
|
|
# Set the PATH.
|
|
|
|
export PATH=/empty
|
|
|
|
for i in @path@; do
|
|
|
|
PATH=$PATH:$i/bin
|
2006-11-03 01:36:08 +01:00
|
|
|
if test -e $i/sbin; then
|
|
|
|
PATH=$PATH:$i/sbin
|
|
|
|
fi
|
2006-11-02 23:48:01 +01:00
|
|
|
done
|
|
|
|
|
2006-11-12 19:48:47 +01:00
|
|
|
|
2006-11-03 01:36:08 +01:00
|
|
|
# Mount special file systems.
|
|
|
|
mkdir /etc # to shut up mount
|
|
|
|
touch /etc/fstab # idem
|
|
|
|
mkdir /proc
|
2006-11-04 01:18:22 +01:00
|
|
|
mount -t proc none /proc
|
2006-11-03 01:36:08 +01:00
|
|
|
mkdir /sys
|
2006-11-04 01:18:22 +01:00
|
|
|
mount -t sysfs none /sys
|
2006-11-03 01:36:08 +01:00
|
|
|
|
2006-11-12 19:48:47 +01:00
|
|
|
|
2006-11-24 01:04:29 +01:00
|
|
|
# Process the kernel command line.
|
|
|
|
stage2Init=@stage2Init@
|
|
|
|
for o in $(cat /proc/cmdline); do
|
|
|
|
case $o in
|
|
|
|
init=*)
|
|
|
|
set -- $(IFS==; echo $o)
|
|
|
|
stage2Init=$2
|
|
|
|
;;
|
|
|
|
debugtrace)
|
|
|
|
# Show each command.
|
|
|
|
set -x
|
|
|
|
;;
|
|
|
|
debug1)
|
|
|
|
fail
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
|
2006-11-03 00:58:06 +01:00
|
|
|
# Create device nodes in /dev.
|
|
|
|
source @makeDevices@
|
|
|
|
|
2006-11-12 19:48:47 +01:00
|
|
|
|
2006-11-03 01:36:08 +01:00
|
|
|
# Load some kernel modules.
|
2006-11-03 12:47:40 +01:00
|
|
|
export MODULE_DIR=@modules@/lib/modules/
|
2006-11-03 10:45:06 +01:00
|
|
|
modprobe ide-generic
|
|
|
|
modprobe ide-disk
|
|
|
|
modprobe ide-cd
|
|
|
|
|
2006-11-10 15:38:15 +01:00
|
|
|
|
2006-11-12 19:48:47 +01:00
|
|
|
# Try to find and mount the root device.
|
2006-11-03 10:45:06 +01:00
|
|
|
mkdir /mnt
|
2006-11-12 19:48:47 +01:00
|
|
|
mkdir /mnt/root
|
|
|
|
|
|
|
|
echo "mounting the root device..."
|
|
|
|
|
|
|
|
if test -n "@autoDetectRootDevice@"; then
|
2006-11-10 15:38:15 +01:00
|
|
|
|
2006-11-12 19:48:47 +01:00
|
|
|
# Look for the root device by label.
|
|
|
|
echo "probing for the NixOS installation CD..."
|
2006-11-10 15:38:15 +01:00
|
|
|
|
2006-11-12 19:48:47 +01:00
|
|
|
for i in /sys/devices/*/*/media; do
|
|
|
|
if test "$(cat $i)" = "cdrom"; then
|
2006-11-10 15:38:15 +01:00
|
|
|
|
2006-11-12 19:48:47 +01:00
|
|
|
# Hopefully `drivename' matches the device created in /dev.
|
|
|
|
devName=/dev/$(cat $(dirname $i)/drivename)
|
2006-11-10 15:38:15 +01:00
|
|
|
|
2006-11-12 19:48:47 +01:00
|
|
|
echo " in $devName..."
|
2006-11-10 15:38:15 +01:00
|
|
|
|
2006-11-12 19:48:47 +01:00
|
|
|
if mount -o ro -t iso9660 $devName /mnt/root; then
|
|
|
|
if test -e "/mnt/root/@rootLabel@"; then
|
|
|
|
found=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
umount /mnt/root
|
2006-11-10 15:38:15 +01:00
|
|
|
fi
|
|
|
|
|
2006-11-12 19:48:47 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if test -z "$found"; then
|
|
|
|
echo "CD not found!"
|
|
|
|
fail
|
2006-11-10 15:38:15 +01:00
|
|
|
fi
|
|
|
|
|
2006-11-12 19:48:47 +01:00
|
|
|
else
|
|
|
|
|
|
|
|
# Hard-coded root device.
|
|
|
|
mount -o ro "@rootDevice@" /mnt/root
|
|
|
|
|
2006-11-10 15:38:15 +01:00
|
|
|
fi
|
2006-11-03 01:36:08 +01:00
|
|
|
|
2006-11-24 01:04:29 +01:00
|
|
|
|
2006-11-06 23:21:50 +01:00
|
|
|
# Start stage 2.
|
|
|
|
# !!! Note: we can't use pivot_root here (the kernel gods have
|
|
|
|
# decreed), but we could use run-init from klibc, which deletes all
|
|
|
|
# files in the initramfs, remounts the target root on /, and chroots.
|
2006-11-12 19:48:47 +01:00
|
|
|
cd /mnt/root
|
2006-11-06 23:21:50 +01:00
|
|
|
mount --move . /
|
|
|
|
umount /proc # cleanup
|
|
|
|
umount /sys
|
2006-11-13 12:41:27 +01:00
|
|
|
|
2006-11-24 01:04:29 +01:00
|
|
|
echo "INIT = $stage2Init"
|
|
|
|
|
|
|
|
if test -z "$stage2Init"; then fail; fi
|
|
|
|
|
|
|
|
exec chroot . $stage2Init
|
2006-11-04 01:01:13 +01:00
|
|
|
|
2006-11-10 15:38:15 +01:00
|
|
|
fail
|