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.
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?