omarchy icon indicating copy to clipboard operation
omarchy copied to clipboard

omarchy-hibernation-setup never reconciles a stale resume_offset (guards at lines 63 and 131 make re-running it a silent no-op)

Open adevwithpurpose opened this issue 2 months ago • 8 comments

System details

Omarchy 4.0.3-1; Linux 7.2.3-arch1-3; Hyprland 0.56.2-2; Dell G5 5590 (Intel UHD 630 + NVIDIA RTX 2060 Mobile, hybrid); LUKS-encrypted btrfs root with a dedicated /swap subvolume; Limine + limine-mkinitcpio-hook 1.38.0-1.1.

omarchy debug --no-sudo --print output is attached (/tmp/omarchy-debug.log), trimmed only to remove serial numbers. Note that its parameters line already shows the defect: resume=/dev/mapper/omarchy_root resume_offset=1905130.

What's wrong?

bin/omarchy-hibernation-setup only ever writes the resume drop-in. It never reconciles it. On any system where hibernation was configured once and the swapfile was later recreated at a different size, the drop-in keeps a stale resume_offset and omarchy hibernation setup reports success while doing nothing.

Two independent guards cause this, both in bin/omarchy-hibernation-setup:

1. Line 63 — early exit makes re-running the command a no-op.

if [[ -f $MKINITCPIO_CONF ]] && grep -q "^HOOKS+=(resume)$" "$MKINITCPIO_CONF"; then
  # Fix empty resume_offset if btrfs map-swapfile failed during initial setup
  if [[ -f $RESUME_DROP_IN ]] && grep -q 'resume_offset="$' "$RESUME_DROP_IN" && [[ -f $SWAP_FILE ]]; then

The repair branch at line 65 only matches an empty resume_offset=. A stale-but-non-empty value never matches 'resume_offset="$', so nothing is corrected before the unconditional exit 0 at line 76.

2. Line 131 — the drop-in is written only if absent.

if [[ ! -f $RESUME_DROP_IN ]]; then
  ...
  RESUME_OFFSET=$(sudo btrfs inspect-internal map-swapfile -r "$SWAP_FILE")

Because the file exists, map-swapfile is never consulted again.

Evidence from this machine

/swap/swapfile had been recreated after hibernation was first configured — filefrag -v showed 3 extents, whereas btrfs filesystem mkswapfile always produces a single extent, so the file had been resized by hand rather than created by the script.

$ sudo btrfs inspect-internal map-swapfile -r /swap/swapfile
19565702

$ grep resume_offset /etc/limine-entry-tool.d/resume.conf
KERNEL_CMDLINE[default]+=" resume=/dev/mapper/omarchy_root resume_offset=1905130"

The stored offset was 17x off, so the resume path could not find the swap header. Re-running sudo omarchy hibernation setup printed Hibernation is already set up and exited 0 — no warning, no repair. Hibernation never worked on this machine and there was no signal that it was misconfigured.

Two things that are not the cause, checked so they can be ruled out: the initramfs already carried hooks/resume, usr/bin/resume and usr/lib/systemd/systemd-hibernate-resume, and swap inside the LUKS container is fine because the initramfs unlocks it at boot.

Steps to reproduce

  1. sudo omarchy hibernation setup on a system where it succeeds, so /etc/limine-entry-tool.d/resume.conf and /etc/mkinitcpio.conf.d/omarchy_resume.conf both exist.
  2. Change the swapfile: sudo swapoff /swap/swapfile && sudo rm /swap/swapfile && sudo btrfs filesystem mkswapfile -s 32g /swap/swapfile && sudo swapon -p 0 /swap/swapfile.
  3. sudo omarchy hibernation setup again.
  4. Observe: Hibernation is already set up, exit 0. /etc/limine-entry-tool.d/resume.conf is unchanged, and map-swapfile -r no longer matches it.

systemctl hibernate then fails to resume, silently cold-booting instead.

Suggested fix

Make the drop-in self-reconciling instead of write-once: when HOOKS+=(resume) is present, recompute map-swapfile -r and rewrite resume.conf if the stored value differs, rebuilding only when it actually changes. That also subsumes the existing empty-offset special case at line 65. A related size check would help too — a swapfile smaller than /sys/power/image_size can never hold the image, and this machine had 4 GiB against a 26.7 GB target.

Also worth noting for anyone hitting this: the workaround is to stage /etc/mkinitcpio.conf.d/omarchy_resume.conf aside and delete /etc/limine-entry-tool.d/resume.conf so the guards stop short-circuiting, then run sudo env OMARCHY_PATH=/usr/share/omarchy omarchy hibernation setup --force. Two incidental obstacles there: without an exported OMARCHY_PATH the script fails with install: cannot stat '/default/systemd/system-sleep/keyboard-backlight', and --force is required non-interactively because the gum confirm prompts fail with could not open TTY.

adevwithpurpose avatar Sep 12 '26 09:09 adevwithpurpose

Adding the diagnostics the template asks for. gh cannot upload files, so the relevant excerpts are inline rather than attached; the full omarchy debug --no-sudo --print output is available if useful.

Note on timing: serial numbers from the log are stripped below, and this was captured a few minutes after I applied a local workaround, so the swap numbers reflect the corrected state while the boot cmdline still shows the pre-fix value (it only changes on the next boot). The mismatch that matters is the one recorded in /etc/limine-entry-tool.d/resume.conf before the workaround, quoted in the report above.

$ sudo btrfs inspect-internal map-swapfile -r /swap/swapfile
32515328

Swap (current state after recreating the swapfile at 32 GiB):

ID-1  swap-1  type file  size 32 GiB    used 0 KiB   priority 0    file /swap/swapfile
ID-2  swap-2  type zram  size 62.6 GiB  used 11.57 GiB (18.5%)  priority 100  comp zstd

Hibernation capability as reported by omarchy debug:

hibernate platform
avail shutdown, reboot, suspend, test_resume
image 24.93 GiB

For contrast, the swapfile on this machine was 4 GiB against that 24.93 GiB image target — the second (independent) reason hibernation could not have worked here even with a correct offset.

Boot cmdline (unchanged until reboot; this is the stale value the report describes):

rtc_cmos.use_acpi_alarm=1 resume=/dev/mapper/omarchy_root resume_offset=1905130

Resume machinery confirmed present in the initramfs, so the usual suspects are ruled out:

hooks/resume
usr/bin/resume
usr/lib/systemd/systemd-hibernate-resume

Suggested verification for a fix — the two-way check that exposes this class of bug, which I would put in the test suite if one exists for this command:

[[ $(sudo btrfs inspect-internal map-swapfile -r /swap/swapfile) == $(grep -oP 'resume_offset=\\K[0-9]+' /etc/limine-entry-tool.d/resume.conf) ]]

One unrelated observation I noticed while reading the debug output and am reporting only so it is not lost, not as part of this issue: two transient page allocation failure: order:0 events at 05:55:59 and 06:00:44 (GFP_NOMEMALLOC), in a node and a tokio process, with no OOM kill and both processes surviving. They predate my swapfile change, so if that pattern matters it belongs in its own report.

Confirming the diagnosis is welcome — I am reporting this as a functional gap in the setup script based on reading bin/omarchy-hibernation-setup at 1aeb0d7552b54ba49c74f39ad4dadac204058ee7, and I would rather be corrected than have a wrong diagnosis sit in the tracker.

adevwithpurpose avatar Sep 12 '26 09:09 adevwithpurpose

Confirmed in source on quattro (8bd1b7c04). In bin/omarchy-hibernation-setup, the already-configured branch at lines 69–83 only repairs an offset that is empty (resume_offset="$), then exits 0 with "Hibernation is already set up". The only other place that writes resume.conf (line 137) is guarded by [[ ! -f $RESUME_DROP_IN ]]. So once hibernation is set up, a swapfile recreated at a different offset leaves a stale non-empty resume_offset that nothing recomputes. The code was read, not run: repeating your steps needs a btrfs swapfile, Limine and a real hibernate cycle, so no worker reproduction was attempted.

#11477 fixes this and already says Fixes #11437. Its already-configured branch recomputes the device and map-swapfile -r offset, rewrites the drop-in when it differs, and rebuilds only then. Traced against your exact drop-in line, it matches the format it is allowed to rewrite and gets replaced. It also covers the missing drop-in case in #7619. #13768 changes the same lines but only on the first-time setup path, which a configured system never reaches, so it does not fix this scenario on its own. Your swapfile size check against /sys/power/image_size is not part of either pull request.

The second opinion did not run: Codex Medium answered omabot review --ping, but the review was refused because the reviewer's daily limit was spent. This diagnosis is one model's reading. #11477 will be reviewed and run on its own, and whether it lands is up to the maintainer.

omarchybot avatar Oct 11 '26 14:10 omarchybot

Same stale resume_offset class as #14360 / #14379 / #13583. Open fix #13768 keeps the offset in sync with the swapfile — please test that branch if you can; this can close when it lands.

jandrusk avatar Oct 13 '26 16:10 jandrusk

Re-checked against quattro at ecf0eb362 after the note above. The bug is still there: in bin/omarchy-hibernation-setup, the already-configured branch (lines 69–83) only repairs an empty resume_offset, then exits with "Hibernation is already set up". The only other write of resume.conf (line 137) runs only when the file is absent.

#13768 does not fix this scenario on its own. At its head (6e3991d8), the already-configured branch is unchanged, so re-running setup on a configured system still exits before reaching its new always-recompute block. That block runs only on first-time setup. Its change to omarchy-hibernation-remove deletes resume.conf, so omarchy hibernation remove followed by omarchy hibernation setup would pick up the new offset. That is the #13583 case it says it fixes, and it is a workaround here rather than a fix. #12176 (02004b51) does fall through when the offset differs, but it keeps the [[ ! -f $RESUME_DROP_IN ]] guard (its line 228), so the stale file survives. It also compares offsets by unanchored substring (line 89), so some different offsets would count as a match.

#11477 (5f07d1ec) is the one that fixes it. It already says Fixes #11437. On a configured system it recomputes the device and offset before exiting, rewrites a standard Omarchy drop-in when they differ, and rebuilds only then. A drop-in in any other format is refused with a message instead of being rewritten. Its current head has not yet been re-verified on a worker. It will be reviewed and run as its own item.

This was read in source, not reproduced. Repeating your steps needs a btrfs swapfile, Limine and a real hibernate cycle. Codex Medium reviewed the same three branches as a second opinion and agreed on each. It added the substring-match point about #12176. Its independence from this review is not guaranteed. Your /sys/power/image_size size check is still not in any of these pull requests. This now waits on the maintainer's decision on #11477.

omarchybot avatar Oct 14 '26 00:10 omarchybot

We can fix anything

ElBrodino avatar Oct 25 '26 14:10 ElBrodino

Re-checked against quattro at 175e63b62. Since the last note, #16658 (6573c3d48) changed this script, and the bug is still there. In bin/omarchy-hibernation-setup, the already-configured branch (lines 141–159) still recomputes the offset only when it is empty (line 143). The new rename_resume_device (lines 95–117) renames a /dev/... device to UUID=..., but it writes back the offset already in the file (lines 100–107) and never calls map-swapfile. A stale non-empty resume_offset therefore survives a re-run, and setup still prints "Hibernation is already set up" and exits 0. --force doesn't help, because it is checked only after that exit.

Where the open pull requests stand:

  • #11477 is still the only one that fixes this scenario, but it now conflicts with quattro. The conflict isn't only textual. Its reconcile_resume_parameters takes the device from findmnt SOURCE and accepts only /dev/.... On an unencrypted root, it would rewrite #16658's resume=UUID=... line back to a kernel name such as /dev/nvme0n1p2, because its ownership regex accepts the UUID form. Switching it to resume_device() alone isn't enough either: its ^/dev/ check would reject UUID=... and make every re-run exit 1. A resolution needs to build the line from resume_device() with a fresh offset in one write, and to accept both device forms. It also has to keep #16658's rebuild marker (RESUME_REBUILD_PENDING). Without the marker, a run killed between writing the drop-in and rebuilding leaves a matching drop-in, so the next run skips the rebuild. @yashranaway, that's what a rebase onto quattro would need.
  • #8199 does not fix it. Its setup change is in the first-time path (around line 206), which a system that still has the resume hook never reaches. It fixes the leftover-drop-in case after remove, not a swapfile recreated under a working setup. #13768 is the same. Merging either one should not close this issue.
  • The existing test can't catch this yet. Its btrfs stub always returns 4242, and the re-run fixture already stores 4242. A regression case needs the stored offset to differ from what map-swapfile returns.

This was read in source, not run. The mechanism is fully visible in the script, and a real reproduction needs a btrfs swapfile, Limine and a hibernate cycle. The second opinion was two models, Codex Medium and muse-wonder (via pi, thinking high), given the script and the three diffs and asked about each point. Both agreed on each one, and their independence is not guaranteed. Both also raised the lost rebuild marker in #11477 and the test fixture gap without being asked about them. Your /sys/power/image_size size check is still not in any of these pull requests. This waits on #11477 being brought up to date with quattro, and then on the maintainer.

omarchybot avatar Nov 01 '26 23:11 omarchybot

Adding a hardware-upgrade case for the swap-size validation mentioned in this issue.

I upgraded RAM from 16 GB to 64 GB. The existing /swap/swapfile is still about 15.5 GiB, consistent with the old RAM size. On Omarchy 4.0.6-1, kernel 7.2.15-1-omarchy, read-only checks show:

/proc/meminfo:
MemTotal:       65741272 kB

/proc/swaps (disk swap only):
Filename        Type  Size (KiB)  Used  Priority
/swap/swapfile  file  16277380    0     0

/sys/power/image_size:
26856685568

omarchy hibernation available
# no output; exit status 1

The disk swap is smaller than the approximately 25 GiB image_size target, so it fails Omarchy's availability check. There is also zram, but that is not disk storage for the hibernation image.

Reading the installed omarchy-hibernation-setup, the existing HOOKS+=(resume) marker causes the already-configured branch to exit with "Hibernation is already set up" without checking the swapfile size. --force does not bypass that branch. I have not rerun setup or tested a hibernate/resume cycle; this reports the availability-check result and the source-level setup behavior, not a demonstrated resume failure or a stale resume_offset on this machine.

It would help if rerunning setup revalidated the existing swap size and explained why it no longer passes the availability check, rather than treating the marker alone as sufficient. An explicit resize offer, with a free-space check and the necessary resume-parameter/boot-image updates, would make recovery straightforward after a RAM upgrade. Silently reserving another roughly 48 GiB on disk does not seem necessary; a clear warning and repair path would already be useful.

One distinction worth preserving: image_size is the kernel's best-effort target, not a guaranteed minimum image size. A smaller swapfile failing Omarchy's check does not by itself prove that hibernation must fail under the current workload. See the kernel documentation.

pershin-daniil avatar Nov 05 '26 19:11 pershin-daniil

@pershin-daniil, the reported swap-size comparison is sufficient to explain Omarchy rejecting availability. On a disposable worker with current quattro (419a5a709), I supplied the reported disk-swap size (16,277,380 KiB) and image_size (26,856,685,568 bytes), with the kernel's disk state and resume hook present: the real availability command returned 1. Changing only disk swap to 32 GiB made it return 0. Zram was excluded. All nine existing availability tests passed.

Setup still exits through its already-configured branch before checking capacity, and --force does not bypass that exit. #11477 remains open and already links this issue; it addresses stale-offset reconciliation, but contains no swap-size validation or resizing. The new report does not establish a stale offset on that machine.

The distinction about image_size is correct: the kernel documents it as a best-effort upper limit. My earlier wording that swap below it could never hold an image was too strong. The worker check establishes Omarchy's availability decision; no actual hibernate/resume cycle was attempted.

Opus 5.5 High and muse-wonder (via pi, thinking high) reviewed the source, #11477’s diff and the worker results. Both agreed with this diagnosis; their independence from this review is not guaranteed.

This remains with the maintainer for #11477 and for a decision on size diagnostics or an explicit resize flow after a RAM upgrade.

omarchybot avatar Nov 18 '26 03:11 omarchybot