Hibernate shops the information of the reminiscence/RAM (consumer session) of a operating laptop on the disk and shuts it down. The following time the pc is powered on, the information is learn again from the disk to the reminiscence/RAM and the consumer session is restored.
Hibernate doesn’t drain the battery of the system whereas sleep does, though sleep serves the identical function as hibernate. The explanation why sleep drains the battery of the system is as a result of sleep doesn’t energy off the pc totally and it makes use of a small quantity of energy to protect the contents of the reminiscence/RAM. Because the contents of the reminiscence/RAM are preserved, the pc can resume itself quicker than hibernate. Whereas sleep can get up the pc quicker, hibernate saves extra energy. That’s a bonus of hibernate over sleep.
On this article, we are going to present you how you can allow the Hibernate energy choices in Ubuntu 22.04 LTS.
- Checking the Present Swap and Reminiscence Dimension
- Making a New Swap File to Allow Hibernate
- Enabling the New Swap House on Ubuntu
- Making Certain that Swap is Enabled upon Startup
- Discovering the Filesystem UUID and the Bodily Offset Variety of the Swapfile
- Configuring GRUB to Resume Ubuntu from Hibernate
- Enabling Hibernate in Initramfs
- Including the Hibernate Choice within the System Tray Energy Off/Log Out Menu of Ubuntu 22.04 LTS
- Restarting Ubuntu for the Adjustments to Take Impact
- Hibernating Ubuntu from the Command Line
- Hibernating Ubuntu from the System Tray Energy Off Menu
- What If Hibernate Is Not Working?
- Conclusion
- References
Checking the Present Swap and Reminiscence Dimension
For hibernate to work, the swap measurement of your Ubuntu machine and the put in reminiscence measurement of your laptop ought to be the identical.
You’ll find the swap measurement of your Ubuntu machine with the next command:
As you possibly can see, the swap measurement of our Ubuntu machine is 1.8 GB.
The swap measurement is far smaller than the bodily reminiscence of our laptop which is 3.8 GB. So, we’ve to extend the swap measurement of our Ubuntu machine.
Making a New Swap File to Allow Hibernate
Earlier than you possibly can enhance the swap file measurement, you must disable/flip off the present swap file with the next command:
To extend the swap file measurement to 4 GB (let’s say), run the next command:
$ sudo dd if=/dev/zero of=/swapfile bs=1MB depend=$((4*1024)) standing=progress
NOTE: Within the command part depend=$((4*1024)), 4 is the quantity of bodily reminiscence of our laptop in GB/Gigabyte models. So, if we’ve 16 GB of system reminiscence put in, we write 16 as a substitute of 4.
The swap file measurement is being elevated. It takes some time relying on how huge of a swap file you need.
Right now, the swap file measurement ought to be elevated.
As soon as the swap file measurement is elevated, set the swap file permission to solely the consumer readable and writable with the next command:
$ sudo chmod 600 /swapfile
Format the swap file with the next command:
The swap file ought to be formatted.
Enabling the New Swap House on Ubuntu
To allow the newly created swap file, run the next command:
The newly created swap file ought to be enabled.
Now, the swap measurement and the bodily reminiscence measurement of your laptop ought to be the identical.
Making Certain that Swap Is Enabled upon Startup
To be sure that swap is enabled when Ubuntu boots, you’ll want to have an entry within the /and many others/fstab file to mount the swap file mechanically at startup.
First, open the /and many others/fstab file with the “gedit” textual content editor as follows:
Make it possible for the marked line is current within the /and many others/fstab file. If the road is just not current, add it to the /and many others/fstab file.
When you’re executed, press <Ctrl> + S to avoid wasting the /and many others/fstab file.
Discovering the Filesystem UUID and the Bodily Offset Variety of the Swapfile
To configure the GRUB bootloader to renew from hibernation, you’ll want to know the UUID of the filesystem the place you created the swap file and the bodily offset variety of the swap file.
To search out the bodily offset variety of the swap file, run the next command:
$ sudo filefrag -v /swapfile | head –lines=10
The bodily offsets of the swap file ought to be listed. You don’t want all of them; simply the primary bodily offset. The primary bodily offset of the swap file in our case is 2887680. It will likely be completely different for you. So, ensure that to switch this quantity with yours to any extent further.
As you create the swap file within the root (/) filesystem, discover the system title of the basis filesystem with the next command. In our case, the system title of the basis filesystem is /dev/sda3. It will likely be completely different for you. So, ensure that to switch it with yours to any extent further.
To search out the UUID of the basis filesystem /dev/sda3 (in my case), run the next command:
The UUID of the basis filesystem /dev/sda3 is b1aad2db-6079-4c03-9047-edca0a5e7ead in our case. It will likely be completely different for you. So, ensure that to switch it with yours to any extent further.
Configuring GRUB to Resume Ubuntu from Hibernate
To configure the GRUB bootloader for the hibernation to work, open the GRUB configuration file /and many others/default/grub with the “gedit” textual content editor as follows:
$ sudo gedit /and many others/default/grub
Add the textual content resume=UUID=<your-root-filesystem-UUID> resume_offset=<swapfile_physical_offset> on the finish of the GRUB_CMDLINE_LINUX_DEFAULT as marked within the following screenshot.
When you’re executed, press <Ctrl> + S to avoid wasting the file.
For the adjustments to take impact, replace the GRUB bootloader configuration with the next command:
The GRUB bootloader configuration file ought to be up to date.
Enabling Hibernate in Initramfs
To allow hibernate within the initramfs, create a brand new initramfs configuration file /and many others/initramfs-tools/conf.d/resume with the next command:
$ sudo gedit /and many others/initramfs-tools/conf.d/resume
Add the textual content RESUME=UUID=<your-root-filesystem-UUID> resume_offset=<swapfile_physical_offset> within the newly created file.
When you’re executed, press <Ctrl> + S to avoid wasting the file.
To replace the initramfs picture, run the next command:
$ sudo update-initramfs -c -k all
The initramfs picture ought to be up to date.
Including the Hibernate Choice within the System Tray Energy Off/Log Out Menu of Ubuntu 22.04 LTS
When you add the hibernate choices within the system tray energy off/sign off menu of Ubuntu 22.04 LTS, it is possible for you to to hibernate the Ubuntu 22.04 LTS very simply with just some clicks.
To try this, create a brand new file which is com.ubuntu.enable-hibernate.pkla within the /and many others/polkit-1/localauthority/50-local.d/ listing and open it with the “gedit” textual content editor as follows:
$ sudo gedit /and many others/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
Sort within the following traces of codes within the com.ubuntu.enable-hibernate.pkla file:
Identification=unix-user:*
Motion=org.freedesktop.upower.hibernate
ResultActive=sure
[Re-enable hibernate by default in logind]
Identification=unix-user:*
Motion=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=sure
When you’re executed, save the file by urgent <Ctrl> + S.
Now, replace the APT package deal repository cache with the next command:
Set up the GNOME Extension Supervisor app with the next command:
$ sudo apt set up gnome-shell-extension-manager
To verify the set up, press Y after which press <Enter>.
The GNOME Extension Supervisor app ought to be put in.
As soon as the GNOME Extension Supervisor app is put in, open it from the “Utility Menu” of Ubuntu 22.04 LTS.
Navigate to the “Browse” part of the GNOME Extension Supervisor app[1], seek for hibernate[2], and click on on the “Hibernate Standing Button[3]” as marked within the following screenshot:
Click on on “Set up”.
Click on on “Set up”.
The “Hibernate Standing Button” extension ought to be put in.
Restarting Ubuntu for the Adjustments to Take Impact
For the adjustments to take impact, restart your Ubuntu machine with the next command:
Hibernating Ubuntu from the Command Line
To hibernate your Ubuntu machine from the command line, open a Terminal app and run the next command:
$ sudo systemctl hibernate
Hibernating Ubuntu from the System Tray Energy Off Menu
To hibernate your Ubuntu machine utilizing the graphical consumer interface, click on on the system tray of Ubuntu 22.04 LTS and click on on “Hibernate” from the “Energy Off/Log Out” part.
What If Hibernate Is Not Working?
In some {hardware}, hibernate might not work even after following all these directions. If that’s the case, examine in case you have the safe boot enabled within the BIOS of your laptop. Flip off the safe boot and see if hibernate is working. If it does, safe boot is liable for the hibernate subject.
Conclusion
We confirmed you how you can allow the hibernate choice in Ubuntu 22.04 LTS. We additionally shoed you how you can add the hibernate choice within the system tray of Ubuntu 22.04 LTS and how you can hibernate Ubuntu from the command line and from the graphical consumer interface as nicely.