Repository navigation
Hibernation: fail when unsupported; refuse empty resume= device #9860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ed90e56
82249c8
6dd5097
51fb6b7
289a722
1e8e35c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,15 +26,15 @@ fi | |
|
|
||
| if [[ ! -f /sys/power/image_size ]]; then | ||
| echo -e "Hibernation is not supported on your system" >&2 | ||
| exit 0 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # When --no-rebuild is set, the caller is responsible for the UKI rebuild | ||
| # (e.g. running before limine-mkinitcpio-hook is installed during initial | ||
| # install), so we only require limine-mkinitcpio when we'd invoke it ourselves. | ||
| if ! $NO_REBUILD && omarchy-cmd-missing limine-mkinitcpio; then | ||
| echo "Skipping hibernation setup (requires Limine bootloader)" | ||
| exit 0 | ||
| echo "Skipping hibernation setup (requires Limine bootloader)" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| MKINITCPIO_CONF="/etc/mkinitcpio.conf.d/omarchy_resume.conf" | ||
|
|
@@ -93,15 +93,25 @@ resume_device() { | |
| # the drop-in changes stays until a rebuild succeeds. A failed or interrupted | ||
| # rebuild then leaves the marker, and the next run rebuilds again. | ||
| rename_resume_device() { | ||
| local previous device offset staged | ||
| local previous previous_device device="" offset staged | ||
|
|
||
| [[ -f $RESUME_DROP_IN && -f $SWAP_FILE ]] || return 0 | ||
| [[ -f $RESUME_DROP_IN ]] || return 0 | ||
| previous=$(<"$RESUME_DROP_IN") | ||
| [[ $previous =~ ^KERNEL_CMDLINE\[default\]\+=\"\ ?resume=(/dev/[^[:space:]\"]+)\ resume_offset=([0-9]+)\"$ ]] || return 0 | ||
| [[ ${BASH_REMATCH[1]} != /dev/mapper/* ]] || return 0 | ||
| [[ $previous =~ ^KERNEL_CMDLINE\[default\]\+=\"\ ?resume=(/dev/[^[:space:]\"]+)?\ resume_offset=([0-9]+)\"$ ]] || return 0 | ||
| previous_device=${BASH_REMATCH[1]} | ||
| offset=${BASH_REMATCH[2]} | ||
| device=$(resume_device) | ||
| [[ $device == UUID=* ]] || return 0 | ||
| [[ $previous_device != /dev/mapper/* ]] || return 0 | ||
| if [[ -f $SWAP_FILE ]]; then | ||
| device=$(resume_device) | ||
| fi | ||
| if [[ -z $previous_device ]]; then | ||
| if [[ $device != UUID=?* && $device != /dev/mapper/?* ]]; then | ||
| echo "Could not determine the resume device for $SWAP_FILE. Fix the swapfile mount, then re-run omarchy-hibernation-setup." >&2 | ||
| return 1 | ||
| fi | ||
| else | ||
| [[ $device == UUID=?* ]] || return 0 | ||
| fi | ||
|
|
||
| staged=$(mktemp) || return 1 | ||
| if printf 'KERNEL_CMDLINE[default]+=" resume=%s resume_offset=%s"\n' "$device" "$offset" >"$staged" && | ||
|
|
@@ -138,7 +148,7 @@ rebuild_renamed_resume_device() { | |
| } | ||
|
|
||
| # Check if hibernation is already configured | ||
| if [[ -f $MKINITCPIO_CONF ]] && grep -q "^HOOKS+=(resume)$" "$MKINITCPIO_CONF"; then | ||
| if [[ -f $MKINITCPIO_CONF && -f $RESUME_DROP_IN ]] && 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 | ||
| RESUME_OFFSET=$(sudo btrfs inspect-internal map-swapfile -r "$SWAP_FILE" 2>/dev/null) | ||
|
|
@@ -203,26 +213,28 @@ if ! install_root_file "$OMARCHY_PATH/default/systemd/system-sleep/keyboard-back | |
| exit 1 | ||
| fi | ||
|
|
||
| # Add resume hook to mkinitcpio | ||
| sudo mkdir -p /etc/mkinitcpio.conf.d | ||
| echo "Adding resume hook to $MKINITCPIO_CONF" | ||
| 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=$(resume_device) | ||
| RESUME_OFFSET=$(sudo btrfs inspect-internal map-swapfile -r "$SWAP_FILE") | ||
| if [[ -n $RESUME_OFFSET ]]; then | ||
| # An empty device writes `resume= resume_offset=N`. The factory reset's chroot finds | ||
| # no device, so leave the drop-in out without failing; a rerun adds it. | ||
| if [[ -n $RESUME_DEVICE && -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 | ||
| echo "Warning: Could not determine resume device and offset for $SWAP_FILE (device='$RESUME_DEVICE' offset='$RESUME_OFFSET'); re-run omarchy-hibernation-setup to add them" >&2 | ||
|
Comment on lines
+223
to
+229
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Setup still writes |
||
| fi | ||
| fi | ||
|
|
||
| # Add resume hook to mkinitcpio | ||
| sudo mkdir -p /etc/mkinitcpio.conf.d | ||
| echo "Adding resume hook to $MKINITCPIO_CONF" | ||
| echo "HOOKS+=(resume)" | sudo tee "$MKINITCPIO_CONF" >/dev/null | ||
|
|
||
| # Use ACPI alarm for RTC wakeup on s2idle systems (needed for suspend-then-hibernate) | ||
| if grep -q "\[s2idle\]" /sys/power/mem_sleep 2>/dev/null; then | ||
| LIMINE_DROP_IN="/etc/limine-entry-tool.d/rtc-alarm.conf" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| echo "Repair hibernation drop-ins with an empty resume= device" | ||
|
|
||
| drop_in=/etc/limine-entry-tool.d/resume.conf | ||
| hook=/etc/mkinitcpio.conf.d/omarchy_resume.conf | ||
| pending=/var/lib/omarchy/hibernation-resume-rebuild | ||
|
|
||
| if [[ ! -e $pending ]]; then | ||
| [[ -f $drop_in ]] && grep -Eq 'resume=[[:space:]]+resume_offset=' "$drop_in" || exit 0 | ||
| fi | ||
|
|
||
| # omarchy-hibernation-remove leaves the drop-in behind; without the hook, setup | ||
| # would create the swapfile again. | ||
| [[ -f $hook ]] && grep -q '^HOOKS+=(resume)$' "$hook" || exit 0 | ||
|
|
||
| # Setup repairs the drop-in atomically and keeps this migration pending if the | ||
| # device is unavailable or the boot image could not be rebuilt. | ||
| omarchy-hibernation-setup --force |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a legacy drop-in contains
resume= resume_offset=andmap-swapfilestill fails, this regex returns success without repairing either value. The new migration matches that line, but setup exits successfully and the migration is marked complete. Fixing the mount later will not trigger another repair.Detect the empty device independently of the offset and return non-zero until both values can be repaired. This also satisfies the migration rule that unfinished repairs must remain pending.
File Used:
agents/skills/migrations.md(source)