How to Hibernate Your Linux System (Ubuntu/Debian)

This guide explains how to enable hibernation using a swap file (common in modern Ubuntu installations) rather than a dedicated swap partition.

Hibernation allows your Linux computer to save the current session to disk and completely power off, consuming zero energy. When the system is powered back on, it resumes your previous session, including open apps, documents, and settings.

This guide explains how to enable hibernation using a swap file (common in modern Ubuntu installations) rather than a dedicated swap partition.

What is Hibernation?

Hibernation, or "suspend to disk," saves the contents of your RAM to disk and turns the system off. This differs from "suspend to RAM" (sleep), which keeps memory powered but uses more energy.

Step 1: Check System RAM

Before enabling hibernation, determine how much RAM your system has, as the swap file must be at least equal in size.

bash

CopyEdit

free -h

Make note of the "Mem" total. This is your RAM size.

Step 2: Create or Resize the Swap File

If your system doesn’t already have a swap file large enough to match your RAM, create or resize it:

bash

CopyEdit

sudo swapoff -a

sudo rm /swapfile  # optional: delete existing file

sudo fallocate -l 8G /swapfile  # adjust size to match your RAM

sudo chmod 600 /swapfile

sudo mkswap /swapfile

sudo swapon /swapfile

Replace 8G with the actual size of your RAM.

Step 3: Make the Swap File Permanent

Add the new swap file entry to the system’s filesystem table so it persists after reboot:

bash

CopyEdit

echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Step 4: Find Resume Parameters

Two values are needed: the UUID of the partition containing the swap file and the swap file’s offset on disk.

A. Get the UUID of the Swap Partition:

bash

CopyEdit

findmnt -no UUID -T /swapfile

Copy the UUID string.

B. Find the Resume Offset:

bash

CopyEdit

sudo filefrag -v /swapfile | grep -m1 "^ " | awk '{print $4}' | sed 's/\..*//'

Copy the numeric offset shown.

Step 5: Update GRUB Configuration

Edit the GRUB configuration file to include the resume information:

bash

CopyEdit

sudo nano /etc/default/grub

Find the line starting with:

text

CopyEdit

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

Update it as follows:

text

CopyEdit

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=your-uuid resume_offset=your-offset"

Replace your-uuid and your-offset with the values from step 4.

Save and close the file. Then apply the changes:

bash

CopyEdit

sudo update-grub

sudo update-initramfs -u

Step 6: Test Hibernation

Close any unsaved work and run:

bash

CopyEdit

sudo systemctl hibernate

Your system should shut down completely. Upon restart, your previous session should be restored exactly as it was.

Step 7: Add Hibernate to the Power Menu

To add the hibernate option to graphical menus in environments like GNOME, create a policy rule.

Create a PolicyKit Rule:

bash

CopyEdit

sudo nano /etc/polkit-1/rules.d/10-enable-hibernate.rules

Paste the following:

javascript

CopyEdit

polkit.addRule(function(action, subject) {

    if (action.id == "org.freedesktop.login1.hibernate" ||

        action.id == "org.freedesktop.login1.hibernate-multiple-sessions" ||

        action.id == "org.freedesktop.upower.hibernate" ||

        action.id == "org.freedesktop.login1.handle-hibernate-key" ||

        action.id == "org.freedesktop.login1.hibernate-ignore-inhibit")

    {

        return polkit.Result.YES;

    }

});

Save and reboot the system:

bash

CopyEdit

sudo reboot

After rebooting, "Hibernate" should now appear in the system’s shutdown or power menu.

Troubleshooting and Considerations

Issue

Solution

Hibernate does not restore session:

Recheck UUID and offset values in GRUB configuration

Hibernate option missing in GUI:

Verify the PolicyKit rule was saved correctly

Swap file too small:

Recreate it using fallocate with the correct size

Secure Boot is enabled:

Temporarily disable Secure Boot in BIOS if needed

Dual-boot with Windows:

Disable Windows Fast Startup to avoid boot conflicts

Optional: Check Kernel Support for Hibernation

Run this command to verify:

bash

CopyEdit

cat /sys/power/state

If the output includes disk, your system supports hibernation.

Conclusion

Once set up, hibernation provides:

  • Zero power usage while keeping your session
  • Convenience for laptops and long idle periods
  • Integration into both terminal and GUI environments

With the steps above, you now have full hibernation support configured on your Debian or Ubuntu-based system.

Support.Com Can Help!

If you’re still having trouble, consider reaching out to Support.Com for a personalized solution to all technical support issues.