Hibernate stores the data of the memory/RAM (user session) of a running computer on the disk and shuts it down. The next time the computer is powered on, the data is read back from the disk to the memory/RAM and the user session is restored.
Hibernate does not drain the battery of the device while sleep does, even though sleep serves the same purpose as hibernate. The reason why sleep drains the battery of the device is because sleep does not power off the computer fully and it uses a small amount of power to preserve the contents of the memory/RAM. As the contents of the memory/RAM are preserved, the computer can resume itself faster than hibernate. While sleep can wake up the computer faster, hibernate saves more power. That’s an advantage of hibernate over sleep.
In this article, we will show you how to enable the Hibernate power options in Ubuntu 22.04 LTS.
For hibernate to work, the swap size of your Ubuntu machine and the installed memory size of your computer should be the same.
You can find the swap size of your Ubuntu machine with the following command:
As you can see, the swap size of our Ubuntu machine is 1.8 GB.
The swap size is much smaller than the physical memory of our computer which is 3.8 GB. So, we have to increase the swap size of our Ubuntu machine.
Before you can increase the swap file size, you have to disable/turn off the current swap file with the following command:
To increase the swap file size to 4 GB (let’s say), run the following command:
NOTE: In the command section count=$((4*1024)), 4 is the amount of physical memory of our computer in GB/Gigabyte units. So, if we have 16 GB of system memory installed, we write 16 instead of 4.
The swap file size is being increased. It takes a while depending on how big of a swap file you want.
At this time, the swap file size should be increased.
Once the swap file size is increased, set the swap file permission to only the user readable and writable with the following command:
Format the swap file with the following command:
The swap file should be formatted.
To enable the newly created swap file, run the following command:
The newly created swap file should be enabled.
Now, the swap size and the physical memory size of your computer should be the same.
To make sure that swap is enabled when Ubuntu boots, you need to have an entry in the /etc/fstab file to mount the swap file automatically at startup.
First, open the /etc/fstab file with the “gedit” text editor as follows:
Make sure that the marked line is present in the /etc/fstab file. If the line is not present, add it to the /etc/fstab file.
Once you’re done, press <Ctrl> + S to save the /etc/fstab file.
To configure the GRUB bootloader to resume from hibernation, you need to know the UUID of the filesystem where you created the swap file and the physical offset number of the swap file.
To find the physical offset number of the swap file, run the following command:
The physical offsets of the swap file should be listed. You don’t need all of them; just the first physical offset. The first physical offset of the swap file in our case is 2887680. It will be different for you. So, make sure to replace this number with yours from now on.
As you create the swap file in the root (/) filesystem, find the device name of the root filesystem with the following command. In our case, the device name of the root filesystem is /dev/sda3. It will be different for you. So, make sure to replace it with yours from now on.
To find the UUID of the root filesystem /dev/sda3 (in my case), run the following command:
The UUID of the root filesystem /dev/sda3 is b1aad2db-6079-4c03-9047-edca0a5e7ead in our case. It will be different for you. So, make sure to replace it with yours from now on.
To configure the GRUB bootloader for the hibernation to work, open the GRUB configuration file /etc/default/grub with the “gedit” text editor as follows:
Add the text resume=UUID= resume_offset=
Once you’re done, press
For the changes to take effect, update the GRUB bootloader configuration with the following command:
The GRUB bootloader configuration file should be updated.
To enable hibernate in the initramfs, create a new initramfs configuration file /etc/initramfs-tools/conf.d/resume with the following command:
Add the text RESUME=UUID= resume_offset=
Once you’re done, press
To update the initramfs image, run the following command:
The initramfs image should be updated.
Once you add the hibernate options in the system tray power off/log out menu of Ubuntu 22.04 LTS, you will be able to hibernate the Ubuntu 22.04 LTS very easily with just a few clicks.
To do that, create a new file which is com.ubuntu.enable-hibernate.pkla in the /etc/polkit-1/localauthority/50-local.d/ directory and open it with the “gedit” text editor as follows:
Type in the following lines of codes in the com.ubuntu.enable-hibernate.pkla file:
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
Once you’re done, save the file by pressing
Now, update the APT package repository cache with the following command:
Install the GNOME Extension Manager app with the following command:
To confirm the installation, press Y and then press
The GNOME Extension Manager app should be installed.
Once the GNOME Extension Manager app is installed, open it from the “Application Menu” of Ubuntu 22.04 LTS.
Navigate to the “Browse” section of the GNOME Extension Manager app[1], search for hibernate[2], and click on the “Hibernate Status Button[3]” as marked in the following screenshot:
Click on “Install”.
Click on “Install”.
The “Hibernate Status Button” extension should be installed.
For the changes to take effect, restart your Ubuntu machine with the following command:
To hibernate your Ubuntu machine from the command line, open a Terminal app and run the following command:
To hibernate your Ubuntu machine using the graphical user interface, click on the system tray of Ubuntu 22.04 LTS and click on “Hibernate” from the “Power Off/Log Out” section.
In some hardware, hibernate may not work even after following all these instructions. If that’s the case, check if you have the secure boot enabled in the BIOS of your computer. Turn off the secure boot and see if hibernate is working. If it does, secure boot is responsible for the hibernate issue.
We showed you how to enable the hibernate option in Ubuntu 22.04 LTS. We also shoed you how to add the hibernate option in the system tray of Ubuntu 22.04 LTS and how to hibernate Ubuntu from the command line and from the graphical user interface as well.
At Canonical, the work of our teams is strongly embedded in the open source principles…
Welcome to the Ubuntu Weekly Newsletter, Issue 873 for the week of December 29, 2024…
Have WiFi troubles on your Ubuntu 24.04 system? Don’t worry, you’re not alone. WiFi problems…
The following is a post from Mark Shuttleworth on the Ubuntu Discourse instance. For more…
I don’t like my prompt, i want to change it. it has my username and…
Introduction: A Fragile Trust The Ruby ecosystem relies heavily on RubyGems.org as the central platform…