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
8 changes: 8 additions & 0 deletions bin/omarchy-hibernation-remove
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# omarchy:requires-sudo=true

MKINITCPIO_CONF="/etc/mkinitcpio.conf.d/omarchy_resume.conf"
RESUME_DROP_IN="/etc/limine-entry-tool.d/resume.conf"

# Check if hibernation is configured
if [[ ! -f $MKINITCPIO_CONF ]] || ! grep -q "^HOOKS+=(resume)$" "$MKINITCPIO_CONF"; then
Expand Down Expand Up @@ -48,6 +49,13 @@ fi
echo "Removing resume hook"
sudo rm "$MKINITCPIO_CONF"

# Remove resume kernel parameters. hibernation-setup only writes these when the
# drop-in is absent, so a stale one would pin a later setup to this swapfile's offset.
Comment on lines +52 to +53

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Comment describes outdated setup behavior Setup now rewrites resume.conf whenever it reaches the resume-parameter step, rather than writing it only when absent. This comment gives future maintainers the wrong reason for deleting the file and makes the cleanup harder to understand.

Suggested change
# Remove resume kernel parameters. hibernation-setup only writes these when the
# drop-in is absent, so a stale one would pin a later setup to this swapfile's offset.
# Remove resume kernel parameters so the rebuilt UKI no longer points to
# the deleted swapfile.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

if [[ -f $RESUME_DROP_IN ]]; then
echo "Removing resume kernel parameters"
sudo rm "$RESUME_DROP_IN"
fi
Comment on lines +54 to +57

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Cleanup cannot be retried If removal is interrupted after deleting the resume hook but before deleting resume.conf, a second run exits because the hook is missing. It never removes the old resume parameters or rebuilds the UKI, so rerunning removal leaves boot settings for the deleted swapfile in place.


echo "Regenerating initramfs..."
sudo limine-mkinitcpio

Expand Down
22 changes: 11 additions & 11 deletions bin/omarchy-hibernation-setup
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,17 @@ echo "HOOKS+=(resume)" | sudo tee "$MKINITCPIO_CONF" >/dev/null

# Add resume= kernel parameters so the initramfs resume hook knows where to find the
# hibernation image. Without these, resume happens late (after GPU drivers load) and fails.
if [[ ! -f $RESUME_DROP_IN ]]; then
echo "Adding resume kernel parameters"
sudo swapon -p 0 "$SWAP_FILE" 2>/dev/null
RESUME_DEVICE=$(findmnt -no SOURCE -T "$SWAP_FILE" | sed 's/\[.*\]//')
RESUME_OFFSET=$(sudo btrfs inspect-internal map-swapfile -r "$SWAP_FILE")
if [[ -n $RESUME_OFFSET ]]; then
sudo mkdir -p /etc/limine-entry-tool.d
echo "KERNEL_CMDLINE[default]+=\" resume=$RESUME_DEVICE resume_offset=$RESUME_OFFSET\"" | sudo tee "$RESUME_DROP_IN" >/dev/null
else
echo "Warning: Could not determine resume offset for $SWAP_FILE" >&2
fi
# Always rewrite them: a drop-in left by an earlier setup names that swapfile's offset.
echo "Adding resume kernel parameters"
sudo swapon -p 0 "$SWAP_FILE" 2>/dev/null
RESUME_DEVICE=$(findmnt -no SOURCE -T "$SWAP_FILE" | sed 's/\[.*\]//')
RESUME_OFFSET=$(sudo btrfs inspect-internal map-swapfile -r "$SWAP_FILE")
if [[ -n $RESUME_OFFSET ]]; then
sudo mkdir -p /etc/limine-entry-tool.d
echo "KERNEL_CMDLINE[default]+=\" resume=$RESUME_DEVICE resume_offset=$RESUME_OFFSET\"" | sudo tee "$RESUME_DROP_IN" >/dev/null
else
sudo rm -f "$RESUME_DROP_IN"
echo "Warning: Could not determine resume offset for $SWAP_FILE" >&2
fi
Comment on lines +139 to 142

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Offset failure prevents recovery If a valid resume.conf remains after the hook configuration was removed and map-swapfile temporarily fails, this branch deletes the valid parameters. Setup then rebuilds without them. Because it has already written the hook, a later setup run exits before recalculating the offset, leaving hibernation unable to resume until the partial configuration is repaired.


# Use ACPI alarm for RTC wakeup on s2idle systems (needed for suspend-then-hibernate)
Expand Down
30 changes: 30 additions & 0 deletions test/shell.d/hibernation-remove-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

source "$(dirname -- "${BASH_SOURCE[0]}")/base-test.sh"

# Every resume drop-in hibernation-setup writes must be removed again, or a
# later setup keeps the old swapfile's resume_offset and resume breaks.
for drop_in in /etc/mkinitcpio.conf.d/omarchy_resume.conf /etc/limine-entry-tool.d/resume.conf; do
grep -F "$drop_in" "$ROOT/bin/omarchy-hibernation-setup" >/dev/null ||
fail "hibernation setup writes $drop_in"
grep -F "$drop_in" "$ROOT/bin/omarchy-hibernation-remove" >/dev/null ||
fail "hibernation remove deletes $drop_in"
done
pass "hibernation remove deletes the resume drop-ins setup writes"

remove_line=$(grep -n 'sudo rm "$RESUME_DROP_IN"' "$ROOT/bin/omarchy-hibernation-remove" | cut -d: -f1)
rebuild_line=$(grep -n '^sudo limine-mkinitcpio' "$ROOT/bin/omarchy-hibernation-remove" | cut -d: -f1)
[[ -n $remove_line && -n $rebuild_line ]] ||
fail "hibernation remove keeps recognizable drop-in removal and rebuild steps"
(( remove_line < rebuild_line )) ||
fail "hibernation remove drops resume parameters before rebuilding the UKI"
pass "hibernation remove drops resume parameters before rebuilding the UKI"
Comment on lines +15 to +21

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Test misses skipped cleanup This test checks that deletion appears before the rebuild in the source, but never runs the removal script. It passes even when a missing hook makes the script exit before deleting a stale resume.conf, so it cannot catch that cleanup regression. A behavioral test of the partial state would cover it.


# A machine that removed hibernation before remove cleaned up still has the old drop-in.
! grep -F '[[ ! -f $RESUME_DROP_IN ]]' "$ROOT/bin/omarchy-hibernation-setup" >/dev/null ||
fail "hibernation setup rewrites a resume drop-in left by an earlier setup"
grep -F 'sudo tee "$RESUME_DROP_IN"' "$ROOT/bin/omarchy-hibernation-setup" >/dev/null ||
fail "hibernation setup writes the resume drop-in"
grep -F 'sudo rm -f "$RESUME_DROP_IN"' "$ROOT/bin/omarchy-hibernation-setup" >/dev/null ||
fail "hibernation setup drops a stale resume drop-in when it cannot find the offset"
pass "hibernation setup rewrites a resume drop-in left by an earlier setup"