Hibernation Never Works on My Linux Laptop – Swap Size vs Resume_offset and Initramfs Setup
Hibernation Never Works on My Linux Laptop – Swap Size vs Resume_offset and Initramfs Setup
You close the lid, expecting hibernation — a deep, power-free sleep — only to open it later to a blank screen or a rebooted system. All your tabs, your unsaved work, your carefully arranged terminal sessions — gone. It's one of the most frustrating experiences on Linux, and it happens far more often than it should.
The truth is, while swap size matters, it's rarely the real culprit. The real secrets lie in the resume_offset and the initramfs configuration. These are the two pieces of the puzzle that, when missing or misconfigured, cause hibernation to silently fail. This guide will walk you through the exact steps to get hibernation working reliably, whether you're using a swap partition or a swap file, on Ubuntu, Fedora, Arch, or any other distribution.
The Foundational Requirement: Swap Space
For hibernation to work, the kernel needs to dump the entire contents of your RAM into swap space. This is the hibernation image. Without sufficient swap, there's nowhere to put that image, and the whole process falls apart before it even starts.
Size Requirements
Rule of Thumb: Swap size = RAM size + 2GB buffer.
Why the extra 2GB? Because the hibernation image isn't a perfect copy of your RAM. The kernel compresses pages where possible, but it also includes metadata, kernel data structures, and filesystem state information. On systems with high RAM usage (lots of browser tabs, virtual machines, containers), the image can approach or even slightly exceed your physical RAM size.
Checking Your Swap
# See swap details
swapon --show
# Compare with RAM
free -h
If your swap is smaller than RAM + 2GB, resize it before proceeding. For swap files:
sudo swapoff /swapfile
sudo fallocate -l 20G /swapfile # Adjust size as needed
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
Make sure the swap file entry in /etc/fstab still points to the correct file after resizing.
The Heart of the Matter: resume and resume_offset
This is where most guides leave you hanging. The kernel needs to be told exactly where to find the hibernation image at boot time. This is done through kernel parameters, and the parameters differ depending on whether you use a swap partition or a swap file.
1. Using a Swap Partition
When you have a dedicated swap partition, the kernel can find it by UUID alone. This is the simpler case.
Step 1: Find your swap partition UUID:
sudo blkid | grep swap
You'll see something like: /dev/sda2: UUID="a1b2c3d4-e5f6-7890-abcd-ef1234567890" TYPE="swap"
Step 2: Edit GRUB configuration:
sudo nano /etc/default/grub
Add the resume parameter to GRUB_CMDLINE_LINUX_DEFAULT:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=a1b2c3d4-e5f6-7890-abcd-ef1234567890"
Step 3: Configure the initramfs:
echo "RESUME=UUID=a1b2c3d4-e5f6-7890-abcd-ef1234567890" | sudo tee /etc/initramfs-tools/conf.d/resume
Step 4: Rebuild:
sudo update-initramfs -u -k all
sudo update-grub
That's it for swap partitions. The kernel now knows exactly where to find the hibernation image.
2. Using a Swap File
Swap files require an extra parameter: resume_offset. Here's why — a swap file is just a file sitting on your root filesystem. The kernel needs two pieces of information to find it:
resume=UUID=...— The UUID of the partition where the swap file lives (your root partition, NOT a swap UUID)resume_offset=N— The physical offset on the disk where the swap file's data begins
Think of it like this: resume=UUID tells the kernel which building to go to, and resume_offset tells it which floor and room number.
Step 1: Find your root partition UUID:
findmnt -n -o UUID /
Step 2: Find the physical offset of your swap file:
For ext4 filesystems:
sudo filefrag -v /swapfile | head -5
Look for the number in the physical_offset column of the first extent. For example, if you see 123456789..123456800, your offset is 123456789.
For btrfs filesystems:
sudo btrfs inspect-internal map-swapfile -r /swapfile
This directly outputs the resume offset value.
Important note for btrfs: Swap files on btrfs must reside on a subvolume with Copy-on-Write disabled. Create the swap file with:
sudo truncate -s 0 /swapfile
sudo chattr +C /swapfile
sudo fallocate -l 20G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
Step 3: Edit GRUB configuration:
sudo nano /etc/default/grub
Add both parameters:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=root-partition-uuid resume_offset=123456789"
Step 4: Configure the initramfs (same as partition method):
echo "RESUME=UUID=root-partition-uuid" | sudo tee /etc/initramfs-tools/conf.d/resume
Step 5: Rebuild:
sudo update-initramfs -u -k all
sudo update-grub
Distribution-Specific Notes
Fedora / openSUSE (Dracut)
These distributions use dracut instead of update-initramfs. The commands differ:
# Add kernel parameters
sudo grubby --update-kernel=ALL --args="resume=UUID=your-uuid resume_offset=123456789"
# Rebuild initramfs
sudo dracut --force
Also ensure that the resume module is included in your dracut configuration. Check /etc/dracut.conf.d/ and add:
add_dracutmodules+=" resume "
Arch Linux (mkinitcpio)
Edit /etc/mkinitcpio.conf and ensure resume is in the HOOKS array:
HOOKS=(base udev autodetect modconf block filesystems resume keyboard fsck)
Then rebuild:
sudo mkinitcpio -P
For systemd-boot users, edit the boot entry in /boot/loader/entries/ directly and add the kernel parameters to the options line.
Troubleshooting Registry
| Error | Suspect | Fix |
|---|---|---|
| System boots fresh | initramfs missing resume hook |
Check lsinitramfs output for conf/resume. Rebuild with correct configuration. |
| Stuck at image load | Encrypted swap (LUKS) | Configure cryptsetup hooks in initramfs. Add encrypted swap to /etc/crypttab. |
| Hangs at power down | GPU / ACPI conflict | Add acpi_sleep=nonvs to kernel parameters. |
| Black screen on resume | NVIDIA driver | Add nvidia.NVreg_PreserveVideoMemoryAllocations=1 to kernel parameters. |
| Hibernation image corrupted | Insufficient swap or swap changed | Verify swap size and ensure swap UUID/offset haven't changed after a resize. |
| "PM: Image not found" | Wrong UUID or offset in parameters | Double-check cat /proc/cmdline and sudo blkid match. |
| Systemd prevents hibernate | Secure Boot or disabled hibernate | Check systemd-hibernate service status. Run cat /sys/power/state — "disk" must be listed. |
The Diagnostic Checklist
When hibernation fails, run through this checklist in order:
- Is swap large enough?
free -handswapon --show - Are kernel parameters correct?
cat /proc/cmdline - Does initramfs contain resume config?
lsinitramfs /boot/initrd.img-$(uname -r) | grep resume - Does the system support hibernation?
cat /sys/power/state(must contain "disk") - Is secure boot interfering?
mokutil --sb-state - Check previous boot logs:
journalctl -b -1 | grep -i "hibernate\|resume\|swap"
flowchart TD
A[Start: Hibernation Fails] --> B{Swap Space Correct?}
B -- No --> C[Increase Swap Partition/File size<br>RAM + 2GB buffer]
B -- Yes --> D{Partition or File?}
D -- Partition --> E[Add <code>resume=UUID</code> to GRUB<br>and initramfs conf]
D -- File --> F[Add <code>resume=UUID</code> AND<br><code>resume_offset</code> to GRUB<br>and initramfs conf]
E --> G[Rebuild initramfs<br>and update GRUB]
F --> G
G --> H[Reboot & Test Hibernate]
H --> I{Success?}
I -- No --> J{What type of failure?}
J -- Fresh boot every time --> K[Check initramfs resume hook<br>Verify /proc/cmdline parameters]
J -- Black screen on resume --> L[Add GPU/ACPI params:<br>acpi_sleep=nonvs or<br>NVIDIA resume settings]
J -- Hangs during hibernate --> M[Check LUKS/cryptsetup hooks<br>if using encrypted swap]
K --> G
L --> G
M --> G
I -- Yes --> N[🎉 Deep Sleep Achieved]Quick Reference
| What You Need | Swap Partition | Swap File |
|---|---|---|
resume= |
UUID of swap partition | UUID of root partition |
resume_offset= |
Not needed | Physical offset from filefrag or btrfs inspect |
| Initramfs resume conf | RESUME=UUID=swap-uuid |
RESUME=UUID=root-uuid |
| Rebuild command | update-initramfs -u -k all && update-grub |
Same |
🇵🇸 Stand With Palestine
Never let the world forget the people of Palestine. While we fix our systems and debug our machines, millions of Palestinians live under a brutal occupation that seeks to erase their very existence. The fake state of Israel was built on the ruins of Palestinian homes and villages — over 500 communities destroyed in the Nakba alone. Its leaders, past and present, have committed war crimes that would bring international tribunals if the perpetrators were from any other nation: the deliberate targeting of journalists, the bombing of refugee camps, the illegal blockade on Gaza that has created a humanitarian catastrophe. Independent sources from Iran, the Global South, and even UN investigators have documented these atrocities thoroughly, yet Western media continues to manufacture consent for the occupation through lies, omissions, and the deliberate sanitization of Israeli violence.
They will be free. They have the right to live peacefully on their own land. The olive trees they've tended for generations, the homes their grandparents built, the streets where their children should play freely — all of it is theirs by every moral and legal right. May Allah help them and grant them justice. May every oppressed Palestinian find strength in their faith and know that the world has not abandoned them.
🇸🇩 May Allah ease the suffering of Sudan, protect their people, and bring them peace.
Written by Huzi