18

I tried different options to enable hibernate in Ubuntu 20.04 but nothing is working. How can I enable hibernate option in Ubuntu 20.04?

  • Hibernate does not work with all equipment. Install the pm-utils package. – user535733 May 16 at 3:48
18

I assume you have a swap partition ready to use.

Install pm-utils and hibernate:

sudo apt install pm-utils hibernate

Then:

cat /sys/power/state

You should see:

freeze mem disk

Then run:

grep swap /etc/fstab

Copy the UUID value. You will need it later. Then run:

sudo nano /etc/default/grub

(or your favourite editor if not nano). 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_VALUE"

Then, after saving the file and quitting the text editor, run:

sudo update-grub

To test it, run:

sudo systemctl hibernate

Right now no GNOME extension is working to have the hibernate option back in the system menu.

Tested on Ubuntu 20.04 Kernel 5.4.0-31 on my Lenovo Thinkpad X1 Carbon.

| improve this answer | |
  • I already tried this. ~$ swapon NAME TYPE SIZE USED PRIO /dev/sda10 partition 17.7G 584K -2 ~$ grep swap /etc/fstab UUID=8fb05489-1d06-4e02-bb80-1ec8022410ee none swap sw 0 0 #/swapfile none swap sw 0 0 ~$ grep resume /boot/grub/grub.cfg linux /boot/vmlinuz-5.4.0-31-generic root=UUID=a1d06496-6e35-4db5-be50-6171988216f0 ro quiet splash resume=8fb05489-1d06-4e02-bb80-1ec8022410ee $vt_handoff – Rajesh May 24 at 5:38
  • 1
    Works. :) it worked for me only with UUID. – adazem009 Jun 23 at 18:08
  • 2
    just to mention this extension for gnome 36 / ubuntu 20.04, handy once the setup is done. extensions.gnome.org/extension/755/hibernate-status-button (check github page of the extension for additional configuration required by ubuntu) – squalou Jun 28 at 8:53
  • 3
    What if grep swap /etc/fstab doesn't return a UUID? – Jules Colle Aug 8 at 7:57
  • 1
    Running grep swap /etc/fstab returns /swapfile none swap sw 0 0 . Any suggestion? – MikeMarsian Sep 28 at 19:30
4

I just added a keyboard shortcut. Disabled Super+H. (I don't need it - default is hide window) and created a new shortcut with command systemctl hibernate. Done. :-)

| improve this answer | |
3

And if you want to turn on hibernation in your Ubuntu 20.04*, follow these steps:

  1. First be ensure you allocate swap memory in your machine to check

     swapon --show
    
  2. Then check whether the swap memory you allocated is more than or at least equal to the Physical memory(RAM).

  3. Use the following command to find the swap partition.

     grep swap /etc/fstab
    
  4. Copy the UUID of the output for example(UUID=XXXXX-XXX-XXXX-XXXX-YYYYYYYYYY)

  5. Add a boot parameter by the following command

     sudoedit /etc/default/grub
    
  6. To the line starting 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 UUID value)

    Final Line Will Be like:

     GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=XXXXX-XXX-XXXX-XXXX-YYYYYYYYYY"
    
  7. Update the file

     sudo update-grub
    
  8. sudo systemctl hibernate and hibernation will now work in your Ubuntu 20.04.

| improve this answer | |
  • 1
    If grep swap /etc/fstab does not give you swap's UUID try sudo blkid. Also, if sudo systemctl hibernate doesn't work, try sudo hibernate. I think you don't even need to edit grub because when you install hibernate it will detect your swap partition. – user2319453 Jul 23 at 11:00
  • My RAM is 16 GB and my swap is 2 GB. How do I increase the swap to match the RAM? – Yehuda Aug 4 at 17:47
2

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:

  1. 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.
  2. Create a new partition of type swap in the empty/unpartitioned space on your disk.
  3. Reboot back into your installed OS (ie without the live CD/USB)
  4. Go to "partitions" or "gparted" to get the UUID of your new swap partition.
  5. Add your new swap partition to /etc/fstab and delete (or comment out) the old swap file
  6. Use the swapoff and swapon commands to switch from the swap file to the swap partition
  7. Don't forget to the delete the swap file to reclaim that space
  8. Now you can follow SuRa's instructions.
| improve this answer | |
1

eldwist's solution worked for me, except...

...not initially, 'cos I got the following error:

$ 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).

| improve this answer | |
0

Using 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 with GRUB_CMDLINE_LINUX_DEFAULT in the file /etc/default/grub to contain resume=<partition_device>

Example:
if /etc/fstab contains this

    # <file system> <mount point>   <type>  <options>       <dump>  <pass>
    /dev/mapper/ubuntu--vg-swap_1 none            swap    sw              0       0

/etc/default/grub should contain the line

    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=/dev/mapper/ubuntu--vg-swap_1"

Then execute sudo update-grub and test by executing sudo systemctl hibernate

| improve this answer | |
-2

In Ubuntu, if you can not hibernate, you can suspend. You can find this option by clicking on the downwards facing triangle in the top right of your screen, and then click on "Power Off/Log Out" dropdown menu. This will bring up the "Suspend" option.

The only difference is that in hibernate the computer powers down completely and moves all data to the hard drive, whereas in suspend still delivers power to the RAM. Suspend shouldn't use too much more power and the computer will be a bit faster to start back up.

Have fun exploring Ubuntu!

| improve this answer | |
  • In Linux Mint 19 (based on Ubuntu), you can add the hibernate option. Why isn't this possible in Ubuntu 20.04 anymore? – Kane May 20 at 17:58
  • @Kane I’m not sure why either, I have had other distros that allow me to hibernate as well. – sleipnir May 20 at 18:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.