@@ -185,39 +185,6 @@ if test -n "$debug1devices"; then fail; fi
185185@postDeviceCommands@
186186
187187
188−# Try to resume - all modules are loaded now, and devices exist
189−if test -e /sys/power/tuxonice/resume; then
190− if test -n "$(cat /sys/power/tuxonice/resume)"; then
191− echo 0 > /sys/power/tuxonice/user_interface/enabled
192− echo 1 > /sys/power/tuxonice/do_resume || echo "failed to resume..."
193− fi
194−fi
195−
196−if test -e /sys/power/resume -a -e /sys/power/disk; then
197− if test -n "@resumeDevice@"; then
198− resumeDev="@resumeDevice@"
199− resumeInfo="$(udevadm info -q property "$resumeDev" )"
200− else
201− for sd in @resumeDevices@; do
202− # Try to detect resume device. According to Ubuntu bug:
203− # https://bugs.launchpad.net/ubuntu/+source/pm-utils/+bug/923326/comments/1
204− # when there are multiple swap devices, we can't know where the hibernate
205− # image will reside. We can check all of them for swsuspend blkid.
206− resumeInfo="$(test -e "$sd" && udevadm info -q property "$sd")"
207− if [ "$(echo "$resumeInfo" | sed -n 's/^ID_FS_TYPE=//p')" = "swsuspend" ]; then
208− resumeDev="$sd"
209− break
210− fi
211− done
212− fi
213− if test -e "$resumeDev"; then
214− resumeMajor="$(echo "$resumeInfo" | sed -n 's/^MAJOR=//p')"
215− resumeMinor="$(echo "$resumeInfo" | sed -n 's/^MINOR=//p')"
216− echo "$resumeMajor:$resumeMinor" > /sys/power/resume 2> /dev/null || echo "failed to resume..."
217− fi
218−fi
219−
220−
221188# Return true if the machine is on AC power, or if we can't determine
222189# whether it's on AC power.
223190onACPower() {
@@ -348,6 +315,68 @@ mountFS() {
348315}
349316
350317
318+# Function for waiting a device to appear.
319+waitDevice() {
320+ local device="$1"
321+
322+ # USB storage devices tend to appear with some delay. It would be
323+ # great if we had a way to synchronously wait for them, but
324+ # alas... So just wait for a few seconds for the device to
325+ # appear.
326+ if test ! -e $device; then
327+ echo -n "waiting for device $device to appear..."
328+ try=20
329+ while [ $try -gt 0 ]; do
330+ sleep 1
331+ # also re-try lvm activation now that new block devices might have appeared
332+ lvm vgchange -ay
333+ # and tell udev to create nodes for the new LVs
334+ udevadm trigger --action=add
335+ if test -e $device; then break; fi
336+ echo -n "."
337+ try=$((try - 1))
338+ done
339+ echo
340+ [ $try -ne 0 ]
341+ fi
342+}
343+
344+
345+# Try to resume - all modules are loaded now.
346+if test -e /sys/power/tuxonice/resume; then
347+ if test -n "$(cat /sys/power/tuxonice/resume)"; then
348+ echo 0 > /sys/power/tuxonice/user_interface/enabled
349+ echo 1 > /sys/power/tuxonice/do_resume || echo "failed to resume..."
350+ fi
351+fi
352+
353+if test -e /sys/power/resume -a -e /sys/power/disk; then
354+ if test -n "@resumeDevice@" && waitDevice "@resumeDevice@"; then
355+ resumeDev="@resumeDevice@"
356+ resumeInfo="$(udevadm info -q property "$resumeDev" )"
357+ else
358+ for sd in @resumeDevices@; do
359+ # Try to detect resume device. According to Ubuntu bug:
360+ # https://bugs.launchpad.net/ubuntu/+source/pm-utils/+bug/923326/comments/1
361+ # when there are multiple swap devices, we can't know where the hibernate
362+ # image will reside. We can check all of them for swsuspend blkid.
363+ if waitDevice "$sd"; then
364+ resumeInfo="$(udevadm info -q property "$sd")"
365+ if [ "$(echo "$resumeInfo" | sed -n 's/^ID_FS_TYPE=//p')" = "swsuspend" ]; then
366+ resumeDev="$sd"
367+ break
368+ fi
369+ fi
370+ done
371+ fi
372+ if test -n "$resumeDev"; then
373+ resumeMajor="$(echo "$resumeInfo" | sed -n 's/^MAJOR=//p')"
374+ resumeMinor="$(echo "$resumeInfo" | sed -n 's/^MINOR=//p')"
375+ echo "$resumeMajor:$resumeMinor" > /sys/power/resume 2> /dev/null || echo "failed to resume..."
376+ fi
377+fi
378+
379+
351380# Try to find and mount the root device.
352381mkdir -p $targetRoot
353382
@@ -380,29 +409,11 @@ while read -u 3 mountPoint; do
380409 ;;
381410 esac
382411
383− # USB storage devices tend to appear with some delay. It would be
384− # great if we had a way to synchronously wait for them, but
385− # alas... So just wait for a few seconds for the device to
386− # appear. If it doesn't appear, try to mount it anyway (and
387− # probably fail). This is a fallback for non-device "devices"
388− # that we don't properly recognise.
389− if test -z "$pseudoDevice" -a ! -e $device; then
390− echo -n "waiting for device $device to appear..."
391− try=20
392− while [ $try -gt 0 ]; do
393− sleep 1
394− # also re-try lvm activation now that new block devices might have appeared
395− lvm vgchange -ay
396− # and tell udev to create nodes for the new LVs
397− udevadm trigger --action=add
398− if test -e $device; then break; fi
399− echo -n "."
400− try=$((try - 1))
401− done
402− echo
403− if [ $try -eq 0 ]; then
404− echo "Timed out waiting for device $device, trying to mount anyway."
405− fi
412+ if test -z "$pseudoDevice" && ! waitDevice "$device"; then
413+ # If it doesn't appear, try to mount it anyway (and
414+ # probably fail). This is a fallback for non-device "devices"
415+ # that we don't properly recognise.
416+ echo "Timed out waiting for device $device, trying to mount anyway."
406417 fi
407418
408419 # Wait once more for the udev queue to empty, just in case it's