Enable Hibernate on Ubuntu 24.04 Easily: Step-by-Step Instructions

Enable Hibernate on Ubuntu 24.04 Easily: Step-by-Step Instructions

I recently came across on one of my notebooks that hibernation is not available by default under Ubuntu 24.04. After reading up on it, the forums don't know why this is the case, but there is a solution.

Don't worry, I'll walk you through step by step, it should take about 10-15 minutes.

Let's get started!

Check if the system supports hibernation: First, run the following command to check if your system can support hibernation:
sudo systemctl hibernate
If the system hibernates and wakes up properly, hibernation is supported.

Turn off the current swap:
sudo swapoff /swap.img

Resize the swap file. At the end of the command, instead of "17", enter a number one greater than the amount of RAM you have.
sudo dd if=/dev/zero of=/swap.img bs=1G count=17

Change the swap file permissions:
sudo chmod 600 /swap.img

Format the new swap file:
sudo mkswap /swap.img

Enable the new swap:
sudo swapon /swap.img

Check if the new swap is active:
sudo swapon --show

Verify that /etc/fstab contains this line (It's included by default, so it's really just a check):
/swap.img none swap sw 0 0

Configure the GRUB bootloader: You need to tell Ubuntu where to find the swap file for hibernation. First, find the UUID of your root partition:
blkid | grep $(df / | tail -1 | cut -d" " -f1)

Then, edit the GRUB configuration:
sudo nano /etc/default/grub

Add or update the following lines:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=<your-root-partition-UUID>"
Replace <your-root-partition-UUID> with the actual UUID of your root partition.

Update GRUB:
sudo update-grub

You also need to tell initramfs about the swap file. Edit the resume configuration file:
sudo nano /etc/initramfs-tools/conf.d/resume

Add or update the following line:
RESUME=UUID=<your-root-partition-UUID>

Then, update initramfs:
sudo update-initramfs -u

Test hibernation: Reboot your system, and then test hibernation with the following command:
sudo systemctl hibernate

If this works, we can move on to the step of adding hibernation to the "Power" menu.

Open the file below for editing:
nano /etc/polkit-1/rules.d/10-enable-hibernate.rules

Add the following lines:
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 it by pressing Ctrl + x, then y, then Enter.

Reboot your PC, then test the hibernation by opening the power menu and selecting the Hibernate option. This will save your current session and power down the machine. After the system has fully powered off, turn it back on and check if your previous session is restored correctly.

That's all.

If you found this article useful and would like to show your appreciation, please consider making a small donation via PayPal. Your support will allow me to continue creating valuable content and make my blog even better. Thank you for your contribution!

Comments