1

I have a laptop with the latest version of Linux Mint. I set up a swap partition and running pm-hibernate works normally (shuts down and resumes when booting). However, in Power Management settings "When the battery is critically low" hibernation is not an option. Image of no option I looked at the Python config program (/usr/share/cinnamon/cinnamon-settings/modules/cs_power.py) and there seems to be a block of code that checks if hibernation is possible:

def get_available_options(up_client):
    can_suspend = False
    can_hibernate = False
    can_hybrid_sleep = False

    # Try logind first
    try:
        connection = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
        proxy = Gio.DBusProxy.new_sync(
            connection,
            Gio.DBusProxyFlags.NONE,
            None,
            "org.freedesktop.login1",
            "/org/freedesktop/login1",
            "org.freedesktop.login1.Manager",
            None)

        can_suspend = proxy.CanSuspend() == "yes"
        can_hibernate = proxy.CanHibernate() == "yes"
        can_hybrid_sleep = proxy.CanHybridSleep() == "yes"
    except:
        pass

    # Next try ConsoleKit
    try:
        connection = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
        proxy = Gio.DBusProxy.new_sync(
            connection,
            Gio.DBusProxyFlags.NONE,
            None,
            "org.freedesktop.ConsoleKit",
            "/org/freedesktop/ConsoleKit/Manager",
            "org.freedesktop.ConsoleKit.Manager",
            None)

        can_suspend = can_suspend or (proxy.CanSuspend() == "yes")
        can_hibernate = can_hibernate or (proxy.CanHybridSleep() == "yes")
        can_hybrid_sleep = can_hybrid_sleep or (proxy.CanHybridSleep() == "yes")
    except:
        pass

    def remove(options, item):
        for option in options:
            if option[0] == item:
                options.remove(option)
                break

    lid_options = [
        ("suspend", _("Suspend")),
        ("shutdown", _("Shutdown immediately")),
        ("hibernate", _("Hibernate")),
        ("blank", _("Lock Screen")),
        ("nothing", _("Do nothing"))
    ]

    button_power_options = [
        ("blank", _("Lock Screen")),
        ("suspend", _("Suspend")),
        ("shutdown", _("Shutdown immediately")),
        ("hibernate", _("Hibernate")),
        ("interactive", _("Ask")),
        ("nothing", _("Do nothing"))
    ]

    critical_options = [
        ("shutdown", _("Shutdown immediately")),
        ("hibernate", _("Hibernate")),
        ("nothing", _("Do nothing"))
    ]

    if not can_suspend:
        for options in lid_options, button_power_options, critical_options:
            remove(options, "suspend")

    if not can_hibernate:
        for options in lid_options, button_power_options, critical_options:
            remove(options, "hibernate")

    return lid_options, button_power_options, critical_options, can_suspend, can_hybrid_sleep

If I set can_hibernate to True after this code, the option appears, but it doesn't work. How can I set it to hibernate when battery is low?

LostXOR
  • 203
  • 2
  • 9
  • Maybe you will find my [little guide](https://unix.stackexchange.com/questions/602406/guide-on-how-to-enable-hibernation-on-linux-mint-20-cinnamon-ubuntu-20-and-pre) helpful! – Texno Aug 01 '20 at 18:47
  • Is this helpful `echo -n mem >/sys/power/state` – atheros Sep 18 '20 at 08:52

2 Answers2

3

i just dealt with enabling hibernation on my Linux Mint 19.3 Cinnamon setup.

A) I first followed this tuto, https://www.reddit.com/r/linuxmint/comments/93ta9u/enable_hibernation_in_linux_mint_19_tara/

NOTE: Be sure you have SWAP partition which is big enough.

1.) Create file with name "com.ubuntu.enable-hibernate.pkla" in "/etc/polkit-1/localauthority/50-local.d" :

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

2.) Open this file with your favorite editor (under root privileges) and paste these lines in it and save it:

[Re-enable hibernate by default]
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
ResultActive=yes

3.) Edit this line in file "/etc/default/grub" so it looks like this:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=swap_partition_uuid"

swap_partition_uuid - you can find this UUID in file "/etc/fstab", so replace that string with your actual uuid of swap partition

4.) Update grub configuration by executing this command:

sudo update-grub

  • It made hibernation work with the systemctl hibernate command.

  • But the hibernate button wasn't displayed in the power-off window, nor was the hibernate options displayed in the power management settings (which is what you seemed interested in ;))

B) I then created the /var/lib/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla file as described in this tuto, http://linuxg.net/how-to-enable-hibernation-and-add-the-hibernate-button-to-the-shutdown-menu-on-ubuntu-14-04-trusty-tahr/.

I edited some parts of the quote for more clarity.

1.) Create file with name "com.ubuntu.enable-hibernate.pkla" in "/var/lib/polkit-1/localauthority/50-local.d" :

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

2.) Open this file with your favorite editor (under root privileges) and paste these lines in it and save it:

[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
ResultActive=yes
  • Hibernate button and options are now available on my setup !

Hope this helps.

remym19
  • 48
  • 4
  • @roaima: Thanks, I didn't pay attention. Accounts merged :) – remym19 Jun 05 '20 at 07:20
  • I just figured out that hibernation cannot work with Secure Boot enabled (at the moment and with Linux Mint 19.3). It has to do with **security** when resuming from hibernation. [Source](https://askubuntu.com/questions/1106105/18-04-hibernate-with-uefi-and-secure-boot-enabled) – remym19 Jun 05 '20 at 11:52
2

You might find my little guide helpful! I have been struggling for a while with hibernation.

Texno
  • 171
  • 1
  • 1
  • 5