How to enable the hibernate option in Ubuntu 20.04?
I assume you have a swap partition ready to use (if you have a swap file you cannot hibernate). Follow these steps:
-
Install
pm-utils
andhibernate
:sudo apt install pm-utils hibernate
-
Then:
cat /sys/power/state
-
You should see:
freeze mem disk
-
Then run one of the following lines:
grep swap /etc/fstab blkid | grep swap
-
Copy the
UUID
value. You will need it later. -
Then run (use your favorite editor if not
nano
):sudo nano /etc/default/grub
-
Change the line that says:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
so that it instead says:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=<YOUR_COPIED_UUID>"
Be careful not to miss the
UUID=
part. -
Then, after saving the file and quitting the text editor, run:
sudo update-grub
-
To test it, run:
sudo systemctl hibernate
This extension seems to enable showing the "Hibernate" menu entry, but it changes the overall look of this sub-menu: https://extensions.gnome.org/extension/3070/simpler-off-menu/ .
Tested on Ubuntu 20.04 using kernel version 5.4.0-31 on my Lenovo ThinkPad X1 Carbon.
If you want to use a /swapfile to hibernate instead of the swap partition:
The top answer works well, but you don't have to use a partition, you can also use a default /swapfile
.
First of all, you should increase the size of the /swapfile at least to the size of your RAM.
-
Install dependencies:
sudo apt install pm-utils hibernate uswsusp
-
Find your UUID and swap offset:
findmnt -no UUID -T /swapfile && sudo swap-offset /swapfile
You will see something like this:
371b1a95-d91b-49f8-aa4a-da51cbf780b2 resume offset = 23888916
-
Edit
/etc/default/grub
and replace the string:GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
with your UUID and offset:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=371b1a95-d91b-49f8-aa4a-da51cbf780b2 resume_offset=23888916"
-
Update GRUB:
sudo update-grub
-
Test your hibernation:
sudo systemctl hibernate
Probably you should not change the size of your swap after enabling the hibernation (at least without changing the swap-offset
in GRUB).
See wiki for more details.
EXTRA BONUS: If you want to hibernate when a laptop lid is closed (see this):
-
Disable any options in the settings that touch the laptop lid, set them to "do nothing".
-
Run:
sudo mkdir -p /etc/acpi/events/ && sudo nano /etc/acpi/events/laptop-lid
and paste:
event=button/lid.* action=/etc/acpi/laptop-lid.sh
-
Run:
sudo touch /etc/acpi/laptop-lid.sh && sudo chmod +x /etc/acpi/laptop-lid.sh && sudo nano /etc/acpi/laptop-lid.sh
and paste:
#!/bin/bash LOG_FILE='/var/log/laptop-lid.log' touch $LOG_FILE && chmod 0666 $LOG_FILE grep -q closed /proc/acpi/button/lid/LID/state if [ $? = 0 ] then # close action echo "$(date '+%Y.%m.%d %H:%M:%S.%3N'): closed" >> $LOG_FILE systemctl hibernate else # open action echo "$(date '+%Y.%m.%d %H:%M:%S.%3N'): opened" >> $LOG_FILE fi
-
Run:
sudo /etc/init.d/acpid restart
And if you want to turn on hibernation in your Ubuntu 20.04*, follow these steps:
-
First ensure you allocate swap memory in your machine to check:
swapon --show
-
Then check whether the swap memory you allocated is more than or at least equal to the Physical memory(RAM).
-
Use the following command to find the swap partition:
grep swap /etc/fstab
-
Copy the UUID of the output for example(
UUID=XXXXX-XXX-XXXX-XXXX-YYYYYYYYYY
). -
Add a boot parameter by the following command:
sudoedit /etc/default/grub
-
At the line starting with
GRUB_CMDLINE_LINUX_DEFAULT
, add:resume=UUID=XXXXX-XXX-XXXX-XXXX-YYYYYYYYYY
Note: In all other threads they used to ask to add swap partition but here we are adding the UUID value.
The final line will be like:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=XXXXX-XXX-XXXX-XXXX-YYYYYYYYYY"
-
Update the file:
sudo update-grub
-
sudo systemctl hibernate
and hibernation will now work in your Ubuntu 20.04.