如何禁用Debian系统睡眠?

Debian-Like

1 前言

一个问题,一篇文章,一出故事。
笔者笔记本安装Debian后发现ssh一段时间后自动断开连接,于是想到需要禁用系统睡眠(休眠)功能。

2 最佳实践

2.1 方法一

vim /etc/default/grub

参数修改如下,

#GRUB_CMDLINE_LINUX_DEFAULT="quiet"
GRUB_CMDLINE_LINUX_DEFAULT="quiet acpi=off apm=off"

更新grub

update-grub

2.2 方法二

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

可见如下显示,

● sleep.target - Sleep
     Loaded: loaded (/lib/systemd/system/sleep.target; static)
     Active: inactive (dead)
       Docs: man:systemd.special(7)

● suspend.target - Suspend
     Loaded: loaded (/lib/systemd/system/suspend.target; static)
     Active: inactive (dead)
       Docs: man:systemd.special(7)

● hibernate.target - Hibernate
     Loaded: loaded (/lib/systemd/system/hibernate.target; static)
     Active: inactive (dead)
       Docs: man:systemd.special(7)

● hybrid-sleep.target - Hybrid Suspend+Hibernate
     Loaded: loaded (/lib/systemd/system/hybrid-sleep.target; static)
     Active: inactive (dead)
       Docs: man:systemd.special(7)

执行如下命令,

systemctl mask sleep.target suspend.target hibernate.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.

再次执行如下命令,

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

可见如下显示,

● sleep.target
     Loaded: masked (Reason: Unit sleep.target is masked.)
     Active: inactive (dead)

● suspend.target
     Loaded: masked (Reason: Unit suspend.target is masked.)
     Active: inactive (dead)

● hibernate.target
     Loaded: masked (Reason: Unit hibernate.target is masked.)
     Active: inactive (dead)

● hybrid-sleep.target
     Loaded: masked (Reason: Unit hybrid-sleep.target is masked.)
     Active: inactive (dead)

如需要反向操作,请执行如下命令,

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.

======================
https://blog.51cto.com/u_14867519/4004778
https://blog.csdn.net/qq_30000313/article/details/110234459
https://blog.csdn.net/weixin_45980458/article/details/122952607

没有评论

发表回复

Debian-Like
如何部署Ubuntu Apache Directory Studio?

1 前言 一个问题,一篇文章,一出故事。 由于笔者需要访问LDAP服务器,所以需要安装一个LDAP的 …

Debian-Like
如何安装Ubuntu 24.04.1 QQ音乐?

1 前言 一个问题,一篇文章,一出故事。 笔者发现QQ音频安装有点特殊,于是整理记录。 2 最佳实践 …

Debian-Like
如何安装Debian LibreOffice?

1 前言 一个问题,一篇文章,一出故事。 笔者最近发现FreeOffice需要注册,因此决定还是安装 …