How to Configure Hibernation on Ubuntu 24.04 with a Swap File
A practical walkthrough for enabling hibernation on Ubuntu 24.04 using a swap file instead of a partition, covering GRUB, initramfs pitfalls and the new polkit rules format.
This guide walks through enabling hibernation on Ubuntu 24.04 LTS using a swap.img file rather than a dedicated swap partition. It starts by locating the UUID of the partition hosting the swap file and its physical offset on disk, then adding these as resume and resume_offset parameters to GRUB_CMDLINE_LINUX_DEFAULT before running update-grub.
Two common pitfalls are specifically called out: creating a manual resume file under initramfs-tools, which triggers spurious warnings about a missing swap device, and using legacy init-premount scripts that try to manually write to /sys/power/resume during boot, causing a "sh: write error: invalid argument" failure. The recommended fix is to let the kernel read resume parameters directly from GRUB and avoid adding extra initramfs scripts.
The guide also highlights a change specific to Ubuntu 24.04: with polkit 122+, the older .pkla authorization format is silently ignored, and hibernation permissions must instead be granted via a JavaScript-based .rules file placed in /etc/polkit-1/rules.d. A seven-step debug checklist rounds out the guide, covering kernel command-line parameters, swap state, Secure Boot status, polkit authorization checks, and leftover initramfs scripts for cases where CanHibernate reports "no". This is a useful reference for sysadmins and desktop Linux users trying to understand why older hibernation tutorials no longer work on recent Ubuntu releases.
This synthesis was produced from its source by AI; there is no human editor or manual review step. How we work