@@ -2,7 +2,22 @@
22
33systemConfig=@systemConfig@
44
5−export HOME=/root
5+export HOME=/root PATH="@path@"
6+
7+
8+# Process the kernel command line.
9+for o in $(</proc/cmdline); do
10+ case $o in
11+ boot.debugtrace)
12+ # Show each command.
13+ set -x
14+ ;;
15+ resume=*)
16+ set -- $(IFS==; echo $o)
17+ resumeDevice=$2
18+ ;;
19+ esac
20+done
621
722
823# Print a greeting.
@@ -11,21 +26,6 @@ echo -e "\e[1;32m<<< NixOS Stage 2 >>>\e[0m"
1126echo
1227
1328
14−# Set the PATH.
15−setPath() {
16− local dirs="$1"
17− export PATH=/empty
18− for i in $dirs; do
19− PATH=$PATH:$i/bin
20− if test -e $i/sbin; then
21− PATH=$PATH:$i/sbin
22− fi
23− done
24−}
25−
26−setPath "@path@"
27−
28−
2929# Normally, stage 1 mounts the root filesystem read/writable.
3030# However, in some environments, stage 2 is executed directly, and the
3131# root is read-only. So make it writable here.
@@ -61,7 +61,9 @@ echo "booting system configuration $systemConfig" > /dev/kmsg
6161chown -f 0:30000 /nix/store
6262chmod -f 1775 /nix/store
6363if [ -n "@readOnlyStore@" ]; then
64− if ! readonly-mountpoint /nix/store; then
64+ if ! [[ "$(findmnt --noheadings --output OPTIONS /nix/store)" =~ ro(,|$) ]]; then
65+ # FIXME when linux < 4.5 is EOL, switch to atomic bind mounts
66+ #mount /nix/store /nix/store -o bind,remount,ro
6567 mount --bind /nix/store /nix/store
6668 mount -o remount,ro,bind /nix/store
6769 fi
@@ -75,31 +77,12 @@ rm -f /etc/mtab* # not that we care about stale locks
7577ln -s /proc/mounts /etc/mtab
7678
7779
78−# Process the kernel command line.
79−for o in $(cat /proc/cmdline); do
80− case $o in
81− boot.debugtrace)
82− # Show each command.
83− set -x
84− ;;
85− resume=*)
86− set -- $(IFS==; echo $o)
87− resumeDevice=$2
88− ;;
89− esac
90−done
91−
92−
9380# More special file systems, initialise required directories.
9481[ -e /proc/bus/usb ] && mount -t usbfs usbfs /proc/bus/usb # UML doesn't have USB by default
9582mkdir -m 01777 -p /tmp
96−mkdir -m 0755 -p /var /var/log /var/lib /var/db
97−mkdir -m 0755 -p /nix/var
98−mkdir -m 0700 -p /root
99−chmod 0700 /root
100−mkdir -m 0755 -p /bin # for the /bin/sh symlink
101−mkdir -m 0755 -p /home
102−mkdir -m 0755 -p /etc/nixos
83+mkdir -m 0755 -p /var/{log,lib,db} /nix/var /etc/nixos/ \
84+ /run/lock /home /bin # for the /bin/sh symlink
85+install -m 0700 -d /root
10386
10487
10588# Miscellaneous boot time cleanup.
@@ -111,9 +94,6 @@ rm -f /etc/{group,passwd,shadow}.lock
11194rm -rf /nix/var/nix/gcroots/tmp /nix/var/nix/temproots
11295
11396
114−mkdir -m 0755 -p /run/lock
115−
116−
11797# For backwards compatibility, symlink /var/run to /run, and /var/lock
11898# to /run/lock.
11999ln -s /run /var/run
@@ -127,8 +107,8 @@ fi
127107
128108
129109# Use /etc/resolv.conf supplied by systemd-nspawn, if applicable.
130−if [ -n "@useHostResolvConf@" -a -e /etc/resolv.conf ]; then
131− cat /etc/resolv.conf | resolvconf -m 1000 -a host
110+if [ -n "@useHostResolvConf@" ] && [ -e /etc/resolv.conf ]; then
111+ resolvconf -m 1000 -a host </etc/resolv.conf
132112fi
133113
134114# Log the script output to /dev/kmsg or /run/log/stage-2-init.log.