How to Hibernate Ubuntu: A Step-by-Step Guide

Are you doing multi-tasking on your Linux machine and suddenly there is a power cut? Is your Laptop battery low or have any problem with your PC’s UPS? Hibernating system is a good option for you! You can save all your work and resume where you left after switching on the computer.

Before we continue, we’d like to tell you about Contabo. We host LinuxAndUbuntu on Contabo VPS. Check them out if you need web hosting. Prices start at $6.99 per month for an 8GB RAM and 4 Core CPU VPS. 

contabo vps

What is Hibernate?

Hibernate is an option that allows you to save your system state immediately to your hard disk, so that when you switch your computer on then all the programs can be restored from the hard disk and you can start working again with the same system state as you had before switching off, without losing any data.

Hibernate saves all of your RAM data on the hard disk and restores back into RAM after you turn on the computer.

In Ubuntu, Hibernate is not enabled by default, so you will have to do it manually. But don’t worry It will not take much time once you fulfill the requirements.

Before we continue there are some important things to know to enable Hibernate.

Why Hibernate is not enabled?

When Hibernate can save work in an emergency then why it’s not enabled by default. Well, Hibernate does not work properly with many hardware configurations in Ubuntu and other Linux distributions. If hibernate does not work properly then this might cause data loss after switching back on from hibernation. So PCs or Laptops capable of enabling hibernate option can enable it manually.

Is my Hardware Capable of Hibernate?

You can simply know if your system works properly with hibernate or not. Simply save all your work (otherwise you’ll lose work if hibernate does not work properly) and Open up Terminal from dash or CTRL+ALT+T.

how to open terminal in linux ubuntu

Type and run the following command in Terminal.

$ sudo pm-hibernate

As you run the command, your computer will switch off. Switchback on and see if all your programs that were running before switching off are still running. If all programs are running then Hibernate is working properly.

There is one more common problem. As I told you above hibernate saves all your RAM data to the swap partition that you configured when you installed Ubuntu. That’s why the swap partition must be more than or equal to RAM. To check your swap partition open ‘System Monitor’.

system monitor to enable hibernate

In the Resources Tab check your RAM and Swap. If swap is more than RAM, you’re good to go, otherwise, if you still need to enable hibernate then run gparted from a live cd and increase Swap space.

linux hibernate option RAM and swap memory

Enable Hibernate in System Menu

The indicator session was updated to use logind instead of upower. Hibernate is disabled by default in both upower and logind.

Run the following commands to enable hibernate.

$ sudo -i
$ cd /var/lib/polkit-1/localauthority/50-local.d/
$ gedit com.ubuntu.enable-hibernate.pkla

Tips: if the config file does not work for you, try another one by changing /var/lib to /etc in the code.

Copy and paste the below lines to the file and save it.

[Re-enable hibernate by default in upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes
[Re-enable hibernate by default in logind]
Identity=unix-user:*
Action=org.freedesktop.login1.hibernate
ResultActive=yes
linux hibernation feature script

Log out or Restart your system and you’ve done. After you log in, you’ll see hibernate option in your system Menu above in the tray.

hibernate in linux ubuntu

Open /etc/default/grub in nano or text editor of your choice and add the resume=UUID [UUID for your swap partition/file] right after GRUB_CMDLINE_LINUX_DEFAULT=.

UUID is the UUID of the swap partition.

Find Swap UUID by the following command –

sudo blkid

After updating the config, update grub with the following command –

sudo update-grub

SHARE THIS POST

MassiveGRID Banner
16 Comments Text
  • I think you don’t want to edit localauthority in /var, create a new file like
    /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla

  • This works perfectly on my Xubuntu set up. Thank you. However, the system resets itself every time after I run System Updates. Is there a way to script it so that it won’t reset after running System Update?

  • Yeah, doesn’t work for me either on Ubuntu 20.04.2 .. just goes into hibernate and reboots when I bring it back out.

  • Well, it still doesn’t work in Mint 20.2. As Ben reported, it reboots instead of restoring the previous session. Any fresh ideas?

    • There may be a message that flashes across your screen too fast to read, which says something like “sparse file not allowed”. This means GRUB can’t identify the filesystem hosting the OS that is going to be restored from hibernation, possibly because GRUB has been configured to save the previously selected OS instead of defaulting to a specific OS on each bootup. (you’d think remembering which OS was booted previously would actually *improve* things, but apparently it causes problems. don’t ask me why.) Check /etc/default/grub and make sure GRUB_DEFAULT=”0″ and GRUB_SAVEDEFAULT=”false”. Change the “0” to whatever number is necessary to correctly target the default Linux OS on your computer. (It’s usually 0, but some people get fancy with multi-boot systems.) Then run “sudo update-grub” to apply the changes.

  • It didn’t work for me at first.

    But it worked when I added in the /etc/default/grub

    resume=UUID=’the UUID of my swap partition’

    at the end of the line

    GRUB_CMDLINE_LINUX_DEFAULT=

    Then

    sudo update-grub

    and it worked!!

    • I can confirm that Josan2’s additional step is required, and works correctly. You can also use a swapfile, but you need to run “sudo mkswap [name of swapfile]” and take note of the UUID generated for the swapfile by the mkswap program, and insert that into /etc/default/grub as Josan2 describes above.

  • Has anyone had any luck with this? I have a Tiger Lake i7 laptop and cannot hibernate on Ubuntu 22.04 after setting up a 17GB swap partition and following all these directions. It will shut down after `systemctl hibernate` but not restore.

  • hi, please update your post to reflect that the config parameter is

    resume=UUID=[UUID for your swap partition/file]

    not

    resume=[UUID for your swap partition/file]

    you have

    resume=UUID

    which is definitely wrong, but suggests the latter.

    • Thanks JD for the comment, but it’s already there. Read the end of the article, I have already mentioned the step.

  • Duude, pm-hibernate uses APM interface to hibernate, while something like “echo disk > /sys/power/state” uses regular ACPI shutdown + bootloader and resume=UUID option.
    If you try it on an old ThinkPad, you’ll see that both work differently – with APM you’ll have the “moon/sleep” led flashing when hibernation happens; with ACPI – disk will light up write swap is being written and then it will shut down. No surprise here – APM and ACPI are totally different interfaces, one was replaced by the other.
    That being said, some new BIOSes might not implement APM at all, so checking if “hibernation works” using APM is not the best way.

  • Also, you can’t find a UUID for swap file (and swap files are default for Ubuntu), that’s why “echo disk > /sys/powe/state” and restore=UUID method is not going to work for a standard Ubuntu install. But, this non-APM hibernation method should work everywhere.

  • Leave a Reply

    Your email address will not be published. Required fields are marked *