Skip to content

Commit

Permalink
adds support for late resume
Browse files Browse the repository at this point in the history
controlled by the 'late_resume' parameter, will move the trigger point
for resume to after devices have been decrypted or discovered
allows resume from encrypted swap or devices requiring extra handling be visible to the kernel
  • Loading branch information
truffle0 committed Nov 29, 2024
1 parent 27098e2 commit 6a2834b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ Importing this module will run `btrfs device scan` and pull btrfs modules.

When enabled, attempts to resume after hibernation if resume= is passed on the kernel command line.

> Please use the following option with **CAUTION** as it can be unstable in certain configurations! Any writes to disks that occur pre-resume run the risk of causing system instability! For more information have a read of the warnings in the [kernel docs](https://www.kernel.org/doc/html/latest/power/swsusp.html).
* `late_resume` (true) When enabled will attempt to resume from hibernation after decryption and device mapping, allowing resume from encrypted or otherwise hidden swap devices.

### Cryptographic modules

Several cryptographic modules are provided, mostly to assist in mounting encrypted volumes and handling keyfiles.
Expand Down
14 changes: 12 additions & 2 deletions src/ugrd/fs/resume.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
__version__ = "0.4.0"

from zenlib.util import contains, unset

def handle_resume(self) -> None:
def _resume(self) -> None:
"""Returns a bash script handling resume from hibernation.
Checks that /sys/power/resume is writable, resume= is set, and noresume is not set, if so,
checks if PARTUUID= is in the resume var, and tries to use blkid to find the resume device.
Expand All @@ -17,7 +18,7 @@ def handle_resume(self) -> None:
return [
"resumeval=$(readvar resume)", # read the cmdline resume var
'if ! check_var noresume && [ -n "$resumeval" ] && [ -w /sys/power/resume ]; then',
' if echo "$resumeval" | grep -q "PARTUUID="; then', # resolve partuuid to device
' if echo "$resumeval" | grep -q -E "^PARTUUID=|^UUID="; then', # resolve partuuid to device
' resume=$(blkid -t "$resumeval" -o device)',
" else",
" resume=$resumeval",
Expand All @@ -35,3 +36,12 @@ def handle_resume(self) -> None:
" fi",
"fi",
]

@unset('late_resume')
def handle_resume(self) -> None:
return _resume(self)

@contains('late_resume')
def handle_late_resume(self) -> None:
self.logger.warning("WARNING: Late resume enabled, can cause instability if not used with caution. Highly recommended to read configuration documentation before use.")
return _resume(self)
6 changes: 6 additions & 0 deletions src/ugrd/fs/resume.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ cmdline_strings = [ "resume" ]

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

[imports.init_premount]
"ugrd.fs.resume" = [ "handle_late_resume"]

[custom_parameters]
late_resume = "bool"

0 comments on commit 6a2834b

Please sign in to comment.