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:

  1. Install pm-utils and hibernate:

    sudo apt install pm-utils hibernate
    
  2. Then:

    cat /sys/power/state
    
  3. You should see:

    freeze mem disk
    
  4. Then run one of the following lines:

    grep swap /etc/fstab
    blkid | grep swap
    
  5. Copy the UUID value. You will need it later.

  6. Then run (use your favorite editor if not nano):

    sudo nano /etc/default/grub
    
  7. 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.

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

    sudo update-grub
    
  9. 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.

  1. Install dependencies:

    sudo apt install pm-utils hibernate uswsusp
    
  2. 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
    
  3. 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"
    
  4. Update GRUB:

    sudo update-grub
    
  5. 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):

  1. Disable any options in the settings that touch the laptop lid, set them to "do nothing".

  2. 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
    
  3. 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
    
  4. Run:

    sudo /etc/init.d/acpid restart
    

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

  1. First 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. 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"
    
  7. Update the file:

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