使用hibernate而不是pm-hibernate强制hibernate

我正在运行18.04并试图让我的系统在我的笔记本电脑的盖子关闭时使用hibernate而不是pm-hibernate。

我在16GB内存上有20GB的交换分区,所以空间充足。

当我使用pm-hibernate时,我得到一个小的apci错误,当我hibernate和恢复我无法读取时,它会很快弹出。 虽然hibernate工作在某种意义上似乎转储到磁盘并从磁盘恢复,但似乎是睡眠状态,因为它以正常速率使用电池,而不是完全关闭并停止使用电池。

但是,当我使用hibernate安装时:

sudo apt-get install hibernate 

并运行:

 sudo hibernate 

从那恢复,我注意到我的机器确实关机了 – LED停止悸动等等 – 电池使用量变为零。 这是我想要在盖子关闭时看到的行为,而不是使用电池的睡眠行为,就像我正在积极使用计算机一样。

我遵循了这些指南:

  • 如何启用hibernate?

改性

 /etc/systemd/logind.conf 

包括:

 #HandleLidSwitch=suspend HandlelidSwitch=hibernate 

并添加了我的交换分区更改:

 /etc/default/grub 

要包含正确的resume = link,并请求s2disk专门用于:

 sudo cat /etc/pm/config.d/00sleep_module SLEEP_MODULE="swsusp" 

我已经阅读了以下相关的askubuntus:

  • Hibernate在盖子关闭
  • Ubuntu 17.04 hibernate工作但pm-hibernate没有
  • 笔记本电脑锁屏而不是冬眠
  • 如何让linux更喜欢sudo pm-hibernate而不是systemctl hibernate作为默认值?
  • 睡眠模式的耗电量与笔记本电脑使用时的耗电量相同
  • 将默认的hibernate方法替换为s2disk

我也在联想和Arch论坛上阅读了这些链接:

  • https://forums.lenovo.com/t5/Linux-Discussion/X1-Carbon-Gen-6-cannot-enter-deep-sleep-S3-state-aka-Suspend-to/td-p/3998182/page/ 4
  • https://forums.lenovo.com/t5/Linux-Discussion/X1-Gen6-Massive-battery-drain-in-suspend-No-deep-sleep-support/mp/3997789
  • https://wiki.archlinux.org/index.php/Lenovo_ThinkPad_X1_Carbon_(Gen_6)
  • https://wiki.archlinux.org/index.php/Power_management/Sus​​pend_and_hibernate

如何确保关闭时调用的hibernate是hibernate而不是pm-hibernate?

更新

这仍然是一个问题,仍然使得使用ubuntu的Carbon X1第6代基本没用。 任何可以修复此问题并且可能另外添加登录提示的解决方案可能几乎与4年前的Windows机器一样好……;)

我也讨厌传递URL,因此我将复制并粘贴信息并将网页附加到底部。 我在你的链接中没有看到这个。

阅读本文时,我注意到如果使用btrfs文件系统格式化,hibernate可能无法正常工作? 那么,如何在Ubuntu 16.04中永久启用hibernate模式?

要使Ubuntuhibernate过程永久化,您需要在命令行上使用文本编辑器创建新文件:

 sudo nano /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla 

系统需要root权限才能启用hibernate选项,因此应添加命令sudo。 您可以使用其他文本编辑器,如vi,gedit,emacs等。

现在,将以下文本复制并粘贴到文件中(使用鼠标;键盘快捷键不起作用):

 [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 

CTRL + O保存,按CTRL + X退出nano编辑器。

现在,注销您的系统,然后再次登录。 现在,您将看到一个hibernate选项,以及“关闭”和“暂停”选项。

您方便的链接是: https : //fossbytes.com/enable-disable-hibernate-option-ubuntu-power-menu/

两种选择

第一个选项(列在第二个选项)是查看journalctl以获取与hibernate相关的可能错误消息。 如果第一个选项没有产生结果,则第二个选项是创建一个包装器脚本,将pm-hibernate替换为`hibernate。

创建包装器脚本

创建包装器脚本允许hibernate替换pm-hibernate

查找目录中的命令

在创建包装器脚本之前,您需要知道hibernatepm-hibernate命令所在的目录。 使用这两个命令:

 $ locate bin/hibernate /mnt/c/Program Files (x86)/CyberPower PowerPanel Business Edition/bin/hibernate.dll $ locate bin/pm-hibernate /mnt/clone/usr/sbin/pm-hibernate /mnt/old/usr/sbin/pm-hibernate /usr/sbin/pm-hibernate 

您要创建的包装器脚本将是/usr/sbin/pm-hibernate 。 我没有安装hibernate包,因此第一次搜索只找到一个Windows实用程序。 根据包文件列表 ,它应该显示/usr/sbin/hibernate以及其他几个文件。

备份原始文件

首先,我们要制作原始文件的在线备份副本:

 sudo cp -a /usr/sbin/pm-hibernate /usr/sbin/pm-hibernate.bak 

接下来删除原始文件:

 sudo rm -f /usr/sbin/pm-hibernate 

创建包装脚本

注意:代替包装器脚本很多人发现为pm-hibernate创建一个符号链接更容易hibernate : 如何创建一个软链接或符号链接?

我喜欢使用gedit进行编辑,但您可以使用nanovim或您喜欢的任何编辑器替换它:

 sudo -H gedit /usr/sbin/pm-hibernate 

将出现一个空文件。 粘贴以下行

 #!/bin/bash # Wrapper script to replace pm-hibernate with hibernate package /usr/sbin/hibernate "$@" 

将包装脚本转换为可执行文件

目前,包装器脚本是常规文件。 我们需要将其转换为可执行对象:

 sudo chmod a+x /usr/sbin/pm-hibernate 

我们现在有一个可操作的包装器脚本,因此每次调用pm-hibernate都会调用hibernate 。 如上所述,您应该在创建包装器脚本之前先查看journalctl (下面介绍)。

审查journalctl

您可以在journalctl查看hibernate消息以journalctl可能出现的问题。

我不使用hibernate,但我确实使用暂停。 以下命令允许我查看与suspend相关的所有消息,您将用hibernate替换它们:

 $ journalctl -b | grep -i suspend Oct 09 22:26:33 alien eyesome[21740]: Lid Open/Close: Wait 3 seconds to see if suspending Oct 09 22:26:48 alien systemd[1]: Starting TLP suspend/resume... Oct 09 22:26:48 alien systemd[1]: Started TLP suspend/resume. Oct 09 22:26:48 alien systemd[1]: Starting Suspend... Oct 09 22:26:48 alien systemd-sleep[22938]: /lib/systemd/system-sleep/sound: Going to suspend... Oct 09 22:26:48 alien eyesome[22952]: Wakeup: Going to suspend. Creating: /tmp/eyesome-is-suspending Oct 09 22:26:49 alien systemd-sleep[22938]: Suspending system... Oct 10 04:26:38 alien kernel: PM: Suspending system (mem) Oct 10 04:26:38 alien kernel: Suspending console(s) (use no_console_suspend to debug) Oct 10 04:26:38 alien kernel: PM: suspend of devices complete after 1142.044 msecs Oct 10 04:26:38 alien kernel: PM: late suspend of devices complete after 19.766 msecs Oct 10 04:26:38 alien kernel: PM: noirq suspend of devices complete after 61.505 msecs Oct 10 04:26:38 alien kernel: Suspended for 21583.011 seconds Oct 10 04:26:38 alien eyesome[23137]: Lid Open/Close: Wait 3 seconds to see if suspending Oct 10 04:26:38 alien systemd-sleep[22938]: /lib/systemd/system-sleep/sound: Waking up from suspend... Oct 10 04:26:38 alien eyesome[23168]: Wakeup: Called from suspend. Oct 10 04:26:41 alien systemd[1]: Started Suspend. Oct 10 04:26:41 alien systemd[1]: Stopping TLP suspend/resume... Oct 10 04:26:41 alien systemd[1]: Reached target Suspend. Oct 10 04:26:41 alien systemd[1]: suspend.target: Unit is bound to inactive unit systemd-suspend.service. Stopping, too. Oct 10 04:26:41 alien systemd[1]: Stopped target Suspend. Oct 10 04:26:42 alien systemd[1]: Stopped TLP suspend/resume. Oct 10 04:26:52 alien eyesome[24459]: Daemon: Removed file: /tmp/eyesome-is-suspending Oct 10 05:47:09 alien eyesome[12434]: Lid Open/Close: Wait 3 seconds to see if suspending Oct 10 05:51:43 alien systemd[1]: Starting TLP suspend/resume... Oct 10 05:51:44 alien systemd[1]: Started TLP suspend/resume. Oct 10 05:51:44 alien systemd[1]: Starting Suspend... Oct 10 05:51:44 alien systemd-sleep[28353]: /lib/systemd/system-sleep/sound: Going to suspend... Oct 10 05:51:44 alien eyesome[28367]: Wakeup: Suspending. Creating /tmp/eyesome-is-suspending Oct 10 05:51:45 alien systemd-sleep[28353]: Suspending system... Oct 10 16:30:59 alien kernel: PM: Suspending system (mem) Oct 10 16:30:59 alien kernel: Suspending console(s) (use no_console_suspend to debug) Oct 10 16:30:59 alien kernel: PM: suspend of devices complete after 623.519 msecs Oct 10 16:30:59 alien kernel: PM: late suspend of devices complete after 19.654 msecs Oct 10 16:30:59 alien kernel: PM: noirq suspend of devices complete after 61.549 msecs Oct 10 16:30:59 alien kernel: Suspended for 38348.943 seconds Oct 10 16:30:59 alien eyesome[28563]: Lid Open/Close: Wait 3 seconds to see if suspending Oct 10 16:30:59 alien systemd-sleep[28353]: /lib/systemd/system-sleep/sound: Waking up from suspend... Oct 10 16:30:59 alien eyesome[28599]: Wakeup: Called from suspend. Oct 10 16:31:02 alien systemd[1]: Started Suspend. Oct 10 16:31:02 alien systemd[1]: Stopping TLP suspend/resume... Oct 10 16:31:02 alien systemd[1]: Reached target Suspend. Oct 10 16:31:02 alien systemd[1]: suspend.target: Unit is bound to inactive unit systemd-suspend.service. Stopping, too. Oct 10 16:31:02 alien systemd[1]: Stopped target Suspend. Oct 10 16:31:03 alien systemd[1]: Stopped TLP suspend/resume. Oct 10 16:31:13 alien eyesome[30020]: Daemon: Removed file: /tmp/eyesome-is-suspending