about summary refs log tree commit diff
path: root/nixos/modules/system
diff options
context:
space:
mode:
authorIhor Antonov <ngortheone@gmail.com>2018-05-09 10:15:16 -0400
committerTuomas Tynkkynen <tuomas.tynkkynen@iki.fi>2018-05-12 02:55:33 +0300
commit08ebd830a559692f9b34a1619cca44b1888468a0 (patch)
tree8630368f698780704a48f434a158c81827202220 /nixos/modules/system
parente4777ae2d84c5f38740b744fe85e305f1a2f0209 (diff)
downloadnixlib-08ebd830a559692f9b34a1619cca44b1888468a0.tar
nixlib-08ebd830a559692f9b34a1619cca44b1888468a0.tar.gz
nixlib-08ebd830a559692f9b34a1619cca44b1888468a0.tar.bz2
nixlib-08ebd830a559692f9b34a1619cca44b1888468a0.tar.lz
nixlib-08ebd830a559692f9b34a1619cca44b1888468a0.tar.xz
nixlib-08ebd830a559692f9b34a1619cca44b1888468a0.tar.zst
nixlib-08ebd830a559692f9b34a1619cca44b1888468a0.zip
Fix kernel crash caused by absent root device
Diffstat (limited to 'nixos/modules/system')
-rw-r--r--nixos/modules/system/boot/grow-partition.nix2
-rw-r--r--nixos/modules/system/boot/stage-1-init.sh50
2 files changed, 27 insertions, 25 deletions
diff --git a/nixos/modules/system/boot/grow-partition.nix b/nixos/modules/system/boot/grow-partition.nix
index 1e6f9e442b67..8c9b1502558a 100644
--- a/nixos/modules/system/boot/grow-partition.nix
+++ b/nixos/modules/system/boot/grow-partition.nix
@@ -30,7 +30,7 @@ with lib;
 
     boot.initrd.postDeviceCommands = ''
       rootDevice="${config.fileSystems."/".device}"
-      if [ -e "$rootDevice" ]; then
+      if waitDevice "$rootDevice"; then
         rootDevice="$(readlink -f "$rootDevice")"
         parentDevice="$rootDevice"
         while [ "''${parentDevice%[0-9]}" != "''${parentDevice}" ]; do
diff --git a/nixos/modules/system/boot/stage-1-init.sh b/nixos/modules/system/boot/stage-1-init.sh
index 964ec68cfe2f..1facf419ed06 100644
--- a/nixos/modules/system/boot/stage-1-init.sh
+++ b/nixos/modules/system/boot/stage-1-init.sh
@@ -74,6 +74,32 @@ ln -s /proc/mounts /etc/mtab # to shut up mke2fs
 touch /etc/udev/hwdb.bin # to shut up udev
 touch /etc/initrd-release
 
+# Function for waiting a device to appear.
+waitDevice() {
+    local device="$1"
+
+    # USB storage devices tend to appear with some delay.  It would be
+    # great if we had a way to synchronously wait for them, but
+    # alas...  So just wait for a few seconds for the device to
+    # appear.
+    if test ! -e $device; then
+        echo -n "waiting for device $device to appear..."
+        try=20
+        while [ $try -gt 0 ]; do
+            sleep 1
+            # also re-try lvm activation now that new block devices might have appeared
+            lvm vgchange -ay
+            # and tell udev to create nodes for the new LVs
+            udevadm trigger --action=add
+            if test -e $device; then break; fi
+            echo -n "."
+            try=$((try - 1))
+        done
+        echo
+        [ $try -ne 0 ]
+    fi
+}
+
 # Mount special file systems.
 specialMount() {
   local device="$1"
@@ -377,31 +403,7 @@ lustrateRoot () {
     exec 4>&-
 }
 
-# Function for waiting a device to appear.
-waitDevice() {
-    local device="$1"
 
-    # USB storage devices tend to appear with some delay.  It would be
-    # great if we had a way to synchronously wait for them, but
-    # alas...  So just wait for a few seconds for the device to
-    # appear.
-    if test ! -e $device; then
-        echo -n "waiting for device $device to appear..."
-        try=20
-        while [ $try -gt 0 ]; do
-            sleep 1
-            # also re-try lvm activation now that new block devices might have appeared
-            lvm vgchange -ay
-            # and tell udev to create nodes for the new LVs
-            udevadm trigger --action=add
-            if test -e $device; then break; fi
-            echo -n "."
-            try=$((try - 1))
-        done
-        echo
-        [ $try -ne 0 ]
-    fi
-}
 
 
 # Try to resume - all modules are loaded now.