Ubuntu Linux has been prevented users from moving their computers into hibernation mode for a while. In many cases, people do not use Hibernate because it doesn’t work or they prefer to suspend instead.
Even though Ubuntu’s Hibernate mode isn’t nearly as popular as Suspend, it’s still useful.
Hibernate has the advantage that it shuts down most parts of the computer to being low-power, which means that the laptop battery will last longer.
In Ubuntu Linux, Hibernate mode can be enabled easily by changing a few settings.
Hibernate vs Suspend in Ubuntu
Ubuntu Linux users often confuse "Suspend" and "Hibernate". Suspend and Hibernate differ in how they manage power when your computer goes into "low-power mode".
The "Suspend" button on your KDE or Gnome desktop causes the computer to become semi-awake. All data and instructions are still stored in the RAM, and the device switches to low-power mode. Your laptop’s battery will still be drained or use energy as long as your Ubuntu machine remains in this state.
Hibernation, on the other hand, does not use any energy. If Hibernate is enabled on your Ubuntu Linux PC, its state is stored on the hard drive and is transferred to a frozen state.
Both Hibernate and Suspend have their own benefits.
The benefit of suspend is that it can be resumed very quickly if you are always using your laptop. In contrast, if you want to save battery life, Hibernate is a better choice.
Check if Ubuntu Hibernation can be enabled
We recommend first checking that your Ubuntu installation supports hibernation before making changes to system settings. You should back up all your important data in case something goes wrong and the computer cannot recover to its previous state.
Using Ctrl + Alt + T keyboard shortcut to open a terminal and run the command
sudo systemctl hibernate
Once the computer has been completely shut down, turn it back on. When all your applications are open again after restoring the computer and the restore process itself is relatively fast, then Ubuntu hibernation is working, otherwise it isn’t.
In case hibernation doesn’t work, make sure your kernel is supporting hibernation. You can do this by looking at /sys/power/state
contents:
cat /sys/power/state
In the terminal output, you should see the word disk
if hibernation is available. The disk
part indicates that we can suspend the entire system to disk.
If you see disabled
instead of disk
in the output, check your Secure Boot settings.
Configure enough swap for hibernation
Next, make sure that you have enough swap
space to store the entire RAM contents.
The following commands will show you the information about how much RAM you have, the currently free disk space and existing swap
space.
# Get RAM info
free -mh | grep "Mem"
# Get free disk space info
free -h
# Existing swap information
swapon --show
Make sure that you’re using a separate swap partition instead of a file. This can be determined by looking at swapon --show
output. If the name
is something similar to /dev/sdaX
, you’re good to go.
You can get more details about swap
with: lsblk | grep SWAP
. The output will look something like this.
/dev/sdb6: UUID="2ae674d7-6b75-4680-93c5-6d11c7bfb9b3" TYPE="swsuspend" PARTLABEL="swap" PARTUUID="ab9cf927-6daa-4b7a-a548-2c0a7de0dcec"
The most important thing you need to note is the UUID of the partition. Save 2ae674d7-6b75-4680-93c5-6d11c7bfb9b3
part elsewhere as we will use it in the next section.
Note : File-based swap still works with hibernation, but it’s not really stable and can suffer from disk fragmentation.
If you don’t know how to create a swap partition, check out this tutorial.
Enable Ubuntu Hibernate
Using Hibernate inside Ubuntu Linux requires installing a package. It includes a set of scripts to handle system suspend and resume, includes Hibernate.
The pm-utils
package can be obtained by running the terminal window. You can open the terminal window by pressing Ctrl + Alt + T.
After you open the terminal window, you can use apt-get to install pm-utils
sudo apt-get install pm-utils
Hibernate is available once the pm-utils
package has been installed on your Ubuntu computer. To check this out, go to the terminal and type the following command.
Note : A root account or sudo access is required to access the Hibernate function. It won’t work and may cause serious problems if you try to run it without root access!
sudo pm-hibernate
Set up resume point with GRUB and initramfs
By now the swap space has been created, we can now tell the kernel where to "resume" system state.
We must first update our GRUB configuration.
Run sudo nano /etc/default/grub
in a terminal and look for GRUB_CMDLINE_LINUX_DEFAULT
variable. This is the list of kernel parameters that are passed on boot. Most likely, it will be set to quiet splash
.
You are going to add resume=UUID=2ae674d7-6b75-4680-93c5-6d11c7bfb9b32
to GRUB_CMDLINE_LINUX_DEFAULT
. Remember to replace the UUID with our own value.
Update grub to for the changes to take effect by running
sudo update-grub
We’re also going to need to regenerate the initramfs
and provide it the resume parameter:
# write the resume UUID (replace this with your UUID)
echo RESUME=UUID=2ae674d7-6b75-4680-93c5-6d11c7bfb9b2 | sudo tee /etc/initramfs-tools/conf.d/resume
# Refresh initramfs
sudo update-initramfs -c -k all
Add Hibernate shortcut to Ubuntu
With pm-utils
installed, you can now put your computer into hibernation mode. There is, however, no way to use it other than running pm-utils
via the terminal. Normal users will find this inconvenient.
It would be a good idea to include a "Hibernate" button or shortcut if you regularly use this feature.
First you need to edit com.ubuntu.desktop.pkla
file by running the following command
sudo nano /var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla
Copy and paste the below lines to the file 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
ResultActive=yes
Next, Log out or Restart your system and you’ve done.
After you login, you’ll see Hibernate option in your system Menu above in the tray.