10

I was used to have 21.04 with the hibernate function recallable via an extension that apparently is not compatible anymore with the new GNOME on 22.04.

Apparently there is not an alternative on the extension site. Do you know anything that can be used rather than typing in the command in the terminal?

  • No, the only solution I have is to to manipulate user rights in the ubuntu.pkla files. I could write a book about the different pathes over the years (it is really annoying). If you're interested in coping code via terminal - say so... – kanehekili May 01 '22 at 20:09
  • I think I've added some entries in the policy file as per the plug-in author without success. Happy to read your approach as I'm not having hibernating via cli. And it's annoying the power button doesn't answer to the hibernating command now that they added it – Andrea Moro May 03 '22 at 05:07
  • @kanehekili by any chance can you send over the hints on how to modify the system menu? – Andrea Moro May 10 '22 at 05:30

3 Answers3

7

There is an extension that will show your hibernate button. That doesn't necessarily means it will work. So a few steps have to be taken:

  1. Check if hibernate works: Open a terminal and execute systemctl hibernate. IF this does not work, you'll have to look into the Ubuntu handbook on how to define your swap partition/file

  2. Enter terminal as root (sudo will not work). Open (or create) a file with: nano /var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla

Add the text below at the end of the file:

##NEW entry since Ubuntu 18:
[Re-enable hibernate by default in upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes

##NEW entry since Ubuntu 18: [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

  1. Clean up hook (Error - recordfail after resume from hibernate). That error occurs after resume (Ubuntu really doesn't want you to hibernate):

sudo nano /etc/systemd/system/use-10_grub_common.service Enter:

[Unit]
Description=Execute the /etc/pm/sleep.d/10_grub_common script after hibernation.
After=hibernate.target

[Service] Type=oneshot ExecStart=/etc/pm/sleep.d/10_grub-common thaw

[Install] WantedBy=hibernate.target

This script will remove an error flag from grub, preventing it showing an error the next time you boot. Since it is a service you need to enable it:

sudo systemctl enable use-10_grub_common

What I did not cover is the definition of your swap (either partition or file) - see the link at point 1. There are two places where "Resume" has to be defined: Grub: Resume=UUID=xxxx (when you have a swap partion and xxx is the uid of that) and an entry in /etc/initramfs-tools/conf.d/resume (Resume=UUID=xxxx)

Since I do not know your configuration and have never tried hibernation with swap files I will not elaborate (now)

kanehekili
  • 6,402
  • Thanks @kanehikili. I didn't know that extension or perhaps I did check before and it appears that only recentently it started to support GNOME 42. I will have a try. – Andrea Moro May 12 '22 at 05:04
  • @kanehikili I've a couple of questions. What is the role of the com.ubuntu.desktop.pkla file. I'm asking, because I don't remember I have edited this before, but I have the same rules already but infact the label on top says [Disable hibernate ... ]. And in your snippet, the second one seems to miss the ResultActive=yes. Perhaps an omission? – Andrea Moro May 12 '22 at 05:08
  • Do you have some documentation re that second snippet that creates the service part to trick the grub? On my side I was not having that, but when the system boots after the hibernation I see a flashing screen with some errors that is difficult to capture and that I thought the script would have removed. This is not the case. – Andrea Moro May 12 '22 at 05:16
  • Sorry, I lost the last line and updated my answer. The pkla file allows you to hibernate from userspace. Its like a rule. The [Re-enable] was necessary from Ubuntu 18.04 on, otherwise it didn't work. (Do not ask me why they change it intermittently). And if you do not implement the systemd service you should get an error indicator in grub on resume (as if you've turned off the machine via power button) – kanehekili May 12 '22 at 06:50
  • So you are saying that even the definition in the Parentesys can affect the result? In any case, my hibernate works, still cannot make via the system menu. Have to try the other gnome extension. Though I can see a kind of an error that I don't know how to capture on resume. Do you have any idea? – Andrea Moro May 14 '22 at 09:32
  • Eventually using also the gnome-shell-extension-manager (that now seems to work fine in 22.04, it was not on 20.04) I got the extension installed and working and the hibernate entry in the menu.

    1 more question. I made a couple of changes in where the .pkla file, moving it from 50-local.d to 10-vendor.d as per your suggestion. Not sure if this was the item missing (it was working before), and in theory it should have worked as no other files where present below to override the behaviour, and according to the lexicographic order that should have made difference but in fact it was not working

    – Andrea Moro May 14 '22 at 12:53
  • 1
    danger: systemctl hibernate froze the PC, then the PC turned off, but when unplugged from electricity and turned back on - it did not recover the previous state ... – jave.web Oct 05 '22 at 10:13
  • Might happen if one of your drivers are not coping. Hibernate is not guaranteed to work- therefore Ubuntu does not support it out of the box. I did not get it to run with swap files either - only swap partition worked – kanehekili Oct 05 '22 at 18:33
  • On my laptop with a fresh Ubuntu 22.04 installation, the above method didn't work until I disabled the "Secure Boot" from BIOS. – vahid-dan Mar 14 '23 at 18:24
  • Many things do not work in Ubuntu if you've got SecureBoot enabled... I'm surprised you could install at all. – kanehekili Mar 15 '23 at 07:52
2

I followed this tutorial and it worked perfectly for 22.04: https://ubuntuhandbook.org/index.php/2021/08/enable-hibernate-ubuntu-21-10/

Just do:

sudo gedit /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla

And insert this lines:

[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

And then install the Hibernate button extension: https://extensions.gnome.org/extension/755/hibernate-status-button/

  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review – Pilot6 Sep 21 '22 at 15:37
  • 1
    On my laptop with a fresh Ubuntu 22.04 installation, the above method didn't work until I disabled the "Secure Boot" from BIOS. – vahid-dan Mar 14 '23 at 18:25
  • 1
    For Ubuntu 23.10 I can get the following hints: install polkitd-pkla - I was searching for hours to find the reason for not loading the pkla file! – Thomas C. Oct 15 '23 at 18:32
  • Since sudo systemctl hibernate already worked for me because I'd already enabled that feature (maybe via https://distroid.net/enable-hibernate-on-ubuntu/ instructions), I did not need to install this extension after inserting these lines. Thanks. – Ryan Jan 06 '24 at 16:07
  • Nothin happens after i press hibernate after those commands :( – vozman Jan 11 '24 at 16:09
0

If you're using the extension on ubuntu 23.10, do

sudo apt install polkitd-pkla
  • There is no release "Ubuntu 23", the version numbers of Ubuntu alway consist of four digest separated by a dot, like 22.04. Please edit your answer and state the correct version you are using in order to make the answer helpful. – noisefloor Nov 22 '23 at 16:42