1.配置文件

/etc/systemd/logind.conf

1.1 配置文件解析

输入命令

sudo nano /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. # You can change settings by editing this file. # Defaults can be restored by simply deleting this file. # # See logind.conf(5) for details.

[Login] #NAutoVTs=6 #ReserveVT=6 #KillUserProcesses=no #KillOnlyUsers= #KillExcludeUsers=root #InhibitDelayMaxSec=5 #HandlePowerKey=poweroff #HandleSuspendKey=suspend #HandleHibernateKey=hibernate #HandleLidSwitch=suspend #HandleLidSwitchExternalPower=suspend #HandleLidSwitchDocked=ignore #PowerKeyIgnoreInhibited=no #SuspendKeyIgnoreInhibited=no #HibernateKeyIgnoreInhibited=no #LidSwitchIgnoreInhibited=yes #HoldoffTimeoutSec=30s #IdleAction=ignore #IdleActionSec=30min #RuntimeDirectorySize=10% #RemoveIPC=yes #InhibitorsMax=8192 #SessionsMax=8192

# xiaowang HandleLidSwitch=ignore HandleLidSwitchExternalPower=ignore HandleLidSwitchDocked=ignore

文件解释

文件信息:

这个文件是 systemd 的一部分,用于配置系统的登录管理服务(logind)。 文件中的内容显示了编译时的默认设置,你可以通过编辑这个文件来更改这些设置。 如果你想恢复默认设置,只需删除这个文件。

[Login] 部分:

这部分包含了与登录和系统行为相关的设置。

具体选项解释:

NAutoVTs=6: 系统自动分配的虚拟终端数量,默认为 6。 ReserveVT=6: 保留的虚拟终端编号,默认为 6。 KillUserProcesses=no: 是否在用户注销时杀死其进程,默认为不杀死。 KillOnlyUsers= 和 KillExcludeUsers=root: 指定在注销时要杀死或排除杀死哪些用户的进程。 InhibitDelayMaxSec=5: 禁止操作的最大延迟时间(秒)。 HandlePowerKey=poweroff: 当按下电源键时执行的操作,默认为关机。 HandleSuspendKey=suspend: 当按下挂起键时执行的操作,默认为挂起。 HandleHibernateKey=hibernate: 当按下休眠键时执行的操作,默认为休眠。 HandleLidSwitch=suspend: 当合上笔记本电脑盖子时执行的操作,默认为挂起。 HandleLidSwitchExternalPower=suspend: 当笔记本电脑连接到外部电源且合上盖子时执行的操作,默认为挂起。 HandleLidSwitchDocked=ignore: 当笔记本电脑连接到坞站且合上盖子时执行的操作,默认为忽略。 PowerKeyIgnoreInhibited=no, SuspendKeyIgnoreInhibited=no, HibernateKeyIgnoreInhibited=no, LidSwitchIgnoreInhibited=yes: 控制是否忽略对相应操作的禁止。 HoldoffTimeoutSec=30s: 在系统空闲后等待一段时间才执行闲置操作的时间(秒)。 IdleAction=ignore: 当系统空闲时执行的操作,默认为忽略。 IdleActionSec=30min: 系统空闲多久后执行闲置操作的时间(分钟)。 RuntimeDirectorySize=10%: 运行时目录的最大大小(以磁盘总空间的百分比表示)。 RemoveIPC=yes: 是否在会话结束时删除 IPC 对象。 InhibitorsMax=8192: 最大允许的禁止器数量。 SessionsMax=8192: 最大允许的会话数量。  

 修改

在保持原文件内容不变的情况下,在下方添加需要的内容

HandleLidSwitch=ignore

HandleLidSwitchExternalPower=ignore

HandleLidSwitchDocked=ignore

 1.2 操作步骤

第一步:打开终端

打开终端

第二步:打开文件

打开文件。

输入命令,且获取管理员权限

sudo nano /etc/systemd/logind.conf

第三步:找到相关选项

找到相关选项

在打开的文件中,使用上下箭头键滚动找到与盖子关闭行为相关的选项:

HandleLidSwitch

HandleLidSwitchExternalPower

HandleLidSwitchDocked

这些选项可能已经被注释掉了(以 # 开头),或者已经有了默认值。

第四步:修改选项值

修改选项值。

两种方式:

①要取消注释一个选项,将光标移动到该行的行首,然后按退格键删除 # 符号。接着,将这些选项的值改为 ignore。你可以使用左右箭头键移动光标,然后使用删除键或插入键进行修改。

②因为,文件中的选项都有默认值,且都被注释掉了。为了记住文件的默认值,可以在文件最后添加修改后的选项即可。

[Login]

# ...

HandleLidSwitch=ignore

HandleLidSwitchExternalPower=ignore

HandleLidSwitchDocked=ignore

第五步:保存并关闭文件

保存并关闭文件

按 Ctrl + O 键(字母 "O",不是数字 "0"),然后按回车键确认保存更改。

按 Ctrl + X 键关闭 Nano 编辑器。

第六步:重启相关服务

 为了让更改生效,需要重启 systemd-logind 服务:

systemctl restart systemd-logind

现在,系统应该不会在合上盖子时自动挂起或休眠了。但是,请注意,这可能会对电池寿命和电源管理产生影响,因此在不需要长时间运行关键程序的情况下,建议保持默认的系统挂起行为。

相关文章

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: 


大家都在找:

linux:linux常用命令

ubuntu:ubuntu怎么读

大家都在看: