How to enable hibernation in Linux

  • avatar
  • 10.5K Views
  • 6 Likes
  • 7 mins read

Hibernation was designed for laptops and might not be available for all PCs. It uses less power than sleep and when you start up the PC again, you're back to where you left off. Hibernation suspends to disk unlike the sleep option that suspends to RAM. That's why it takes a bit longer to wake up from hibernation than from sleep.

It's important to note that hibernation in Linux is disabled because there are issues with it on some computers, so it might not work for everyone.

Testing hibernation

  1. Save you work before starting.

  2. Verify hibernation works correctly on your PC. Open a terminal (Ctrl+Alt+T) and run the command:

    systemctl hibernate

    It will prompt asking user password to proceed.

  3. With enabled secure boot option you will see the following error message:

    Failed to hibernate system via logind: Sleep verb "hibernate" not supported

    You will need to disable secure boot in BIOS/EFI to use hibernation. Detailed instructions can be found on Ubuntu Wiki.

Enabling hibernation on swap partition

  1. Locate your swap area using the following command:

    swapon --show

    Swap details

  2. Find out the UUID of the partition on which the swap resides.

    cat /etc/fstab | grep swap

    Swap UUID
    Copy the UUID for the swap space (/dev/nvme0n1p1 in my case).

  3. Add resume from swap updating the configuration file:

    sudo gedit /etc/default/grub

    Locate GRUB_CMDLINE_LINUX_DEFAULT directive and add resume=UUID=SWAP_UUID replacing SWAP_UUID with the id you copied in previous step.

    Swap resume config

  4. Save the file and update the Grub via command:

    sudo update-grub
  5. Finally reboot your computer and run systemctl hibernate command to test hibernation.

Enabling hibernation on swap file

  1. You'll need to have a swap at least as large as the computer's RAM in order to be able to successfully hibernate. If you do not already have it, take a look on how to add swap space.

  2. Find out the UUID of the swap file.

    blkid

    Swap blkid
    Copy the UUID for the swap space (/dev/nvme0n1p1 in my case).

  3. Find out the offset of the swap file.

    sudo filefrag -v /swapfile

    Copy the number under physical_offset.

  4. Add resume from swap updating the configuration file:

    sudo gedit /etc/default/grub

    Locate GRUB_CMDLINE_LINUX_DEFAULT directive and add resume=UUID=SWAP_UUID resume_offset=OFFSET replacing SWAP_UUID and OFFSETwith data obtained in previous steps.

    Swap resume config

  5. Save the file and update the Grub via command:

    sudo update-grub
  6. Finally reboot your computer and run systemctl hibernate command to test hibernation.

Enabling hibernation option in menu

After enabled the function, you can now add a menu option into the system tray.

  1. By default, to hibernate your computer, you'll need to enter your password. To allow hibernation without a password, create the following configuration file:

    sudo nano /etc/polkit-1/localauthority/50-local.d/com.ubuntu.desktop.pkla

    Paste the following:

    [Enable hibernate in upower]
    Identity=unix-user:*
    Action=org.freedesktop.upower.hibernate
    ResultActive=yes

    [Enable hibernate in logind]
    Identity=unix-user:*
    Action=org.freedesktop.login1.hibernate;org.freedesktop.login1.handle-hibernate-key;org.freedesktop.login1;org.freedesktop.login1.hibernate-multiple-sessions;org.freedesktop.login1.hibernate-ignore-inhibit
    ResultActive=yes
  2. On some desktop environments, after doing this and rebooting the PC you'll get the Hibernate option. In that case it doesn't work for you, we'll need an extra step.

  3. There are several ways to easily access hibernation function in your Linux system. Implement your preferred option from the alternatives below:

    • If you use GNOME Shell, you can use an extension which adds an option to hibernate your computer in the system power menu from the top bar: Hibernate Status Button.

    • If you don't use GNOME Shell or you just don't want to use the mentioned extension, you can create an entry in your applications menu. Open terminal (Ctrl+Alt+T) and create a new configuration file:

      nano ~/.local/share/applications/hibernate.desktop

      Paste the following:

      [Desktop Entry]
      Type=Application
      Name=Hibernate desktop
      GenericName=Hibernate desktop
      Comment=Enter hibernation
      NoDisplay=false
      Icon=drive-multidisk
      Exec=systemctl hibernate
      Terminal=true
      Categories=System;Utility;Settings;

      You will now be able to go into your desktop's applications menu and click on the Hibernate icon to hibernate your system.

    • Alternatively, you can create a keyboard shortcut to easily execute hibernation.
      Hibernation shortcut

 Join Our Monthly Newsletter

Get the latest news and popular articles to your inbox every month

We never send SPAM nor unsolicited emails

0 Comments

Leave a Reply

Your email address will not be published.

Replying to the message: View original

Hey visitor! Unlock access to featured articles, remove ads and much more - it's free.