Tuesday, March 31, 2020

Setting up Hibernation on Ubuntu 18.04 LTS

The ability to hibernate the computer when we are done for the day and get back to where we left next time was a useful feature we had in Ubuntu sometime back by default. However, unfortunately, recent Ubuntu versions does not offer this feature off-the-shelf. Recently, I wanted to get this feature into my laptop running Ubuntu 18.04 version and following are the steps I followed.

1. Creating a swap file

My laptop has 8GB of RAM. Therefore, we need to have a swap space of at least the same size of RAM. Since I didn't want to allocate a partition partition, I created a swap file as follows. 

sudo fallocate -l 8G /swapfile2
sudo chmod 600 /swapfile2
sudo mkswap /swapfile2
sudo swapon /swapfile2

Append the following line to /etc/fstab file in your system.

/swapfile2 none swap sw 0 0

2. Enabling hibernation

Check the UUID of the device where swapfile is located using the following command. The UUID is a very long number that you can see in the output.

sudo findmnt -no SOURCE,UUID -T /swapfile2

Install the following tool.

sudo apt install uswsusp

Run the following command. When prompted, go ahead without a valid swap space by giving 'yes' as the response and then select the device partition where the swap file exists (don't select the swap file itself).

sudo dpkg-reconfigure -pmedium uswsusp

I'm not sure whether I ran the following command next. Probably I did.

sudo update-initramfs -u

3. Enabling the resume from hibernation at next boot

We need to update the /etc/default/grub file as follows.

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=<swap uuid>"

The following is how mine looks like after the modification.

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=cda0136e-ffd9-4a0c-8657-a6511517aa71"

4. Testing hibernation

Run the following command to hibernate your computer. When you turn the computer on next time, it should resume the execution from where you left it when you run the following command.

sudo pm-hibernate


1. https://askubuntu.com/questions/6769/hibernate-and-resume-from-a-swap-file

2. https://askubuntu.com/questions/548015/ubuntu-14-04-sudo-pm-hibernate-doesnt-work