首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在电源管理中启用休眠?

在电源管理中启用休眠?
EN

Unix & Linux用户
提问于 2020-02-17 15:37:12
回答 2查看 2.4K关注 0票数 1

我有一台带有最新版本Linux的笔记本电脑。我设置了一个交换分区,并正常运行pm-hibernate (启动时关闭并继续运行)。然而,在电源管理设置“当电池非常低”冬眠不是一种选择。

我查看了Python程序(/usr/share/cinnamon/cinnamon-settings/modules/cs_power.py),似乎有一段代码可以检查是否可能冬眠:

代码语言:javascript
复制
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,则会出现该选项,但它不起作用。当电池电量不足时,我如何将其设置为hibernate?

EN

回答 2

Unix & Linux用户

回答已采纳

发布于 2020-05-21 16:35:26

我刚刚处理了在LinuxMint19.3肉桂设置上启用休眠的问题。

( A)我第一次学习这门课,https://www.reddit.com/r/linuxmint/comments/93ta9u/enable_冬眠_在……里面_linux_薄荷_19_塔拉/

注意:请确保您有足够大的交换分区。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)。用您最喜欢的编辑器打开这个文件(在根特权下),并将这些行粘贴到其中并保存它:默认情况下重新启用hibernate Identity=unix-user:* Action=org.freedesktop.upower.hibernate ResultActive=yes 默认情况下,在logind中重新启用hibernate. 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,所以用交换分区4的实际uuid替换该字符串。通过执行以下命令更新grub配置:sudo update-grub

  • 它使hibernation可以使用systemctl hibernate命令。
  • 但是hibernate按钮没有显示在断电窗口中,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特权下),并将这些行粘贴到其中并保存它:默认情况下,在upower中重新启用hibernate Identity=unix-user:* Action=org.freedesktop.upower.hibernate ResultActive=yes 默认情况下,在logind中重新启用hibernate. Identity=unix-user:* Action=org.freedesktop.login1.hibernate ResultActive=yes

  • Hibernate按钮和选项现在可以在我的设置!

希望这能有所帮助。

票数 3
EN

Unix & Linux用户

发布于 2020-08-01 18:48:47

你可能会发现我的小向导很有用!我在冬眠中挣扎了一段时间。

票数 2
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/568093

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档