我有一台装有最新版本 Linux Mint 的笔记本电脑。我设置了交换分区并pm-hibernate
正常运行(启动时关闭并恢复)。但是,在电源管理设置中,“当电池电量严重不足时”休眠不是一个选项。
我查看了 Python 配置程序 ( /usr/share/cinnamon/cinnamon-settings/modules/cs_power.py
),似乎有一段代码用于检查是否可以休眠:
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
如果我设置can_hibernate
为True
在此代码之后,则会出现该选项,但它不起作用。如何设置电池电量低时休眠?
答案1
我刚刚处理了在 Linux Mint 19.3 Cinnamon 设置上启用休眠的问题。
A)我首先遵循了这个教程,https://www.reddit.com/r/linuxmint/comments/93ta9u/enable_hibernation_in_linux_mint_19_tara/
注意:确保您有足够大的 SWAP 分区。
1.) 在“/etc/polkit-1/localauthority/50-local.d”中创建名为“com.ubuntu.enable-hibernate.pkla”的文件:
sudo touch /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
2.) 使用您最喜欢的编辑器(在 root 权限下)打开此文件,并将这些行粘贴到其中并保存:
[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.) 在文件“/etc/default/grub”中编辑此行,使其看起来像这样:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=swap_partition_uuid"
swap_partition_uuid
- 您可以在文件“/etc/fstab”中找到此 UUID,因此将该字符串替换为交换分区的实际 UUID4.) 通过执行以下命令更新 grub 配置:
sudo update-grub
它使休眠与
systemctl hibernate
命令一起工作。但是休眠按钮没有显示在关机窗口中,休眠选项也没有显示在电源管理设置中(这正是您感兴趣的;))
B)然后我/var/lib/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
按照本教程中的描述创建了文件,http://linuxg.net/how-to-enable-hibernation-and-add-the-hibernate-button-to-the-shutdown-menu-on-ubuntu-14-04-trusty-tahr/。
为了更加清晰,我编辑了引文的某些部分。
1.) 在“/var/lib/polkit-1/localauthority/50-local.d”中创建名为“com.ubuntu.enable-hibernate.pkla”的文件:
sudo touch /var/lib/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
2.) 使用您最喜欢的编辑器(在 root 权限下)打开此文件,并将这些行粘贴到其中并保存:
[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
- 休眠按钮和选项现在在我的设置中可用!
希望这可以帮助。
答案2
你可能会发现我的小导游有帮助!我已经在冬眠中挣扎了一段时间。