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 …” (or /dev/nvmex) 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/sda4 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=8192 bs=1MiB
Replace 8192 MB (8G) 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/sda3’ 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: