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?

3
  • 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
    Commented May 1, 2022 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 Commented May 3, 2022 at 5:07
  • @kanehekili by any chance can you send over the hints on how to modify the system menu? Commented May 10, 2022 at 5:30

3 Answers 3

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)

10
  • 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. Commented May 12, 2022 at 5: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? Commented May 12, 2022 at 5: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. Commented May 12, 2022 at 5: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
    Commented May 12, 2022 at 6:50
  • 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
    Commented Oct 5, 2022 at 10:13
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/

5
  • 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
    Commented Sep 21, 2022 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
    Commented Mar 14, 2023 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.
    Commented Oct 15, 2023 at 18:32
  • Since sudo systemctl hibernate already worked for me because I'd already enabled that feature (maybe via distroid.net/enable-hibernate-on-ubuntu instructions), I did not need to install this extension after inserting these lines. Thanks.
    – Ryan
    Commented Jan 6 at 16:07
  • Nothin happens after i press hibernate after those commands :(
    – vozman
    Commented Jan 11 at 16:09
0

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

sudo apt install polkitd-pkla
1
  • 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
    Commented Nov 22, 2023 at 16:42

You must log in to answer this question.

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