Fix hibernation on btrfs swapfiles with dm-crypt (systemd 256+)#5761
Open
Cliffback wants to merge 3 commits into
Open
Fix hibernation on btrfs swapfiles with dm-crypt (systemd 256+)#5761Cliffback wants to merge 3 commits into
Cliffback wants to merge 3 commits into
Conversation
systemd 256+ cannot resolve btrfs swapfiles on dm-crypt to their backing block device, causing CanHibernate to return 'na' and systemd-sleep to fail with 'Stale file handle'. Work around this with SYSTEMD_BYPASS_HIBERNATION_MEMORY_CHECK on both systemd-logind and systemd-hibernate services. Also detect and fix stale resume_offset when the swapfile has been recreated at a different physical location on the btrfs filesystem. Ref: systemd/systemd#30083
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Omarchy’s hibernation tooling to work around systemd 256+ failing hibernation suitability checks on btrfs swapfiles backed by dm-crypt, and adds logic to detect/update stale resume_offset when a swapfile has been recreated.
Changes:
- Add systemd drop-ins to set
SYSTEMD_BYPASS_HIBERNATION_MEMORY_CHECK=1for bothsystemd-logindandsystemd-hibernate. - Resolve
resumedevice/offset earlier and update staleresume_offsetwhen needed. - Introduce a migration to apply the above fixes to existing installations, and update the removal script to clean up new drop-ins.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Reviewed changes
Copilot reviewed 1 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
migrations/1778497305.sh |
Applies systemd hibernation bypass drop-ins and updates stale resume_offset on existing installs. |
bin/omarchy-hibernation-setup |
Adds bypass drop-ins and stale resume_offset updating during setup. |
bin/omarchy-hibernation-remove |
Removes the new bypass drop-ins during hibernation teardown. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CanHibernateto returnnaandsystemd-sleepto fail with "Stale file handle"SYSTEMD_BYPASS_HIBERNATION_MEMORY_CHECK=1drop-ins for bothsystemd-logindandsystemd-hibernateservicesresume_offsetwhen the swapfile has been recreated at a different physical locationresumemkinitcpio hook beforefilesystemsso the kernel can restore the hibernation image before root is mounted read-writeProblem
Since systemd 256,
find_suitable_hibernation_device_full()tries to resolve the swapfile's backing block device by stat()'ing the file. On btrfs with dm-crypt, stat() returns an anonymous btrfs device ID (e.g.0:39) that doesn't match the actual block device (253:0for/dev/mapper/root). This causes:CanHibernatereturning"na"— hibernate option not shown in menussystemd-sleepfailing with "Failed to find location to hibernate to: Stale file handle" — even when manually triggeredAdditionally,
resume_offsetcan become stale if the swapfile is ever recreated (the physical offset changes but the kernel parameter isn't updated), causing silent resume failures on boot.The previous approach of appending
HOOKS+=(resume)via a separateomarchy_resume.confplaced the resume hook afterfilesystemsandfsck, which is too late — the kernel returnsPM: Image not found (code -22)because the root filesystem is already mounted read-write by that point.Fix
The upstream-acknowledged workaround is
SYSTEMD_BYPASS_HIBERNATION_MEMORY_CHECK=1(systemd#30083). This PR applies it to both services that perform the check, adds stale offset detection, and inserts theresumehook directly intoomarchy_hooks.confbeforefilesystems(removing the legacyomarchy_resume.conf).Changes
bin/omarchy-hibernation-setup: resolve resume device/offset upfront, add stale offset fix, add both systemd bypass drop-ins, insert resume hook before filesystems inomarchy_hooks.confbin/omarchy-hibernation-remove: clean up the new drop-ins on removal, remove resume hook fromomarchy_hooks.confbin/omarchy-hibernation-available: check for resume hook inomarchy_hooks.confinstead of the legacyomarchy_resume.confmigrations/1778497305.sh: apply all fixes to existing installs — move resume hook to correct position, add systemd bypass drop-ins, fix stale offsetTesting
Tested on ASUS ROG Flow Z13 (AMD, LUKS + btrfs, systemd 260.1-2, kernel 7.0.5-2-cachyos). Hibernation and resume both work correctly after the fix.
I have had massive problems with hibernation the last months, then got it working, and then broke again after an omarchy update. This have fixed the issues for me at least