收起左侧

笔记本盒盖休眠控制(详解版)

8
回复
5317
查看
[ 复制链接 ]

8

主题

16

回帖

0

牛值

江湖小虾

2024-11-26 10:07:34 显示全部楼层 阅读模式

ssh后提权

ssh登录后,输入 sudo -i,然后输入登录密码

image.png

查看电源设置

root@good-home:~# cat /etc/systemd/logind.conf 
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it under the
#  terms of the GNU Lesser General Public License as published by the Free
#  Software Foundation; either version 2.1 of the License, or (at your option)
#  any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the logind.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
#
# Use 'systemd-**yze cat-config systemd/logind.conf' to display the full config.
#
# See logind.conf(5) for details.

[Login]
#NAutoVTs=6
#ReserveVT=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#InhibitDelayMaxSec=5
#UserStopDelaySec=10
#HandlePowerKey=poweroff
#HandlePowerKeyLongPress=ignore
#HandleRebootKey=reboot
#HandleRebootKeyLongPress=poweroff
#HandleSuspendKey=suspend
#HandleSuspendKeyLongPress=hibernate
#HandleHibernateKey=hibernate
#HandleHibernateKeyLongPress=ignore
#HandleLidSwitch=lock
#HandleLidSwitchExternalPower=suspend
#HandleLidSwitchDocked=ignore
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
#LidSwitchIgnoreInhibited=yes
#RebootKeyIgnoreInhibited=no
#HoldoffTimeoutSec=30s
#IdleAction=ignore
#IdleActionSec=30min
#RuntimeDirectorySize=10%
#RuntimeDirectoryInodesMax=
#RemoveIPC=yes
#InhibitorsMax=8192
#SessionsMax=8192
#StopIdleSessionSec=infinity
root@good-home:~#

Handle开头的

#HandlePowerKey=poweroff #  按下电源键后如何
#HandleSuspendKey=suspend # 待机挂起后如何
#HandleHibernateKey=hibernate # 按下休眠键后如何
#HandleLidSwitch=suspend # 合上笔记本盖后如何
#HandleLidSwitchDocked=ignore # 合上笔记本盖后外接显示器如何

可选的参数值

参数 说明
ignore 忽略,啥也不干
power off 关电源
reboot 重启
halt 挂起。停止所有的 CPU 功能,但是仍然保持通电。
suspend 待机
hibernate 进入休眠(内存数据存入硬盘,关闭电源)
hybrid-sleep 混合睡眠=睡眠+休眠,主要是为台式机设计的,内存和CPU还是活的。
lock 锁屏,机器继续跑(相当于Win+L)

其他选项

#LidSwitchIgnoreInhibited=yes # 合上笔记本盖子时是否应该忽略被某些应用程序所发出的“禁止休眠”的请求
  • 当设置为 yes 时,无论如何都执行 HandleLidSwitch的定义,即无论应用程序发出任何关于系统状态控制请求,都不会被执行,而是以 HandleLidSwitch为准。
  • 当设置为 no 时,不受 HandleLidSwitch约束。即如果有应用程序发出请求,要求在合盖时不进行休眠或其他操作,系统将不会执行 HandleLidSwitch 定义的行为。

修改配置

保存时要用 :wq

vim /etc/systemd/logind.conf
# 修改
HandleLidSwitch=lock
LidSwitchIgnoreInhibited=yes

注意: 我这边只需要合上笔记本盖后不休眠,请根据自己情况选择参数。 改完 cat 查看一下,确保无误。

root@good-home:~# cat /etc/systemd/logind.conf 
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it under the
#  terms of the GNU Lesser General Public License as published by the Free
#  Software Foundation; either version 2.1 of the License, or (at your option)
#  any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the logind.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
#
# Use 'systemd-**yze cat-config systemd/logind.conf' to display the full config.
#
# See logind.conf(5) for details.

[Login]
#NAutoVTs=6
#ReserveVT=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#InhibitDelayMaxSec=5
#UserStopDelaySec=10
#HandlePowerKey=poweroff
#HandlePowerKeyLongPress=ignore
#HandleRebootKey=reboot
#HandleRebootKeyLongPress=poweroff
#HandleSuspendKey=suspend
#HandleSuspendKeyLongPress=hibernate
#HandleHibernateKey=hibernate
#HandleHibernateKeyLongPress=ignore
HandleLidSwitch=lock
#HandleLidSwitchExternalPower=suspend
#HandleLidSwitchDocked=ignore
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
LidSwitchIgnoreInhibited=yes
#RebootKeyIgnoreInhibited=no
#HoldoffTimeoutSec=30s
#IdleAction=ignore
#IdleActionSec=30min
#RuntimeDirectorySize=10%
#RuntimeDirectoryInodesMax=
#RemoveIPC=yes
#InhibitorsMax=8192
#SessionsMax=8192
#StopIdleSessionSec=infinity

重启服务, 使设置生效

systemctl restart systemd-logind
收藏
送赞 7
分享

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

3

主题

22

回帖

0

牛值

江湖小虾

2024-11-28 09:07:54 显示全部楼层
我直接拆了笔记本屏幕,简单快捷,反正飞牛用不上屏幕
我也拆了,散热还好,方便重启  详情 回复
2025-1-14 10:44
歪日,猛  详情 回复
2024-11-28 18:21

8

主题

16

回帖

0

牛值

江湖小虾

2024-11-28 18:21:31 楼主 显示全部楼层
歪日,猛

0

主题

1

回帖

0

牛值

江湖小虾

2025-1-14 10:44:22 显示全部楼层
我也拆了,散热还好,方便重启

3

主题

10

回帖

0

牛值

江湖小虾

2025-2-8 17:52:19 显示全部楼层
为啥我的没效果,重启了也不行,改成和你一样或者ignore都不行...
前面 # 删掉  详情 回复
2025-2-14 23:28

6

主题

11

回帖

0

牛值

江湖小虾

2025-2-14 23:28:14 显示全部楼层
前面 # 删掉

6

主题

10

回帖

0

牛值

江湖小虾

2025-3-1 19:32:27 显示全部楼层
本帖最后由 z14211 于 2025-3-1 20:26 编辑

vim /etc/systemd/logind.conf 之后怎么退出那个编辑界面     看别的帖子弄好了   懂了 还要加一个!
应该是先按ESC键,再输入":wq"回车(不要引号)  详情 回复
2025-4-18 13:52

5

主题

48

回帖

0

牛值

初出茅庐

2025-4-18 13:52:03 显示全部楼层
z14211 发表于 2025-3-1 19:32
vim /etc/systemd/logind.conf 之后怎么退出那个编辑界面     看别的帖子弄好了   懂了 还要加一个! ...
先按ESC键,再输入":wq!"回车(不要引号)

0

主题

1

回帖

0

牛值

江湖小虾

2025-4-29 06:48:29 显示全部楼层

LidSwitchIgnoreInhibited=yes 应该是不需要的

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则