summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-09-24 18:05:53 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-09-24 18:05:53 +0200
commit38d57b4a94af281c8f935d2ceed0bd476ceeb25e (patch)
tree258a2e32eda7cd322481073c7448187d6c9b36c1 /nixos
parent39d93963808c60da0403402a55edb32e83621bcb (diff)
parentba31749458d8b6179768888aeb1194c3114ac902 (diff)
downloadnixlib-38d57b4a94af281c8f935d2ceed0bd476ceeb25e.tar
nixlib-38d57b4a94af281c8f935d2ceed0bd476ceeb25e.tar.gz
nixlib-38d57b4a94af281c8f935d2ceed0bd476ceeb25e.tar.bz2
nixlib-38d57b4a94af281c8f935d2ceed0bd476ceeb25e.tar.lz
nixlib-38d57b4a94af281c8f935d2ceed0bd476ceeb25e.tar.xz
nixlib-38d57b4a94af281c8f935d2ceed0bd476ceeb25e.tar.zst
nixlib-38d57b4a94af281c8f935d2ceed0bd476ceeb25e.zip
Merge pull request #4244 from abbradar/resume
Replace resumeDevice with autodetection of hibernation partition
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/system/boot/stage-1-init.sh21
-rw-r--r--nixos/modules/system/boot/stage-1.nix16
2 files changed, 28 insertions, 9 deletions
diff --git a/nixos/modules/system/boot/stage-1-init.sh b/nixos/modules/system/boot/stage-1-init.sh
index 73fc6ce543cf..f14f105ef239 100644
--- a/nixos/modules/system/boot/stage-1-init.sh
+++ b/nixos/modules/system/boot/stage-1-init.sh
@@ -168,9 +168,24 @@ if test -e /sys/power/tuxonice/resume; then
     fi
 fi
 
-if test -n "@resumeDevice@" -a -e /sys/power/resume -a -e /sys/power/disk; then
-    echo "@resumeDevice@" > /sys/power/resume 2> /dev/null || echo "failed to resume..."
-    echo shutdown > /sys/power/disk
+if test -e /sys/power/resume -a -e /sys/power/disk; then
+    if test -n "@resumeDevice@"; then
+        resumeDev="@resumeDevice@"
+    else
+        for sd in @resumeDevices@; do
+            # Try to detect resume device. According to Ubuntu bug:
+            # https://bugs.launchpad.net/ubuntu/+source/pm-utils/+bug/923326/comments/1
+            # When there are multiple swap devices, we can't know where will hibernate
+            # image reside. We can check all of them for swsuspend blkid.
+            if [ "$(udevadm info -q property "$sd" | sed -n 's/^ID_FS_TYPE=//p')" = "swsuspend" ]; then
+                resumeDev="$sd"
+                break
+            fi
+        done
+    fi
+    if test -n "$resumeDev"; then
+        echo "$resumeDev" > /sys/power/resume 2> /dev/null || echo "failed to resume..."
+    fi
 fi
 
 
diff --git a/nixos/modules/system/boot/stage-1.nix b/nixos/modules/system/boot/stage-1.nix
index 6977880fa284..1ec11e70e845 100644
--- a/nixos/modules/system/boot/stage-1.nix
+++ b/nixos/modules/system/boot/stage-1.nix
@@ -181,6 +181,9 @@ let
     inherit (config.boot.initrd) checkJournalingFS
       preLVMCommands postDeviceCommands postMountCommands kernelModules;
 
+    resumeDevices = map (sd: if sd ? device then sd.device else "/dev/disk/by-label/${sd.label}")
+                    (filter (sd: sd ? label || hasPrefix "/dev/" sd.device) config.swapDevices);
+
     fsInfo =
       let f = fs: [ fs.mountPoint (if fs.device != null then fs.device else "/dev/disk/by-label/${fs.label}") fs.fsType fs.options ];
       in pkgs.writeText "initrd-fsinfo" (concatStringsSep "\n" (concatMap f fileSystems));
@@ -220,13 +223,14 @@ in
   options = {
 
     boot.resumeDevice = mkOption {
-      type = types.nullOr types.str;
-      default = null;
-      example = "8:2";
+      type = types.str;
+      default = "";
+      example = "/dev/sda3";
       description = ''
-        Device for manual resume attempt during boot, specified using
-        the device's major and minor number as
-        <literal><replaceable>major</replaceable>:<replaceable>minor</replaceable></literal>.
+        Device for manual resume attempt during boot. This should be used primarily
+        if you want to resume from file. Specify here the device where the file
+        resides. You should also use <varname>boot.kernelParams</varname> to specify
+        <literal><replaceable>resume_offset</replaceable></literal>.
       '';
     };