Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ugrd/fs/resume.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmdline_strings = [ "resume" ]

[imports.init_main]
[imports.init_main]
"ugrd.fs.resume" = [ "handle_resume" ]

[import_order.before]
Expand Down
44 changes: 44 additions & 0 deletions src/ugrd/fs/resume_swapfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
__version__ = "0.4.2"


def handle_resume_swapfile(self) -> None:
"""Returns a shell script handling resume from hibernation with a swapfile.
Checks that /sys/power/resume is writable, resume_offset= is sane, resume= is set, and noresume is not set,
if so, checks if UUID= or PARTUUID= or LABEL= is in the resume var,
and tries to use blkid to find the resume device.
If the specified device exists, writes resume device to /sys/power/resume.
In the event of failure, it prints an error message, a list of block devuices, then runs rd_fail.


Resuming or failing to do so is potentially dangerous.
If the system was hibernated, and fails to resume, it will be in an inconsistent state.
If the system is freshly booted, it will not be able to resume, as there is no hibernation image.
Distinguising between a fresh boot and missing/borked hibernation image is not possible at run time.
"""
return [
"resumeval=$(readvar resume)", # read the cmdline resume var
"offset=$(readvar resume_offset)",
'if ! check_var noresume && [ -n "$resumeval" ] && [ -w /sys/power/resume ]; then',
' if echo "$resumeval" | grep -q "UUID=" ||', # resolve uuid to device
' echo "$resumeval" | grep -q "PARTUUID=" ||', # or resolve partuuid to device
' echo "$resumeval" | grep -q "LABEL=" ; then', # or resolve label to device
' resume=$(blkid -t "$resumeval" -o device)',
" else",
" resume=$resumeval",
" fi",
' if [ ! -n "$offset" ] || [ "$offset" -le 0 ]; then', # check for sane offset value, i.e. not empty and greater than 0
' ewarn "resume_offset not set, resume from swapfile likely to fail"',
" fi",
' if [ -e "$resume" ]; then', # Check if the resume device exists
' einfo "Resuming from: $resume position $offset"',
' printf "%s" "$resume" > /sys/power/resume', # Attempt to resume
' ewarn "Failed to resume from: $resume position $offset"',
" else",
' ewarn "Resume device not found: $resume)"', # Warn if the resume device does not exist
r' eerror "Block devices:\n$(blkid)"',
' eerror "If you wish to continue booting, remove the resume= kernel parameter."',
''' eerror " or run 'setvar noresume 1' from the recovery shell (set ugrd_recovery) to skip resuming."''',
' rd_fail "Failed to resume from $(readvar resume)."',
" fi",
"fi",
]
10 changes: 10 additions & 0 deletions src/ugrd/fs/resume_swapfile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmdline_strings = [ "resume" ]

[imports.init_main]
"ugrd.fs.resume_swapfile" = [ "handle_resume_swapfile" ]

[import_order.after]
handle_resume_swapfile = [ "crypt_init", "init_lvm" ]

[import_order.before]
handle_resume_swapfile = [ "mount_root", "mount_fstab", "btrfs_scan", "md_init" ]