How to Enable Hibernate Function in Ubuntu 22.04 LTS

Computer hibernate does not work in your Ubuntu? Here’s step by step complete guide shows how to enable this feature.

Similar to suspend, hibernate can be used to save your system work. It moves the content from RAM memory into swap area in hard disk, then shutdown your machine completely. Next time you boot the computer, it restores the system status exactly as it was.

NOTE:This tutorial now is tested and works on my Ubuntu 22.04 Laptop with default GNOME. It may NOT work if you’ve used Grub-Customizer to edit the boot-menu!! For other desktop environments, you need to replace gedit in following commands with your favorite text editor, or use the universal nano command line editor.

Check if hibernate works:

Hibernate does not work in my laptop since Ubuntu 20.04 (maybe, can’t remember it), though it works in Debian 11 bullseye.

NOTE: The command below won’t work for secure boot!! You have to disable it in BIOS/EFI for using hibernate. With secure boot, you’ll get error:

“Failed to hibernate system via logind: Sleep verb “hibernate” not supported”.

To verify if the functions works, open terminal (Ctrl+Alt+T) and run command:

systemctl hibernate

Save you work before running the command!! Then type user password when it asks.

The command will turn off your computer/laptop. Next boot the machine again, and see if it restore your system status after login.

Enable Hibernate on Swap Partition:

So it does not work and just log into blank desktop? Try enable this feature via following steps.

Check Swap Area:

The swap area is used when the memory is getting full. It can also be used to save your system status via hibernate.

Open terminal (Ctrl+Alt+T) and run command tell the swap area:

swapon --show

If it outputs “/dev/sdax partition …” continue this step. Or if it says no swap or a file, go next step: ‘Enable Hibernate on Swap File

Find swap area UUID

In my case the swap is a partition: “/dev/sda4”. Now find the UUID (universally unique identifier) for the area by running command:

cat /etc/fstab |grep swap

Copy the UUID for /dev/sda3 in my case. It will be used in next step.

Resume from swap via Kernel parameter

By adding a Kernel parameter into boot menu entry enables the hibernate in my case in both HP and ASUS laptops.

To do so, run command in terminal to open the config file:

sudo gedit /etc/default/grub

When it opens, add resume=UUID=xxxx (replace xxxx with the id you copied in previous step) as value of “GRUB_CMDLINE_LINUX_DEFAULT”.

Save the file and update the Grub via command:

sudo update-grub

Finally reboot your computer, open a few app windows, and run systemctl hibernate command to test if it works now!

Enable Hibernate on Swap File:

This step is only for those who don’t have a swap partition, since a swap file can also be used for hibernation.

Create Swap File:

To create a file for swap if you don’t have it, run following commands one by one:

a.) Pre-allocate a disk place for a file via command:

sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB

Replace 4096 MB (4G) to your desired size. As large as RAM is recommended for swap.

b.) Change the file permission to only read & write for root:

sudo chmod 600 /swapfile

c.) Set the file as swap area:

sudo mkswap /swapfile

d.) Finally enable it by running command:

sudo swapon /swapfile

e.) And write it into ‘/etc/fstab’, so Ubuntu will mount it automatically on startup.

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

Find the UUID & Offset:

Since the file is created on Ubuntu file-system. It can be located via root UUID as well as physical offset.

To see your Ubuntu partition, run command and find the one mounted on ‘/‘:

df -h

Then find its UUID via command:

blkid

In my case, it’s ‘/dev/sda4’ and UUID is marked underline.

To find the physical offset for /swapfile, run command:

sudo filefrag -v /swapfile

Copy the start number under physical_offset. It’s 1134592 in my case.

Resume on Swap file via Kernel parameter:

Finally edit the Grub configuration file (or use Grub-Customizer) via command:

sudo gedit /etc/default/grub

Then add resume=UUID=xxx resume_offset=xxx as value of “GRUB_CMDLINE_LINUX_DEFAULT”. Also replace ‘xxx’ with the id and/or offset value.

And update grub to apply change via command:

sudo update-grub

Regenerate initramfs:

Hibernate now works in my case after reboot. If not working for you, try regenerating initramfs via a new rule.

Firstly, open terminal (Ctrl+Alt+T) and run command to create a config file:

sudo gedit /etc/initramfs-tools/conf.d/resume

Then paste the line “RESUME=UUID=xxx resume_offset=xxx” (replace xxx with correct id) and save it.

After saving the file, regenerate initramfs via command:

sudo update-initramfs -c -k all

Finally reboot and test hibernate function again.

Enable Hibernate option in Power-Off Menu:

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

1.) Firstly, open terminal (Ctrl+Alt+T) and run command to create & edit a config file:

sudo gedit /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla

When the file opens, paste following lines 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;org.freedesktop.login1.handle-hibernate-key;org.freedesktop.login1;org.freedesktop.login1.hibernate-multiple-sessions;org.freedesktop.login1.hibernate-ignore-inhibit
ResultActive=yes

For non-Gnome desktop, e.g., XUbuntu and Ubuntu MATE, there should be a hibernate option after log-out and back in.

2.) Enable Hibernate option in system menu for the default GNOME Desktop.

For default GNOME desktop, go to the link button below and install the extension for the menu option:

For those first time installing Gnome extension, you need to run command to install “chrome-gnome-shell” package first:

sudo apt install chrome-gnome-shell

And click the “click here to install browser extension” link in the extension page and refresh the page if you don’t see the toggle icon.

Or, search for and install “Extension Manager” from Ubuntu Software, and use the tool to search and install that extension:

Moreover:

If everything goes well after this tutorial, you can get more, including hibernate when lid is closed, and automatic hibernate on system idle.

By Ji m

I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to remind me outdated tutorial! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via ubuntuhandbook1@gmail.com Buy me a coffee: https://ko-fi.com/ubuntuhandbook1

58 comments

  1. Thank you SO MUCH for this tutorial. I have been trying to get my laptop to hibernate for years but was never able to do so. I finally made it thanks to you. You are awesome!

  2. Excellent, clear and accurate step-by-step instructions, thank you very much. I just enabled hibernation on my laptop and it works great.

  3. Bravo very brilliantly explained thank you.
    I guess its normal to expect slower resumption from a swapfile than a swap partition,but really glad to be able to hibernate

  4. Sadly, it doesn’t work for me (fresh Ubuntu 22.04 budgie on thinkpad t14s).

    I had a swap partition (per default, I did not configure anything during installation), but this is only about 1 GB in size. Thus I created a dedicated swapfile
    cat /etc/fstab |grep swap
    # /dev/mapper/vgubuntu–budgie-swap_1 none swap sw 0 0
    /swapfile none swap sw 0 0

    which is also registered

    swapon –show
    NAME TYPE SIZE USED PRIO
    /swapfile file 32G 0B -2

    I tried adding it directly to grub and initramfs with its own UUID
    sudo swaplabel /swapfile
    UUID: e8034255-1bf5-4101-8430-30decbb92b19

    and with the method described here via UUID of the partition it is saved on and the offset found via filefrag -v. Both does not work. It only slows down my boot now with the message “Gave up waiting for suspend/resume device”.

    I’m a bit at a loss here now. Secure boot is disabled. Any directions appreciated.

    1. The UUID you got via “sudo swaplabel /swapfile” command won’t work (at least it does not work in my case).

      But the UUID of the Ubuntu system partition, plus physical offset works. So, the Kernel parameter should be:

      resume=UUID=the-system-partition’s-uuid resume_offset=physical-offset-id

      It works in my HP laptop with 22.04 LTS right now, though it didn’t when Ubuntu 22.04 was in Beta.

      1. Hey, thanks for the quick reply. I tried both. Now back on the UUID of the system partition plus physical offset. But it’s still not working. I’ve found one spot where a problem might be:
        W: initramfs-tools configuration sets RESUME=UUID=2fe750fa-2d0e-414c-8249-39c09d3a336d
        W: but no matching swap device is available.

        initramfs can’t find the swapfile. I have no idea at the moment how to fix that but it’s my best guess that this is the problem.

  5. The hybernation does not work for me as well. I get the following erorr when running “sudo gedit /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla” despite the lines have been added to the file.

    (gedit:3498): dconf-WARNING **: 16:29:11.144: failed to commit changes to dconf: Failed to execute child process “dbus-launch” (No such file or directory)

    I can confirm the swap is created and no other erorrs

      1. thanks for your swift replay, the “dbus-x11” package didn’t sort out the hybernation.
        Failed to hibernate system via logind: Sleep verb “hibernate” not supported

        1. I’ve mentioned that you have to disable “Secure Boot” to be able to use the feature. That could be one of the reasons that Ubuntu does not enable this function out-of-box.

          To verify if Secure Boot enabled in your machine, run command in terminal:

          mokutil --sb-state
          1. Hello my friend, “systemctl hibernate” command is hibernating perfectly. But I can’t enable the sleep button at all.

            I already installed “sudo apt install dbus-x11” and the command “mokutil –sb-state” returns: SecureBoot disabled

            What the master thinks my Ubuntu 22.04LTS can be in Portuguese/BR

          2. Do not recommend anyone disabling secure boot on their laptops. Even on desktop it is questionable.

  6. followed your steps and it worked 100%
    Now i got a wroking Hibernate option in my power menu.
    thanks a million.

  7. Thanks for this tutorial because I managed to hibernate my Beelink GT-R Mini PC with Ubuntu 22.04 Desktop. Keep it up!

  8. I’ve upgraded from 20.04 to 22.04 and the hibernation gone. I’ve done all the steps including extras like dbus and hibernation only locks the screen nothing more. Yes, the secureBoot is disabled. Any ideas to solve the issue?

      1. With the kernel update to linux-image-5.15.0-47-generic the systemctl hibernate work as in 20.04.

        I would like to note that pm-hibernate was not a good alterantive to systemctl hibernate according to my experiences.

  9. I’ve been a linux user for decades and this may be the first time I’ve had “hibernate” actually work after following theses instructions with only slight modifications based on my personal system. Thank you!

  10. I was wondering if you’ve tried this on an encrypted drive? I encrypted my system following this tutorial, but with the following differences:

    1) I did not create a swap partition. Instead I created a swap file after installation according to your tutorial.
    2) I created two partitions inside the encrypted partition, one for my root directory / and one for my home directory /home.

    I am uncertain how to go about getting hibernation to work in this particular case. I can confirm your tutorial for hibernation using swap file does not work as is. Do you have a suggestion how the procedure needs to be modified to get it to work properly?

    created two partitions for my root (/) and home (/home) directories within a LUKS encrypted partition
    I am unable to set up hibernation w

  11. Using Ubuntu 22.04.1 on Thinkpad X1 Carbon Gen 9 with LUKS encrypted LVM and 40 GiB swapfile for 32 GiB RAM. Followed this guide, but cannot get hibernate working.

    userx@x1:~$ sudo filefrag -v /swapfile | head -5
    Filesystem type is: ef53
    File size of /swapfile is 42949672960 (10485760 blocks of 4096 bytes)
    ext: logical_offset: physical_offset: length: expected: flags:
    0: 0.. 2047: 12746752.. 12748799: 2048:
    1: 2048.. 4095: 213837824.. 213839871: 2048: 12748800:

    userx@x1:~$ sudo blkid
    /dev/mapper/nvme0n1p3_crypt: UUID=”…” TYPE=”LVM2_member”
    /dev/mapper/vgubuntu-root: UUID=”87d2097a-7613-42c3-85c1-d18952e4c1a1″ BLOCK_SIZE=”4096″ TYPE=”ext4″

    Line from /etc/default/grub:
    GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash resume=UUID=87d2097a-7613-42c3-85c1-d18952e4c1a1 resume_offset=12746752″

    userx@x1:~$ cat /etc/initramfs-tools/conf.d/resume
    RESUME=UUID=87d2097a-7613-42c3-85c1-d18952e4c1a1 resume_offset=12746752

    Also getting the initramfs warnings mentioned above:
    W: initramfs-tools configuration sets RESUME=UUID=87d2097a-7613-42c3-85c1-d18952e4c1a1
    W: but no matching swap device is available.

    Any idea what may be the problem here?

  12. Worked well.
    Thought in step Enable Hibernate option in Power-Off Menu / 2
    I needed another extension manager for Firefox. But it was suggested by the software center automatically.

  13. Does not work. Disk is full, is the message. My Swap file is 2GB, but my RAM 32GB. I probably have to increase Swap file, but how?

    1. Try disable the swap file via:

      sudo swapon /swapfile

      Then delete the file:

      sudo rm /swapfile

      If you don’t want to re-create the swap file again, also remove “/swapfile none swap sw 0 0” from /etc/fstab file.

  14. I have a machine with 8G and according to swapon -s:
    /swapfile file 8388604 0 -2

    Yet, when I run update-initramfs -c -k all I get
    W: initramfs-tools configuration sets RESUME=UUID=resume=UUID=6b2ce25b-bc09-41fa-894f-70f9655fab24
    W: but no matching swap device is available.

    I should add that findmnt -no UUID -T /swapfile generates
    6b2ce25b-bc09-41fa-894f-70f9655fab24

    So, it seems that the device should be found.

    My swap is NOT encrypted, per the swapon, see above.

    So, why is initramfs not finding it? What am I missing/doing wrong

    1. Please try out if the hibernate function works by running systemctl hibernate command in terminal. And tell your Ubuntu edition, desktop environment, and if possible what’s error you got.

      You can search for and install “Extension Manager” from Ubuntu software, and use it to see if the extension is probably installed and enabled.

  15. Excellent article, works like a dream. However it’s about time this option was included in Ubuntu as standard.

  16. Well part of it has worked!
    It hibernates from the command line.
    It also hibernates from the menu.
    But in both cases when it is restarted, it shows the message “Resuming from hibernation”
    then sadly it just carries on the normal boot, to system screen with no application running.
    .
    So I have question re Modify Grub:
    The UUID= does this go in quotes ie UUID=”168xxyt4684846″ and also the offset address? ie resume_offset=”12345679987″
    In your example you have quote symbol only at the end of the offset address!

    Otherwise thanks for a step by step which has half worked.
    I need to know where to find the log which shows what error then maybe we can find the problem. I have looked in var/log/ but can not find the correct log!

    I am running 22.04.1 LTS with Gnome 42.5 on with X11 on an ancient Clevo laptop CLEVO CO. W240EU/W250EUQ/W270EUQ. (The bios is now being awkward and taking many attempts to boot, but I do no think it is the problem. (Many hundreds of years before secureBoot was invented)

  17. Now it works!!
    Fantastic!
    Many thanks to Ji m !!
    I had a problem with quote marks in the addition to the /etc/default/grub file.
    But it needs to be exactly as per the photo on the page, with a closing quote ONLY at the end of the resume_offset=address”

    Now I have to fix my dodgy bios!

  18. Hi, I’m able to observer that ubuntu often getting crash and throwing bulk_update_rename, I/o error. error while writing superblocks in complete black screen. kinds of error. And this is happenning once i resumed from hibernate and spend few minutes to few hours in ubuntu. Also i can notice that some memories were occupies on swap memory once resumed after hibernate. and ubuntu using completely ram memory before i’m putting ubuntu into hibernate. Also mentioning that i’m running with sufficient ram memory in my system using swap to make the system into hibernate. Could anyone help on this

  19. It works! great! Thank you very much!
    Just one little addition, I think you need to reboot in order to get the Hibernate option in Power-Off Menu visible.

  20. Hello! Thanks for your awesome tutorial. Can you please tell me how may I configure Ubuntu to hibernate in case of critical battery percentage?

    1. Edit the “/etc/UPower/UPower.conf” file, and change the last line from:

      CriticalPowerAction=HybridSleep

      to:

      CriticalPowerAction=Hibernate

      Save file and apply via systemctl restart upower command. See more here.

  21. Ji m, hello and thz.
    Ubuntu 23.04
    If i run “sudo systemctl hibernate” all work,
    but if i press button “Hibernate” in menu after start black screen.
    Helps only reboot.
    You could help?

  22. Hi, Thanks for the explanation. From the responses I understand it should work like a charm, however, I keep running into the error: `Failed to hibernate system via logind: Not enough swap space for hibernation`; even if I make the swapfile 4GB larger than my actual RAM, which is 16GB.
    Do you have any suggestions?
    BTW I found this thread which suggests to bypass the memory size check but I don’t know how to set this, or if this is even save.

  23. Hi there, I have followed these directions in detail and I am having an issue where Hibernate works MOST of the time, but sometimes it does not. About 10-20% of the time, it boots up as if it was shut down completely. The rest of the time, my state is saved properly. Any ideas on this?

  24. Thank you so much. I’ve tried this on two laptops, one of them with Ubuntu 22.04 and the other one with Ubuntu 24.03. Both working perfectly fine.

Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Exit mobile version