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:
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:
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:
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 ‘/‘:
Then find its UUID via command:
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:
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:
If everything goes well after this tutorial, you can get more, including hibernate when lid is closed, and automatic hibernate on system idle.
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!
Fantastic and clear explanation. Worked perfectly on my Lenovo X230 running Ubuntu 21.10
Excellent, clear and accurate step-by-step instructions, thank you very much. I just enabled hibernation on my laptop and it works great.
Thanks, i appreciate
Excellent! Thanks for your detailed tutorial. It works perfectly.
Works like a charm !!! Thank you so much 🙏
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
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
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
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.
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:
It works in my HP laptop with 22.04 LTS right now, though it didn’t when Ubuntu 22.04 was in Beta.
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.
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
Try installing the “dbus-x11” package via command:
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
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:
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
Do not recommend anyone disabling secure boot on their laptops. Even on desktop it is questionable.
That’s one of the reasons why Ubuntu Linux does not have hibernate function out-of-the-box.
followed your steps and it worked 100%
Now i got a wroking Hibernate option in my power menu.
thanks a million.
Indeed the secure boot was enabled, hibernation works fine now.
many thanks, I appreciate your guidance.
Thanks for this tutorial because I managed to hibernate my Beelink GT-R Mini PC with Ubuntu 22.04 Desktop. Keep it up!
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?
It turns out that pm-hibernate work fine as suggested [here](https://askubuntu.com/q/1404958/480954). There is nothing to change, instead of systemctl just use pm-hibernate.
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.
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!
Thanks for the post.
Working on Kubuntu 22.04
Worked well after disabling the secure boot as it says.
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
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
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
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?
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.
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?
Try disable the swap file via:
Then delete the file:
If you don’t want to re-create the swap file again, also remove “/swapfile none swap sw 0 0” from /etc/fstab file.
systemctl hibernate works now after I managed to increase my LVM SWAP partition. Thanks a lot.
Thanks a lot.
This tutorial worked for me.
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
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
Thanks. Been meaning to look into this for a while.
I have followed all the steps and its not showing hibernate option in Power Menu even after Restart. Please reply.
Please try out if the hibernate function works by running
systemctl hibernatecommand 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.
Oh Thank God! It hsa started working, thanks for helping.
It’s my first time with Ubuntu and that was really very helpful. Thank you so much.
Great! Worked fine on lenovo!
Thank you so much guys I’ve been searching for a while in you save me thank u very much
Excellent article, works like a dream. However it’s about time this option was included in Ubuntu as standard.
Is there a way to avoid having to ask for password every time I want to hibernate?
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)
Now it works!!
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!
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
Great! Worked fine on Dell Inspiron 7460!
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.
Thank you very much!!!
Hello! Thanks for your awesome tutorial. Can you please tell me how may I configure Ubuntu to hibernate in case of critical battery percentage?
Edit the “/etc/UPower/UPower.conf” file, and change the last line from:
Save file and apply via
systemctl restart upowercommand. See more here.