$ sudo systemctl hibernate
Failed to hibernate system via logind: Sleep verb not supported
If you get this error, you probably need to disable secure boot under the security menu in the UEFI/BIOS (see similar problem with 16.04). Then it worked for me (tested on Ubuntu 20.04; 5.4.0-33 kernel, configured for Dual-boot with Win10).
I just added a keyboard shortcut. I disabled the Super+H, since I don't need it (the default action is to hide the window) and created a new shortcut with the command:
A hibernate button can be added using GNOME extensions.
Note that there is a slight possibility of getting holes in a swapfile when creating it with fallocate. /var/log/syslog can be searched for the phrase swapon: swapfile has holes to ensure there will be no data loss.
A swap file can alternatively be created using dd:
SuRa's answer at the top works great, however, if your laptop came with a swap file instead of a swap partition then you'll have to follow a few steps first to make it all work. At a high level:
Boot from live CD/USB drive, shrink you main partition by the amount of memory you have plus 1-2 GBs for margin. E.g. I have 16 GBs so I shrunk my partition by 18 GB for good measure. That will leave empty/unpartitioned space on your disk.
Create a new partition of type swap in the empty/unpartitioned space on your disk.
Reboot back into your installed OS (ie without the live CD/USB)
Go to "partitions" or "gparted" to get the UUID of your new swap partition.
Add your new swap partition to /etc/fstab and delete (or comment out) the old swap file
Use the swapoff and swapon commands to switch from the swap file to the swap partition
Don't forget to the delete the swap file to reclaim that space
I had to deviate a bit from the "how to" above, probably since I encrypted my hard drive. My /etc/fstab file does not contain an UUID for the swap partition but a partition device.
If your /etc/fstab contains a <partition_device> rather than a UUID for the swap partition, edit the line starting with GRUB_CMDLINE_LINUX_DEFAULT in the file /etc/default/grub to contain resume=<partition_device>
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
:Then:
You should see:
Then run one of the following lines:
Copy the
UUID
value. You will need it later.Then run (use your favorite editor if not
nano
):Change the line that says:
so that it instead says:
Be careful not to miss the
UUID=
part.Then, after saving the file and quitting the text editor, run:
To test it, run:
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:
Find your UUID and swap offset:
You will see something like this:
Edit
/etc/default/grub
and replace the string:with your UUID and offset:
Update GRUB:
Test your hibernation:
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:
and paste:
Run:
and paste:
Run:
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:
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:
Copy the UUID of the output for example(
UUID=XXXXX-XXX-XXXX-XXXX-YYYYYYYYYY
).Add a boot parameter by the following command:
At the line starting with
GRUB_CMDLINE_LINUX_DEFAULT
, add: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:
Update the file:
sudo systemctl hibernate
and hibernation will now work in your Ubuntu 20.04.eldwist's solution worked for me, except...
...not initially, 'cos I got the following error:
If you get this error, you probably need to disable secure boot under the security menu in the UEFI/BIOS (see similar problem with 16.04). Then it worked for me (tested on Ubuntu 20.04; 5.4.0-33 kernel, configured for Dual-boot with Win10).
I just added a keyboard shortcut. I disabled the Super+H, since I don't need it (the default action is to hide the window) and created a new shortcut with the command:
To enable Hibernation in 20.04:
All of the examples on this page seem to be missing
resume-offset
it is necessary when using a swapfile rather than a swap partition.Increase
swapfile
size to match RAM size up to 8GB.Check the swap that is in use:
If swap partition(s) are found:
Add
#
before theUUID
of the swap partition(s):Add a line for the
swapfile
, if one does not exist:Create the
swapfile
:where
X
isswapfile
's size in GB:Reboot:
Add
resume
location and offset togrub.cfg
:Edit
/etc/default/grub
:Use
UUID
from root.Use offset from:
Update GRUB:
Test hibernation:
A hibernate button can be added using GNOME extensions.
Note that there is a slight possibility of getting holes in a
swapfile
when creating it withfallocate
./var/log/syslog
can be searched for the phraseswapon: swapfile has holes
to ensure there will be no data loss.A swap file can alternatively be created using
dd
:An error when using
dd
may overwrite your HDD.SuRa's answer at the top works great, however, if your laptop came with a swap file instead of a swap partition then you'll have to follow a few steps first to make it all work. At a high level:
/etc/fstab
and delete (or comment out) the old swap fileswapoff
andswapon
commands to switch from the swap file to the swap partitionUsing a partition device instead of an UUID
I had to deviate a bit from the "how to" above, probably since I encrypted my hard drive. My
/etc/fstab
file does not contain an UUID for the swap partition but a partition device.If your
/etc/fstab
contains a<partition_device>
rather than a UUID for the swap partition, edit the line starting withGRUB_CMDLINE_LINUX_DEFAULT
in the file/etc/default/grub
to containresume=<partition_device>
Example:
if
/etc/fstab
contains this/etc/default/grub
should contain the lineThen execute
sudo update-grub
and test by executingsudo systemctl hibernate