分享最新优惠信息
购买主机更加划算

Linux系统禁用/启用挂起和休眠模式的简单方法介绍

在本文中,小编将简单介绍如何在Linux系统上禁用挂起(suspend)休眠(hibernation)模式。但是在操作之前,首先简要概述一下这两种模式。

当挂起Linux系统时,基本上是将其激活或置于睡眠模式。即使计算机仍保持开机状态,屏幕也会关闭。同样,所有的文档和应用程序都保持打开状态。

在不使用操作系统时,挂起系统有助于节省电源。要恢复使用系统,只需单击鼠标或单击任意键盘按钮即可。有时可能需要按电源按钮。

Linux系统中有3种挂起模式:

  • 挂起到RAM(正常挂起):大多数情况下,如果笔记本计算机使用电池运行,笔记本电脑在一定时间内不活动或关闭机盖时自动进入此模式。在这种模式下,为RAM保留了电源,并从大多数组件中切断了电源。
  • 挂起到磁盘(休眠):在此模式下,计算机状态保存到交换空间中,并且系统已完全关闭电源。但是,将其打开后,所有内容都会恢复,然后从离开的地方接起。
  • 两者都挂起(混合挂起):此处,计算机状态保存到交换中,但是系统不会关闭。而是将PC挂在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中验证挂起和休眠状态

《在Ubuntu中启用挂起和休眠》

然后重新引导系统并再次登录,使用以下命令验证更改是否已生效:

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

在Ubuntu中启用挂起和休眠

《在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中验证挂起和休眠状态

《在Ubuntu中启用挂起和休眠》

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

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

在Ubuntu中验证挂起和休眠状态

《在Ubuntu中验证挂起和休眠状态》

为了防止系统在合上lid之后进入挂起状态,请编辑/etc/systemd/logind.conf文件。

$ sudo vim /etc/systemd/logind.conf

将以下行添加到文件。

[Login] 
HandleLidSwitch=ignore 
HandleLidSwitchDocked=ignore

保存并退出文件,然后重新启动系统,以使更改生效。

总结

以上就是关于Linux系统禁用/启用挂起和休眠模式的简单介绍,主要涵盖了在Linux系统上禁用挂起和休眠模式的内容,仅供参考,希望对大家有所帮助。

注意:本文对Ubuntu、Centos等系统均通用。

未经允许不得转载:惠主机 » Linux系统禁用/启用挂起和休眠模式的简单方法介绍

相关文章