Home About Blog Media Free Courses Workshops

Ubuntu 19 - Enable Hibernation

August 24, 2019

After spending the summer playing with differnet OS's, I found that Debian had hibernation ready capability. Unfortunately, I ran into some other issues with it and my laptop and decided to go back to Ubuntu. Ubuntu 19.04's install process does not create a large enough swap partition to allow the system to hibernate, which Debian did.

Hibernation is important for security reasons: with the OS in suspend/sleep, an attacker can get the data off your system since the hard drive is open to Memory. Forcing the system to hibernate when the lid is closed prevents an attacker from getting to your data when the lid is shut, should you ever lose your device.

Follow these steps in order to enable hibernation on Ubuntu 19.04. Please note that these steps begin after you have installed Ubuntu 19.04 on your system and you encrypted the drive as part of the install process.

Step 1: Resizing the root partition

Once the installation is complete, do not reboot. Open the Disks application and a Terminal.
Unlock your encrypted drive by clicking on the lock and entering the password you made during the install process.

Ubuntu Disks

With it unlocked, you should see the now populated Block devices. Knowing where they are is important moving forward.

In Terminal, run "lvmdiskscan" to verify the findings and the disk space currently allocated for the partitions.

We now can begin the resize process. First, we will check the root partition for any errors by typing "sudo e2fsck -f /dev/ubuntu-vg/root" Please remember to change the /dev/ to what you see on your device.

After this has completed with no issues, we can resize the partition with the following command: "sudo lvreduce --resizefs -L __G /dev/ubuntu-vg/root" Please note the "__G" should be the new size of the partition in gigabytes. Make enough room for more than what your total RAM size is.

Step 2: Increase Swap Space

With room to work with, we will increase swap by typing "lvresize -L +15G /dev/ubuntu-vg/swap_1" Please ensure your /dev/ location matches your computer.

You can now reboot the system and boot into Ubuntu for the first time.

Step 3: Enabling Hibernation

Once we're in the OS, we can make final changes to complete the process.

If there is greater than or equal swap space to RAM, running "sudo systemctl hibernate" should cause the system to hibernate. If there isn't enough space, you will see an error about it (at which point, go back to Step 1 and 2 to increase more swap space).

With the test successful, we log back into the machine for the final change. Edit the Lid Actions by typing "sudo nano /etc/systemd/logind.conf"

Once in the file, uncomment and edit the line "HandleLidSwitch=hibernate". Save the file and restart the computer one last time to finish the process!