HomeLinuxThe way to Allow Hibernate in Ubuntu 22.04 LTS

The way to Allow Hibernate in Ubuntu 22.04 LTS


Hibernate, in easy phrases, is a technique of shutting down a pc whereas conserving the consumer session saved in a tough disk or solid-state drive in order that it may be restored when the pc is powered on the following time.

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.

  1. Checking the Present Swap and Reminiscence Dimension
  2. Making a New Swap File to Allow Hibernate
  3. Enabling the New Swap House on Ubuntu
  4. Making Certain that Swap is Enabled upon Startup
  5. Discovering the Filesystem UUID and the Bodily Offset Variety of the Swapfile
  6. Configuring GRUB to Resume Ubuntu from Hibernate
  7. Enabling Hibernate in Initramfs
  8. Including the Hibernate Choice within the System Tray Energy Off/Log Out Menu of Ubuntu 22.04 LTS
  9. Restarting Ubuntu for the Adjustments to Take Impact
  10. Hibernating Ubuntu from the Command Line
  11. Hibernating Ubuntu from the System Tray Energy Off Menu
  12. What If Hibernate Is Not Working?
  13. Conclusion
  14. 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:

A black rectangle with white text Description automatically generated with low confidence

As you possibly can see, the swap measurement of our Ubuntu machine is 1.8 GB.

A screenshot of a computer Description automatically generated with medium confidence

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.

A screenshot of a computer Description automatically generated

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:

A black rectangle with white text Description automatically generated with low confidence

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.

A screenshot of a computer Description automatically generated with medium confidence

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

A picture containing text, screenshot, font Description automatically generated

Format the swap file with the next command:

A picture containing text, screenshot, font Description automatically generated

The swap file ought to be formatted.

A screenshot of a computer Description automatically generated with medium confidence

Enabling the New Swap House on Ubuntu

To allow the newly created swap file, run the next command:

A picture containing text, screenshot, font Description automatically generated

The newly created swap file ought to be enabled.

A screenshot of a computer Description automatically generated with medium confidence

Now, the swap measurement and the bodily reminiscence measurement of your laptop ought to be the identical.

A screenshot of a computer Description automatically generated with medium confidence

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:

A picture containing text, screenshot, font Description automatically generated

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.

A screenshot of a computer Description automatically generated with medium confidence

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

A black rectangle with white text Description automatically generated with low confidence

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.

A screenshot of a computer Description automatically generated

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.

A screenshot of a computer Description automatically generated with medium confidence

To search out the UUID of the basis filesystem /dev/sda3 (in my case), run the next command:

A picture containing text, screenshot, font Description automatically generated

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.

A screenshot of a computer Description automatically generated

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

A screen shot of a computer Description automatically generated with low confidence

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.

A screenshot of a computer Description automatically generated

For the adjustments to take impact, replace the GRUB bootloader configuration with the next command:

A picture containing text, screenshot, font Description automatically generated

The GRUB bootloader configuration file ought to be up to date.

A screenshot of a computer Description automatically generated

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

A screen shot of a computer Description automatically generated with low confidence

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.

A screenshot of a computer Description automatically generated with medium confidence

To replace the initramfs picture, run the next command:

$ sudo update-initramfs -c -k all

A black rectangle with white text Description automatically generated with low confidence

The initramfs picture ought to be up to date.

A screenshot of a computer Description automatically generated with medium confidence

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:

[Re-enable hibernate by default in upower]

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.

A screenshot of a computer Description automatically generated

Now, replace the APT package deal repository cache with the next command:

A screenshot of a computer program Description automatically generated with medium confidence

Set up the GNOME Extension Supervisor app with the next command:

$ sudo apt set up gnome-shell-extension-manager

A screen shot of a computer Description automatically generated with low confidence

To verify the set up, press Y after which press <Enter>.

A screenshot of a computer Description automatically generated

The GNOME Extension Supervisor app ought to be put in.

A screenshot of a computer Description automatically generated

As soon as the GNOME Extension Supervisor app is put in, open it from the “Utility Menu” of Ubuntu 22.04 LTS.

A screenshot of a computer Description automatically generated with low confidence

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:

A screenshot of a browser Description automatically generated with medium confidence

Click on on “Set up”.

A screenshot of a computer Description automatically generated

Click on on “Set up”.

A screenshot of a computer Description automatically generated with medium confidence

The “Hibernate Standing Button” extension ought to be put in.

A screenshot of a computer Description automatically generated

Restarting Ubuntu for the Adjustments to Take Impact

For the adjustments to take impact, restart your Ubuntu machine with the next command:

A picture containing text, screenshot, font Description automatically generated

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

A picture containing text, screenshot, font Description automatically generated

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.

A screenshot of a computer Description automatically generated

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.

References:

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments