Linux-Mint

在電源管理中啟用休眠?

  • August 1, 2020

我有一台裝有最新版本 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_hibernateTrue,則會出現該選項,但它不起作用。電量不足時如何設置休眠?

我剛剛處理了在我的 Linux Mint 19.3 Cinnamon 設置上啟用休眠功能。

A)我首先遵循這個tuto,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,所以用你的交換分區的實際 uuid 替換那個字元串

4.) 通過執行以下命令更新 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
  • 我的設置現在可以使用休眠按鈕和選項!

希望這可以幫助。

引用自:https://unix.stackexchange.com/questions/568093