如何禁用我的系统进入睡眠状态?

Mik*_*lls 115 suspend power-management

我正在家里的旧 AMD 2400+ 台式机上安装 Web 服务器。我已经安装并运行了 Ubuntu 11.04,但是一段时间后,我无法再浏览到服务器。当我去键盘并按下一个键时,一切又神奇地工作了。

我已经查看了 BIOS,但没有看到启用任何节能功能。在 Ubuntu 中有类似的东西吗?可以禁用吗?

我没有安装任何 GUI。这只是控制台。

Dus*_*and 122

在 Ubuntu 16.04 LTS 上,我成功使用以下命令禁用挂起:

sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
Run Code Online (Sandbox Code Playgroud)

这是重新启用它:

sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target
Run Code Online (Sandbox Code Playgroud)

来自man systemctl

mask NAME...  
           Mask one or more units, as specified on the command line. This
           will link these unit files to /dev/null, making it impossible to
           start them. This is a stronger version of disable, since it
           prohibits all kinds of activation of the unit, including
           enablement and manual activation. Use this option with care. This
           honors the --runtime option to only mask temporarily until the
           next reboot of the system. The --now option may be used to ensure
           that the units are also stopped. This command expects valid unit
           names only, it does not accept unit file paths.

 unmask NAME...
           Unmask one or more unit files, as specified on the command line.
           This will undo the effect of mask. This command expects valid
           unit names only, it does not accept unit file paths.
Run Code Online (Sandbox Code Playgroud)

  • 这对我有用,但有副作用,每当我合上盖子时,CPU 就会无限期地达到 70-100%,因为系统服务“systemd-logind”试图执行挂起服务,但无法执行。解决方案是在“/etc/systemd/logind.conf”中使用“HandleLidSwitch=ignore”忽略盖子 (4认同)
  • 我将如何测试这些是否已被屏蔽?(无论如何,`mask` 或 `unmask` 有什么作用?以前从未听说过这些。) (2认同)

Jas*_*son 35

图形用户界面

你看过:

系统 -> 首选项 -> 电源管理

在交流电源选项卡上,在不活动时让计算机进入睡眠状态:“从不”

终端

你能打开“gconf-editor”吗?

在看: /apps/gnome-power-manager/timeout

尝试设置sleep_computer_ac0

如果还有什么需要改变,我也不乐观。

  • 最新的命令行方式是:`gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout '0' && gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive -电池超时'0'` (12认同)
  • 我该如何在控制台上执行此操作?我没有安装图形用户界面。 (2认同)
  • 同样,我没有安装 gnome 或任何安装。它是一个纯粹的控制台。 (2认同)
  • @dess 很有帮助。谢谢!您应该在答案中发布您的回复供其他人查看。 (2认同)

Mik*_*lls 15

正确答案位于此处

您是否尝试将内核选项添加acpi=off apm=offGRUB_CMDLINE_LINUX_DEFAULTin /etc/default/grub

然后运行sudo update-grub并重新启动计算机。

  • 虽然将这些选项添加到我的 grub 配置中确实阻止了我的机器进入睡眠状态,但应该注意设置 `acpi=off` 有 [很多其他效果](https://help.ubuntu.com/community/BootOptions# Common_Kernel_Options)。对我来说关键之一是它还禁用了超线程。 (4认同)

小智 11

这些描述的解决方案都不适合我。笔记本电脑还在睡觉。使用 acpi=off 的 Grub Linux 命令行选项导致笔记本电脑无法启动。我终于找到了这个解决方案。

sudo vi /etc/default/acpi-support # and then set SUSPEND_METHODS="none"
sudo /etc/init.d/acpid restart
Run Code Online (Sandbox Code Playgroud)

基于 Stephan 的原始解决方案:保持 Ubuntu Server 在关闭盖子的笔记本电脑上运行?


小智 8

除了 systemctl 掩码/取消掩码选项之外,我还使用以下命令打开/关闭 Gnome 桌面的挂起。

gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type 'suspend'
gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'suspend'
Run Code Online (Sandbox Code Playgroud)

或者

gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type 'nothing'
gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing'
Run Code Online (Sandbox Code Playgroud)

我通过探索如何转储所有 dconf/gsettings 中列出的命令显示的设置来发现这些设置,以便我可以在两台不同的机器之间比较它们?


Nit*_*esh 7

请尝试查看这些链接 - Cyber​​citi.bizArch 论坛

这是来自Cyber​​citi.biz链接的摘录:

默认情况下,Linux 内核会使用 screen-save 选项来禁用它,您需要键入以下命令(它会关闭监视器 VESA 节能功能):

$ setterm -powersave off -blank 0
Run Code Online (Sandbox Code Playgroud)

如果它以如下错误转储给您:cannot (un)set powersave mode

您需要关闭 X 窗口系统并重新运行上述命令。更好的是, 将以下两个命令添加到您的 ~/.xinitrc 文件中:

setterm -blank 0 -powersave off -powerdown 0
xset s off
Run Code Online (Sandbox Code Playgroud)


小智 7

只是想指出我对已接受答案的问题并提供替代解决方案:

Maskingsleep.targetsuspend.target使用systemctl确实可以完成这项工作,但知道systemd-logind仍然会尝试调用 sleep.target(或任何一个)!

@Djizeus 报告称,这会导致合上盖子后 CPU 使用率无限期达到 70-100%。就我个人而言,我经历过systemd-logind垃圾邮件发送/var/log/auth.log ,直到它填满磁盘(每秒数十行报告sleep被屏蔽)。

再次摘自 @Djizeus 的评论:“解决方案是忽略带有HandleLidSwitch=ignorein 的盖子/etc/systemd/logind.conf”。

  • 我同意那个。而且,由于我无法在这里发帖(作为菜鸟),所以我的反建议是:编辑 /etc/systemd/sleep.conf ;允许挂起=否 ,允许休眠=否 。另请参见 man systemd-sleep 、 man systemd-sleep.conf 。 (3认同)