Merge pull request #17100 from abbradar/resume-delay
nixos stage-1: wait for resume devices to appear
This commit is contained in:
commit
db8401f603
@ -185,39 +185,6 @@ if test -n "$debug1devices"; then fail; fi
|
|||||||
@postDeviceCommands@
|
@postDeviceCommands@
|
||||||
|
|
||||||
|
|
||||||
# Try to resume - all modules are loaded now, and devices exist
|
|
||||||
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
|
|
||||||
echo 1 > /sys/power/tuxonice/do_resume || echo "failed to resume..."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test -e /sys/power/resume -a -e /sys/power/disk; then
|
|
||||||
if test -n "@resumeDevice@"; then
|
|
||||||
resumeDev="@resumeDevice@"
|
|
||||||
resumeInfo="$(udevadm info -q property "$resumeDev" )"
|
|
||||||
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 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
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
if test -e "$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..."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# Return true if the machine is on AC power, or if we can't determine
|
# Return true if the machine is on AC power, or if we can't determine
|
||||||
# whether it's on AC power.
|
# whether it's on AC power.
|
||||||
onACPower() {
|
onACPower() {
|
||||||
@ -348,6 +315,68 @@ mountFS() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# 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.
|
||||||
|
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
|
||||||
|
echo 1 > /sys/power/tuxonice/do_resume || echo "failed to resume..."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -e /sys/power/resume -a -e /sys/power/disk; then
|
||||||
|
if test -n "@resumeDevice@" && waitDevice "@resumeDevice@"; then
|
||||||
|
resumeDev="@resumeDevice@"
|
||||||
|
resumeInfo="$(udevadm info -q property "$resumeDev" )"
|
||||||
|
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 the hibernate
|
||||||
|
# image will reside. We can check all of them for swsuspend blkid.
|
||||||
|
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 -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..."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Try to find and mount the root device.
|
# Try to find and mount the root device.
|
||||||
mkdir -p $targetRoot
|
mkdir -p $targetRoot
|
||||||
|
|
||||||
@ -380,30 +409,12 @@ while read -u 3 mountPoint; do
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# USB storage devices tend to appear with some delay. It would be
|
if test -z "$pseudoDevice" && ! waitDevice "$device"; then
|
||||||
# great if we had a way to synchronously wait for them, but
|
# If it doesn't appear, try to mount it anyway (and
|
||||||
# alas... So just wait for a few seconds for the device to
|
|
||||||
# appear. If it doesn't appear, try to mount it anyway (and
|
|
||||||
# probably fail). This is a fallback for non-device "devices"
|
# probably fail). This is a fallback for non-device "devices"
|
||||||
# that we don't properly recognise.
|
# that we don't properly recognise.
|
||||||
if test -z "$pseudoDevice" -a ! -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
|
|
||||||
if [ $try -eq 0 ]; then
|
|
||||||
echo "Timed out waiting for device $device, trying to mount anyway."
|
echo "Timed out waiting for device $device, trying to mount anyway."
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
# Wait once more for the udev queue to empty, just in case it's
|
# Wait once more for the udev queue to empty, just in case it's
|
||||||
# doing something with $device right now.
|
# doing something with $device right now.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user