How to Hibernate Ubuntu: A Step-by-Step Guide
Are you doing multi-tasking on your Linux machine and suddenly there is a power cut? Is your Laptop battery low or have any problem with your PC’s UPS? Hibernating system is a good option for you! You can save all your work and resume where you left after switching on the computer.
Before we continue, we’d like to tell you about Contabo. We host LinuxAndUbuntu on Contabo VPS. Check them out if you need web hosting. Prices start at $6.99 per month for an 8GB RAM and 4 Core CPU VPS.
Table of contents
What is Hibernate?
Hibernate is an option that allows you to save your system state immediately to your hard disk, so that when you switch your computer on then all the programs can be restored from the hard disk and you can start working again with the same system state as you had before switching off, without losing any data.
Hibernate saves all of your RAM data on the hard disk and restores back into RAM after you turn on the computer.
In Ubuntu, Hibernate is not enabled by default, so you will have to do it manually. But don’t worry It will not take much time once you fulfill the requirements.
Before we continue there are some important things to know to enable Hibernate.
Why Hibernate is not enabled?
When Hibernate can save work in an emergency then why it’s not enabled by default. Well, Hibernate does not work properly with many hardware configurations in Ubuntu and other Linux distributions. If hibernate does not work properly then this might cause data loss after switching back on from hibernation. So PCs or Laptops capable of enabling hibernate option can enable it manually.
Is my Hardware Capable of Hibernate?
You can simply know if your system works properly with hibernate or not. Simply save all your work (otherwise you’ll lose work if hibernate does not work properly) and Open up Terminal from dash or CTRL+ALT+T.
Type and run the following command in Terminal.
$ sudo pm-hibernate
As you run the command, your computer will switch off. Switchback on and see if all your programs that were running before switching off are still running. If all programs are running then Hibernate is working properly.
There is one more common problem. As I told you above hibernate saves all your RAM data to the swap partition that you configured when you installed Ubuntu. That’s why the swap partition must be more than or equal to RAM. To check your swap partition open ‘System Monitor’.
In the Resources Tab check your RAM and Swap. If swap is more than RAM, you’re good to go, otherwise, if you still need to enable hibernate then run gparted from a live cd and increase Swap space.
Enable Hibernate in System Menu
The indicator session was updated to use logind instead of upower. Hibernate is disabled by default in both upower and logind.
Run the following commands to enable hibernate.
$ sudo -i
$ cd /var/lib/polkit-1/localauthority/50-local.d/
$ gedit com.ubuntu.enable-hibernate.pkla
Tips: if the config file does not work for you, try another one by changing /var/lib to /etc in the code.
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
Log out or Restart your system and you’ve done. After you log in, you’ll see hibernate option in your system Menu above in the tray.
Open /etc/default/grub
in nano or text editor of your choice and add the resume=UUID
[UUID for your swap partition/file] right after GRUB_CMDLINE_LINUX_DEFAULT=
.
UUID is the UUID of the swap partition.
Find Swap UUID by the following command –
sudo blkid
After updating the config, update grub with the following command –
sudo update-grub