How to enable hibernation in Linux
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
Save you work before starting.
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.
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
Locate your swap area using the following command:
swapon --show
Find out the UUID of the partition on which the swap resides.
cat /etc/fstab | grep swap
Copy the UUID for the swap space (/dev/nvme0n1p1 in my case).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.
Save the file and update the Grub via command:
sudo update-grub
Finally reboot your computer and run systemctl hibernate command to test hibernation.
Enabling hibernation on swap file
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.
Find out the UUID of the swap file.
blkid
Copy the UUID for the swap space (/dev/nvme0n1p1 in my case).Find out the offset of the swap file.
sudo filefrag -v /swapfile
Copy the number under physical_offset.
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.
Save the file and update the Grub via command:
sudo update-grub
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.
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=yesOn 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.
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.
0 Comments