Hibernation in Kubuntu 20.04

This is what worked for me with Kubuntu 20.04 and a swap partition of the same size of the available RAM. It's somewhat a simplification of other answers seen here and on the other answer for Ubuntu 20.04.

First of all: no need to install either pm-utils, uswsusp or hibernate: I don't have them in my system, however hibernation works with both sudo systemctl hibernate and with the hibernation button in KDE menu.

So, the whole procedure:

  1. find the name and UUID of the swap partition

    sudo swapon --show=NAME,UUID

    (in my case it's /dev/dm-2 - it must start with /dev, otherwise you're using a swap file)

  2. edit /etc/default/grub and change the value for GRUB_CMDLINE_LINUX_DEFAULT by adding the following at the end of the line (within "):

    resume=UUID=<UUID>

    (replace <UUID> with the UUID found previously)

  3. Run update-grub to update the actual grub config based on /etc/default/grub

  4. write the following command:

cat << "EOF" > /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
[Re-enable hibernate by default in upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes

[Re-enable hibernate by default in logind]
Identity=unix-user:*
Action=org.freedesktop.login1.hibernate;org.freedesktop.login1.handle-hibernate-key;org.freedesktop.login1;org.freedesktop.login1.hibernate-multiple-sessions;org.freedesktop.login1.hibernate-ignore-inhibit
ResultActive=yes
EOF
  1. logout and login

Now you can hibernate with either sudo systemctl hibernate or with the hibernation button in KDE menu.


I have created a swap file in /home partition.

  1. Install pm-utils and uswsusp.

    sudo apt install pm-utils uswsusp
    
  2. Create swapfile and give necessary permissions:

    fallocate -l 8G /home/swapfile && chmod 600 /home/swapfile && \
    mkswap /home/swapfile && swapon /home/swapfile
    
  3. Edit /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla:

    cat << "EOF" > /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
    [Re-enable hibernate by default in upower]
    Identity=unix-user:*
    Action=org.freedesktop.upower.hibernate
    ResultActive=yes
    
    [Re-enable hibernate by default in logind]
    Identity=unix-user:*
    Action=org.freedesktop.login1.hibernate;org.freedesktop.login1.handle-hibernate-key;org.freedesktop.login1;org.freedesktop.login1.hibernate-multiple-sessions;org.freedesktop.login1.hibernate-ignore-inhibit
    ResultActive=yes
    EOF
    
  4. Get swap offset:

    swap-offset /home/swapfile
    
  5. Get UUID of /home/swapfile:

    findmnt -no SOURCE,UUID -T /home/swapfile
    
  6. Edit /etc/default/grub and add

    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=861920c2-557d-4910-9b3e-b8a7be8f4fae resume_offset=12900352"
    
  7. Edit service systemd-logind.service:

    systemct edit systemd-logind.service
    

    and add

    [Service] 
    
    ProtectHome=read-only
    
  8. Update the GRUB using update-grub

  9. Reboot