Skip to content

Commit 8d968dd

Browse files
authored
Merge pull request #83 from desultory/resume
Add proper resume support
2 parents 26404c5 + e683470 commit 8d968dd

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

src/ugrd/fs/resume.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
1-
__version__ = "0.3.1"
1+
__version__ = "0.4.0"
22

33

44
def handle_resume(self) -> None:
55
"""Returns a bash script handling resume from hibernation.
66
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.
916
"""
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)."',
1735
" fi",
18-
r' eerror "Block devices:\n$(blkid)"',
36+
"fi",
1937
]
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

src/ugrd/fs/resume.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,3 @@ cmdline_strings = [ "resume" ]
22

33
[imports.init_early]
44
"ugrd.fs.resume" = [ "handle_resume" ]
5-
6-
[custom_parameters]
7-
safe_resume = "bool" # Fail if resume is not possible

0 commit comments

Comments
 (0)