|
1 | | -__version__ = "0.3.1" |
| 1 | +__version__ = "0.4.0" |
2 | 2 |
|
3 | 3 |
|
4 | 4 | def handle_resume(self) -> None: |
5 | 5 | """Returns a bash script handling resume from hibernation. |
6 | 6 | Checks that /sys/power/resume is writable, resume= is set, and noresume is not set, if so, |
7 | | - it checks ifthe specified device exists, then echo's the resume device to /sys/power/resume. |
8 | | - In the event of failure, it prints an error message and a list of block devices. |
| 7 | + checks if PARTUUID= is in the resume var, and tries to use blkid to find the resume device. |
| 8 | + If the specified device exists, writes resume device to /sys/power/resume. |
| 9 | + In the event of failure, it prints an error message, a list of block devuices, then runs rd_fail. |
| 10 | +
|
| 11 | +
|
| 12 | + Resuming or failing to do so is potentially dangerous. |
| 13 | + If the system was hibernated, and fails to resume, it will be in an inconsistent state. |
| 14 | + If the system is freshly booted, it will not be able to resume, as there is no hibernation image. |
| 15 | + Distinguising between a fresh boot and missing/borked hibernation image is not possible at run time. |
9 | 16 | """ |
10 | | - out_str = [ |
11 | | - 'if ! check_var noresume && [ -n "$(readvar resume)" ] && [ -w /sys/power/resume ]; then', |
12 | | - ' if [ -e "$(readvar resume)" ]; then', |
13 | | - ' einfo "Resuming from: $(readvar resume)"', |
14 | | - " readvar resume > /sys/power/resume", |
15 | | - ' eerror "Failed to resume from $(readvar resume)"', |
16 | | - ' eerror "Resume device not found: $(readvar resume)"', |
| 17 | + return [ |
| 18 | + "resumeval=$(readvar resume)", # read the cmdline resume var |
| 19 | + 'if ! check_var noresume && [ -n "$resumeval" ] && [ -w /sys/power/resume ]; then', |
| 20 | + ' if echo "$resumeval" | grep -q "PARTUUID="; then', # resolve partuuid to device |
| 21 | + ' resume=$(blkid -t "$resumeval" -o device)', |
| 22 | + " else", |
| 23 | + " resume=$resumeval", |
| 24 | + " fi", |
| 25 | + ' if [ -e "$resume" ]; then', # Check if the resume device exists |
| 26 | + ' einfo "Resuming from: $resume"', |
| 27 | + ' echo -n "$resume" > /sys/power/resume', # Attempt to resume |
| 28 | + ' ewarn "Failed to resume from: $resume"', |
| 29 | + " else", |
| 30 | + ' ewarn "Resume device not found: $resume)"', # Warn if the resume device does not exist |
| 31 | + r' eerror "Block devices:\n$(blkid)"', |
| 32 | + ' eerror "If you wish to continue booting, remove the resume= kernel parameter."', |
| 33 | + ''' eerror " or run 'setvar noresume 1' from the recovery shell to skip resuming."''', |
| 34 | + ' rd_fail "Failed to resume from $(readvar resume)."', |
17 | 35 | " fi", |
18 | | - r' eerror "Block devices:\n$(blkid)"', |
| 36 | + "fi", |
19 | 37 | ] |
20 | | - if self["safe_resume"]: |
21 | | - out_str += [ |
22 | | - ' eerror "If you wish to continue booting, remove the resume= kernel parameter."', |
23 | | - ''' eerror " or run 'setvar noresume 1' to skip resuming."''', |
24 | | - ' rd_fail "Failed to resume from $(readvar resume)."', |
25 | | - ] |
26 | | - else: |
27 | | - out_str += [' eerror "Failed to resume from $(readvar resume)"'] |
28 | | - |
29 | | - out_str += ["fi"] |
30 | | - |
31 | | - return out_str |
|
0 commit comments