From 986a40421a94528c55531719fb382160292c7e16 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Mon, 8 Aug 2016 01:35:43 +0300 Subject: [PATCH] nixos stage-1: wait for devices during resumption attempt Also a microimprovement -- use `test -n` instead of `test -e` since we have already checked that the file exists. --- nixos/modules/system/boot/stage-1-init.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/nixos/modules/system/boot/stage-1-init.sh b/nixos/modules/system/boot/stage-1-init.sh index fc50481e0bc8b9..ef04629d735f69 100644 --- a/nixos/modules/system/boot/stage-1-init.sh +++ b/nixos/modules/system/boot/stage-1-init.sh @@ -346,7 +346,7 @@ waitDevice() { } -# Try to resume - all modules are loaded now, and devices exist +# Try to resume - all modules are loaded now. if test -e /sys/power/tuxonice/resume; then if test -n "$(cat /sys/power/tuxonice/resume)"; then echo 0 > /sys/power/tuxonice/user_interface/enabled @@ -355,7 +355,7 @@ if test -e /sys/power/tuxonice/resume; then fi if test -e /sys/power/resume -a -e /sys/power/disk; then - if test -n "@resumeDevice@"; then + if test -n "@resumeDevice@" && waitDevice "@resumeDevice@"; then resumeDev="@resumeDevice@" resumeInfo="$(udevadm info -q property "$resumeDev" )" else @@ -364,14 +364,16 @@ if test -e /sys/power/resume -a -e /sys/power/disk; then # https://bugs.launchpad.net/ubuntu/+source/pm-utils/+bug/923326/comments/1 # when there are multiple swap devices, we can't know where the hibernate # image will reside. We can check all of them for swsuspend blkid. - resumeInfo="$(test -e "$sd" && udevadm info -q property "$sd")" - if [ "$(echo "$resumeInfo" | sed -n 's/^ID_FS_TYPE=//p')" = "swsuspend" ]; then - resumeDev="$sd" - break + if waitDevice "$sd"; then + resumeInfo="$(udevadm info -q property "$sd")" + if [ "$(echo "$resumeInfo" | sed -n 's/^ID_FS_TYPE=//p')" = "swsuspend" ]; then + resumeDev="$sd" + break + fi fi done fi - if test -e "$resumeDev"; then + if test -n "$resumeDev"; then resumeMajor="$(echo "$resumeInfo" | sed -n 's/^MAJOR=//p')" resumeMinor="$(echo "$resumeInfo" | sed -n 's/^MINOR=//p')" echo "$resumeMajor:$resumeMinor" > /sys/power/resume 2> /dev/null || echo "failed to resume..."