10

In "System Settings" -> "Power Manager" -> "Energy Saving" there is no "Hibernation" option.

File /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla created with content:

[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-m$
ResultActive=yes

Packages pm-utils and uswsusp installed. Through pm-hibernation successfully leaves in hibernation mode.

7 Answers 7

9

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.

4
  • 2
    Can confirm this procedure works fine for Kubuntu 20.04, no need for any of the utilities mentioned in a lot of other answers (i. e. pm-utils etc.).Since I've also seen some answers which recommend to create the file /etc/initramfs-tools/conf.d/resume: This step is definitely not necessary, but update-initramfs will start to "guess" the right UUID used for hibernation unless it's explicitely specified. In my experience this works just fine, though.
    – opx
    Jul 23, 2021 at 16:23
  • 1
    You should include, that this needs a swap-partition, while current OSes frequently use a swap file as described in this answer
    – Cadoiz
    Nov 23, 2021 at 18:20
  • 1
    @Cadoiz I did write this applies to Kubuntu 20.04 and a swap partition Nov 24, 2021 at 7:04
  • Note that I did these steps using a swap logical volume rather than a raw partition and it worked for me. On logout I did get some scary looking errors that ended with "fixing recursive fault" but hard reseting ended up with a system that could hibernate fine and logout fine and everything. I hope that error doesn't haunt me in the future tho...
    – B T
    Dec 4, 2021 at 22:44
1

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
2
  • After installing gcdemu, hibernation stopped working. I removed gcdemu.
    – Илья
    Dec 14, 2020 at 23:20
  • Is there a way to do this without superuser-privileges?
    – Cadoiz
    Nov 23, 2021 at 18:20
1

I have tested this solution (the new buttons) on a Dell Precsion 5550, Ubuntu 20.04, with a USB3 docking station. Result: While docked, it goes into hibernation, but on resume freezes. If undocked before hibernate, it comes back out. Conclusion: Not solid enough.

I am sticking to the sudo systemctl hibernate solution from How to enable the hibernate option in Ubuntu 20.04? It seems solid, and works both docked and non-docked.

PS. It would be nice to have a polished hibernate option in Ubuntu by default though. (AND, while we are at it: It would be nice to get a real S3 sleep functioning on Dell Precision 5550, current S1/S2 option eats battery)

1

A couple years ago, when I got tired of setting up hibernation every time I installed system, I wrote the script that set it up automatically.

I tested it on Ubuntu 18.04, 20.04 and now on Kubuntu 22.04 and it works fine for me.
It supports systems with a configured swap partition. If needed, it creates the necessary policy and changes to use hibernation when the lid is closed, and disables the grub boot menu after hibernation.

You can find it on GitHub: configure-hibernate

1

I had to modify Mauro's solution a bit to make hibernation fully work on my Kubuntu 22.04:

On forth step replace /etc with /var/lib:

~$ sudo nano /var/lib/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla

Then write the following to the file:

[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.free>
ResultActive=yes

As a result, the hibernation button works fine.

0

Tested in GNOME 20.04 and working!

First, get sudo systemctl hibernate working (see above answer).

Paste

[Enable hibernate in upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes

[Enable hibernate 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

into /etc/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla

Install this GNOME Shell Extension

And voilá, two options appear: * hibernate * hybrid sleep

Proof: enter image description here

I want this to work by default in Ubuntu!

3
  • Is there a way to do this without superuser-privileges?
    – Cadoiz
    Nov 23, 2021 at 18:20
  • I don't think so. Nov 27, 2021 at 18:53
  • It makes no sense to me, that I'm allowed to shutdown/hibernate/etc. via gui, but not via terminal...
    – Cadoiz
    Nov 30, 2021 at 9:53
0

hibernation on kubuntu 21.04 (HP 845 G7).

  1. Disable Secure boot...

  2. make swap file (/swapfile)

fallocate -l 16G /swapfile && chmod 600 /swapfile && \
mkswap /swapfile && swapon /swapfile
  1. install pm-utils
  2. get swap offset
sudo filefrag -v /swapfile |grep " 0:"| awk '{print $4}'<>
  1. get the UUID of the partition where the swapfile lies
findmnt -no SOURCE,UUID -T /swapfile
  1. edit /etc/default/grub and add resume and resume_offset to GRUB_CMDLINE_LINUX_DEFAULT=
resume=UUID=b0644cc4-e29b-4302-acc5-f5954076ffd9 resume_offset=34816
  1. update-grub
  2. add polkit /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
  1. reboot
1
  • Tried to improve your answer a bit. Is there a way to do this without superuser-privileges?
    – Cadoiz
    Nov 30, 2021 at 9:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .