如何在 Linux 中禁用挂起和休眠模式

在本文中,我们将引导您了解如何在 Linux 系统上禁用挂起休眠模式。但在我们这样做之前,让我们简要概述一下这两种模式。

当您暂停Linux系统时,您基本上会激活或将其置于睡眠模式。屏幕熄灭,即使计算机保持开机状态。此外,您的所有文档和应用程序都保持打开状态。

在不使用系统时,挂起系统有助于节省电源。恢复使用系统需要简单的鼠标单击或点击任何键盘按钮。有时,您可能需要按下电源按钮。

Linux 中有 3 种挂起模式:

  • 挂起到 RAM(正常挂起):这是大多数笔记本电脑在一定时间内处于非活动状态或在 PC 使用电池运行时合上盖子时自动进入的模式。在这种模式下,电源是为RAM保留的,并且与大多数组件断绝关系。
  • 挂起到磁盘(休眠):在此模式下,计算机状态将保存到交换空间中,并且系统完全关闭电源。但是,打开它后,一切都会恢复,您可以从离开的地方继续。
  • 挂起到两者(混合挂起):在这里,计算机状态保存到交换中,但系统不会关闭。相反,电脑被挂起到 RAM。电池未使用,您可以安全地从磁盘恢复系统并继续工作。此方法比挂起到 RAM 慢得多。

在 Linux 中禁用挂起和休眠

要防止 Linux 系统挂起或进入休眠状态,您需要禁用以下 systemd 目标:

$ sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

您将获得如下所示的输出:

hybrid-sleep.target
Created symlink /etc/systemd/system/sleep.target → /dev/null.
Created symlink /etc/systemd/system/suspend.target → /dev/null.
Created symlink /etc/systemd/system/hibernate.target → /dev/null.
Created symlink /etc/systemd/system/hybrid-sleep.target → /dev/null.

在 Ubuntu 中禁用挂起和休眠

然后重新启动系统并重新登录。

使用以下命令验证更改是否已生效:

$ sudo systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target

验证 Ubuntu 中的挂起和休眠

从输出中,我们可以看到所有四种状态都被禁用了。

在 Linux 中启用挂起和休眠

要重新启用挂起休眠模式,请运行以下命令:

$ sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target

这是您将获得的输出。

Removed /etc/systemd/system/sleep.target.
Removed /etc/systemd/system/suspend.target.
Removed /etc/systemd/system/hibernate.target.
Removed /etc/systemd/system/hybrid-sleep.target.

在 Ubuntu 中启用挂起和休眠

要验证这一点,请运行以下命令;

$ sudo systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target

验证 Ubuntu 中的挂起和休眠

要防止系统在合上盖子时进入挂起状态,请编辑 /etc/systemd/logind.conf 文件。

$ sudo vim /etc/systemd/logind.conf

将以下行追加到文件中。

[Login] 
HandleLidSwitch=ignore 
HandleLidSwitchDocked=ignore

保存并退出文件。请务必重新启动以使更改生效。

以上就是我们关于如何在 Linux 系统上禁用挂起休眠模式的文章。我们希望您发现本指南对您有所帮助。欢迎您的反馈。

  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值