2006-12-10 23:29:44 +01:00
|
|
|
#! @staticShell@
|
2006-11-02 23:48:01 +01:00
|
|
|
|
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..."
|
2007-02-06 17:53:36 +01:00
|
|
|
echo "(Stage 1 init script is $stage2Init)"
|
2006-12-10 23:29:44 +01:00
|
|
|
exec @staticShell@
|
2006-11-10 15:38:15 +01:00
|
|
|
}
|
|
|
|
|
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
|
2007-05-28 16:09:04 +02:00
|
|
|
echo "<<< Wouters NixOS Stage 1 >>>"
|
2006-11-02 23:50:30 +01:00
|
|
|
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.
|
2006-11-27 02:35:34 +01:00
|
|
|
mkdir -p /etc # to shut up mount
|
2006-11-03 01:36:08 +01:00
|
|
|
touch /etc/fstab # idem
|
2006-11-27 02:35:34 +01:00
|
|
|
mkdir -p /proc
|
2006-11-04 01:18:22 +01:00
|
|
|
mount -t proc none /proc
|
2006-11-27 02:35:34 +01:00
|
|
|
mkdir -p /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 01:36:08 +01:00
|
|
|
# Load some kernel modules.
|
2006-12-19 23:12:44 +01:00
|
|
|
export MODULE_DIR=@modulesDir@/lib/modules/
|
|
|
|
for i in @modules@; do
|
|
|
|
modprobe $i
|
|
|
|
done
|
2006-11-03 10:45:06 +01:00
|
|
|
|
2006-11-10 15:38:15 +01:00
|
|
|
|
2007-01-10 13:42:28 +01:00
|
|
|
# Create device nodes in /dev.
|
|
|
|
mknod -m 0666 /dev/null c 1 3
|
|
|
|
export UDEV_CONFIG_FILE=/udev.conf
|
|
|
|
echo 'udev_rules="/no-rules"' > $UDEV_CONFIG_FILE
|
|
|
|
udevd --daemon
|
|
|
|
udevtrigger
|
|
|
|
udevsettle
|
|
|
|
|
|
|
|
|
2007-02-06 17:53:36 +01:00
|
|
|
# Function for mounting a file system.
|
|
|
|
mountFS() {
|
|
|
|
local device="$1"
|
|
|
|
local mountPoint="$2"
|
|
|
|
local options="$3"
|
|
|
|
|
|
|
|
# Check the root device, if .
|
|
|
|
mustCheck=
|
|
|
|
if test -b "$device"; then
|
|
|
|
mustCheck=1
|
|
|
|
else
|
|
|
|
case $device in
|
|
|
|
LABEL=*)
|
|
|
|
mustCheck=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test -n "$mustCheck"; then
|
|
|
|
fsck -C -a "$device"
|
|
|
|
fsckResult=$?
|
|
|
|
|
|
|
|
if test $(($fsckResult | 2)) = $fsckResult; then
|
|
|
|
echo "fsck finished, rebooting..."
|
|
|
|
sleep 3
|
|
|
|
# reboot -f -d !!! don't have reboot yet
|
|
|
|
fail
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test $(($fsckResult | 4)) = $fsckResult; then
|
|
|
|
echo "$device has unrepaired errors, please fix them manually."
|
|
|
|
fail
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test $fsckResult -ge 8; then
|
|
|
|
echo "fsck on $device failed."
|
|
|
|
fail
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Mount read-writable.
|
|
|
|
mount -n -o "$options" "$device" /mnt/root$mountPoint || fail
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2007-05-28 16:09:04 +02:00
|
|
|
echo "mounting the root device.... (fix: sleeping 5 seconds to wait for upcoming usb drivers)"
|
|
|
|
sleep 5
|
|
|
|
|
2006-11-12 19:48:47 +01:00
|
|
|
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-12-23 02:16:39 +01:00
|
|
|
for i in /sys/block/*; do
|
|
|
|
if test "$(cat $i/removable)" = "1"; then
|
2006-11-10 15:38:15 +01:00
|
|
|
|
2006-12-23 02:16:39 +01:00
|
|
|
echo " in $(basename $i)..."
|
2006-11-10 15:38:15 +01:00
|
|
|
|
2006-12-23 02:16:39 +01:00
|
|
|
set -- $(IFS=: ; echo $(cat $i/dev))
|
|
|
|
major="$1"
|
|
|
|
minor="$2"
|
2006-11-10 15:38:15 +01:00
|
|
|
|
2006-12-23 02:16:39 +01:00
|
|
|
# Create a device node for this device.
|
|
|
|
rm -f /dev/tmpdev
|
|
|
|
mknod /dev/tmpdev b "$major" "$minor"
|
|
|
|
|
|
|
|
if mount -n -o ro -t iso9660 /dev/tmpdev /mnt/root; then
|
2006-11-12 19:48:47 +01:00
|
|
|
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
|
|
|
|
|
2007-02-06 17:53:36 +01:00
|
|
|
# Hard-coded root device(s).
|
|
|
|
mountPoints=(@mountPoints@)
|
|
|
|
devices=(@devices@)
|
|
|
|
fsTypes=(@fsTypes@)
|
|
|
|
optionss=(@optionss@)
|
|
|
|
|
|
|
|
for ((n = 0; n < ${#mountPoints[*]}; n++)); do
|
|
|
|
mountPoint=${mountPoints[$n]}
|
|
|
|
device=${devices[$n]}
|
|
|
|
fsType=${fsTypes[$n]}
|
|
|
|
options=${optionss[$n]}
|
|
|
|
|
|
|
|
# !!! Really quick hack to support bind mounts, i.e., where
|
|
|
|
# the "device" should be taken relative to /mnt/root, not /.
|
|
|
|
# Assume that every device that doesn't start with /dev or
|
|
|
|
# LABEL= is a bind mount.
|
|
|
|
case $device in
|
|
|
|
/dev/*)
|
|
|
|
;;
|
|
|
|
LABEL=*)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
device=/mnt/root$device
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
echo "mounting $device on $mountPoint..."
|
|
|
|
|
|
|
|
mountFS "$device" "$mountPoint" "$options"
|
|
|
|
done
|
|
|
|
|
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
|
|
|
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
|