summary refs log tree commit diff
path: root/nixos/modules/system
diff options
context:
space:
mode:
authorTyson Whitehead <twhitehead@gmail.com>2021-02-25 15:27:02 -0500
committerTyson Whitehead <twhitehead@gmail.com>2021-02-25 15:58:18 -0500
commitaed7c9a22a8e9c28735a903359a948e50b0b7eb5 (patch)
tree3a9126a2016112a0396212e8093986221981643c /nixos/modules/system
parentfb3970ef7d144525dfcd1c39c0d0d122d248b185 (diff)
downloadnixpkgs-aed7c9a22a8e9c28735a903359a948e50b0b7eb5.tar
nixpkgs-aed7c9a22a8e9c28735a903359a948e50b0b7eb5.tar.gz
nixpkgs-aed7c9a22a8e9c28735a903359a948e50b0b7eb5.tar.bz2
nixpkgs-aed7c9a22a8e9c28735a903359a948e50b0b7eb5.tar.lz
nixpkgs-aed7c9a22a8e9c28735a903359a948e50b0b7eb5.tar.xz
nixpkgs-aed7c9a22a8e9c28735a903359a948e50b0b7eb5.tar.zst
nixpkgs-aed7c9a22a8e9c28735a903359a948e50b0b7eb5.zip
stage-1: accept init symlinks at any level
Diffstat (limited to 'nixos/modules/system')
-rw-r--r--nixos/modules/system/boot/stage-1-init.sh15
1 files changed, 10 insertions, 5 deletions
diff --git a/nixos/modules/system/boot/stage-1-init.sh b/nixos/modules/system/boot/stage-1-init.sh
index 5b39f34200c..ddaf985878e 100644
--- a/nixos/modules/system/boot/stage-1-init.sh
+++ b/nixos/modules/system/boot/stage-1-init.sh
@@ -614,11 +614,16 @@ echo /sbin/modprobe > /proc/sys/kernel/modprobe
 
 
 # Start stage 2.  `switch_root' deletes all files in the ramfs on the
-# current root.  Note that $stage2Init might be an absolute symlink,
-# in which case "-e" won't work because we're not in the chroot yet.
-if [ ! -e "$targetRoot/$stage2Init" ] && [ ! -L "$targetRoot/$stage2Init" ] ; then
-    echo "stage 2 init script ($targetRoot/$stage2Init) not found"
-    fail
+# current root.  The path has to be valid in the chroot not outside.
+if [ ! -e "$targetRoot/$stage2Init" ]; then
+    stage2Check=${stage2Init}
+    while [ "$stage2Check" != "${stage2Check%/*}" ] && [ ! -L "$targetRoot/$stage2Check" ]; do
+        stage2Check=${stage2Check%/*}
+    done
+    if [ ! -L "$targetRoot/$stage2Check" ]; then
+        echo "stage 2 init script ($targetRoot/$stage2Init) not found"
+        fail
+    fi
 fi
 
 mkdir -m 0755 -p $targetRoot/proc $targetRoot/sys $targetRoot/dev $targetRoot/run