如何启用hibernate?
在Ubuntu 12.04及更新版本中, 默认情况下已在policykit中禁用hibernate模式 。 我怎样才能启用它?
如果这个答案在Ubuntu 13.10中不起作用,请参阅此处以获得替代答案
您可以在此处关注官方文档。 对于未通过Ubuntu认证的计算机,12.04 禁用了hibernate模式。
为了启用hibernate,您需要通过在终端中运行sudo pm-hibernate
来测试它是否正常工作。 系统将尝试hibernate。 如果您能够再次启动系统,那么添加覆盖或多或少是安全的。
为此,请开始编辑:
sudo nano /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
用这个填写:
[Re-enable hibernate by default] Identity=unix-user:* Action=org.freedesktop.upower.hibernate ResultActive=yes
或者在14.04及之后:
[Re-enable hibernate by default for login1] Identity=unix-user:* Action=org.freedesktop.login1.hibernate ResultActive=yes [Re-enable hibernate for multiple users by default in logind] Identity=unix-user:* Action=org.freedesktop.login1.hibernate-multiple-sessions ResultActive=yes
按Ctrl – O保存,然后按Ctrl – X 进入然后退出nano。
重启和hibernate又回来了!
或者运行killall unity-panel-service
来重置菜单。
然后,一些用户需要运行sudo update-grub
才能在电源菜单中使用hibernate选项。 某些用户可能还必须至少注销然后登录才能使其显示在(右上角)电源菜单中。
首先,您需要测试您的机器是否支持hibernate。 使用以下命令测试它:
sudo pm-hibernate # or for newer Ubuntus like 17.04 sudo systemctl hibernate
Ubuntu 16.04及以上版本
要在界面中启用,您需要运行sudo nano /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
并填写:
[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;org.freedesktop.login1.hibernate-multiple-sessions ResultActive=yes
Ubuntu 14.04和15.04
要在界面中启用,您需要为Ubuntu 14.04和15.04运行sudo nano /etc/polkit-1/localauthority.conf.d/52-enable-hibernation.conf
并填写:
[Re-enable hibernate by default] Identity=unix-user:* Action=org.freedesktop.upower.hibernate ResultActive=yes [Re-enable hibernate by default for login1] Identity=unix-user:* Action=org.freedesktop.login1.hibernate;org.freedesktop.login1.hibernate-multiple-sessions ResultActive=yes
它有几个节,因为你可能有多个用户(因此不依赖于多用户或更高的管理员而不是login1)
ps:官方最新文档https://help.ubuntu.com/stable/ubuntu-help/power-hibernate.html
此外,对于那些想要禁用暂停按钮的人(出于各种原因),请按类似方式进行…
选择任何文件名,但这是一个详细/约定:
sudoedit /etc/polkit-1/localauthority/50-local.d/com.ubuntu.disable-suspend.pkla
用这个填写:
[Disable suspend by default] Identity=unix-user:* Action=org.freedesktop.upower.suspend ResultActive=no
Ctrl + O , Enter , Ctrl + X.
无需重新启动,进入关机菜单后应立即关闭。
还有一件事:
如果要将hibernate选项添加到XFCE的面板,则必须右键单击您的名称(顶部)并选择properties
。
之后会弹出一个屏幕:
确保你像我一样检查Hibernate。
首先,我建议您测试您的笔记本电脑是否支持hibernate,因为默认情况下禁用hibernate的原因是因为它有时会在某些计算机上产生致命的结果。 通过测试你的机器
按Ctrl + Alt + T然后sudo pm-hibernate
你的机器应该hibernate。 hibernate后唤醒机器并观察其是否行为exception或是否正常。 如果您在hibernate后遇到任何exception,我建议您不要继续以下步骤。 但是,如果它工作正常,继续激活hibernate
sudo gedit /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
编辑打开的文件并添加以下行:
[Re-enable hibernation] Identity=unix-user:* Action=org.freedesktop.upower.hibernate ResultActive=yes
在此之后,重新启动计算机,登录后,您应该会在右上角的设置角看到hibernate选项。
如果使用/etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
的响应在我的情况下不起作用,请不要忘记删除该文件:
sudo rm /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
并尝试使用TuxOnIce 。
首先要确保你有足够的掉期。 它应该与RAM的大小相同或更大。 使用命令
free
规则交换>记忆。 如果不是这种情况,请扩大交换大小。 然后安装TuxOnIce
sudo add-apt-repository ppa:tuxonice/ppa sudo apt-get update sudo apt-get install tuxonice-userui linux-generic-tuxonice linux-headers-generic-tuxonice
然后你可以尝试通过以下方式运行hibernate测试:
sudo pm-hibernate
在你做之前不要忘记保存你的工作。
如果一切顺利,您的计算机将关闭。 打开电源后,您将使桌面处于hibernate状态之前的状态。
使用脚本启用hibernate
我已经翻译了bash
脚本的上述答案。 这使得在多台机器上安装不那么烦人。
脚本enable-hibernate
:
#!/bin/bash #http://askubuntu.com/a/94963/164341 cat << '_EOF_' |sudo tee /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla [Enable Hibernate] Identity=unix-user:* Action=org.freedesktop.upower.hibernate ResultActive=yes _EOF_ clear echo echo 'Hibernate enabled.' echo
脚本disable-suspend
:
#!/bin/bash #http://askubuntu.com/a/154821/164341 cat << '_EOF_' |sudo tee /etc/polkit-1/localauthority/50-local.d/com.ubuntu.disable-suspend.pkla [Disable suspend by default] Identity=unix-user:* Action=org.freedesktop.upower.suspend ResultActive=no _EOF_ clear echo echo 'Suspend disabled.' echo
注意:不要忘记chmod +x
两个脚本使它们可执行。
一个简单的命令,它与接受的答案完全相同,但非交互式:
cat <
在12.04,我在指标菜单中成功启用了hibernate选项来hibernate。 但是我还是无法从hibernate中成功恢复。 我确实按照这些步骤来解决此问题:
在12.04中启用Hibernate
为了启用Hibernate,我遵循了Dima的回答 。
启用hibernate后,我可以hibernate。 但问题是,我无法从hibernate成功恢复。 任何时候我从hibernate启动我的电脑,它就像正常启动一样启动。 所以,我必须做这些事情才能从hibernate状态恢复。
修复程序能够从hibernate状态恢复
有两种方法可以解决这个问题。
1.编辑/etc/initramfs-tools/conf.d/resume
文件
-
首先获取交换分区的UUID。
sudo blkid | grep swap
这将输出类似于这样的行:
/dev/sda12: UUID="a14f3380-810e-49a7-b42e-72169e66c432" TYPE="swap"
实际的行与此不匹配。 在
"..."
双引号之间复制UUID的值。 -
打开简历文件
gksudo gedit /etc/initramfs-tools/conf.d/resume
在该文件中,添加如下所示的行
RESUME=UUID=a14f3380-810e-49a7-b42e-72169e66c432
不要忘记替换从步骤1获得的实际UUID值。保存文件并退出gedit
-
然后在终端中执行此命令
sudo update-initramfs -u
您现在可以从hibernate状态恢复
2.编辑/etc/default/grub
文件。
-
打开终端并执行以下命令将其打开
gksudo gedit / etc / default / grub
-
会有像
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
。 编辑行以在单词splash
之后插入RESUME=UUID=
。例如,在我的情况下,编辑后该行看起来像这样
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=a14f3380-810e-49a7-b42e-72169e66c432"
确保您使用了从
sudo blkid | grep swap
获得的UUID值sudo blkid | grep swap
命令。 -
然后执行此命令
sudo update-grub
这也使您能够成功从hibernate恢复。
测试了两个Ubuntu安装,都工作
我的笔记本上有Ubuntu Gnome 17.04 amd64。 我执行了以下操作以启用hibernate:
$ sudo apt-get install hibernate
( source )
这也安装了libx86-1
uswsusp
vbetool
然后我可以用sudo systemctl hibernate
成功sudo systemctl hibernate
。 我的路径中没有pm-hibernate
可执行文件。
$ sudo nano /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
已插入:( 来源 )
[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;org.freedesktop.login1.handle-hibernate-key;org.freedesktop.login1;org.freedesktop.login1.hibernate-multiple-sessions;org.freedesktop.login1.hibernate-ignore-inhibit ResultActive=yes
已安装https://extensions.gnome.org/extension/755/hibernate-status-button/