Files
nexus/raw/Home Office/Ubuntu禁用合盖休眠.md

79 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title:
source:
author: shenwei
published:
created:
description:
tags: [ubuntu]
---
#ubuntu
```table-of-contents
```
在 Ubuntu 24.04 中,笔记本合盖休眠的行为是由系统的登录管理器 `systemd-logind` 控制的。要让服务器在合盖后继续运行,你需要修改系统的配置文件。
以下是具体操作步骤:
### 1. 修改 `logind.conf` 配置文件
打开终端(或通过 SSH 连接),使用 `nano` 文本编辑器修改系统配置:
Bash
```
sudo nano /etc/systemd/logind.conf
```
### 2. 编辑配置项
在打开的文件中,找到以下几行代码(通常是被注释掉的,即行首有 `#`
- `HandleLidSwitch`:合盖时的动作(通常指用电池时)。
- `HandleLidSwitchExternalPower`:连接外接电源合盖时的动作。
- `HandleLidSwitchDocked`:连接扩展坞合盖时的动作。
将它们修改为 `ignore` 并**删除行首的 `#`**,修改后的内容应如下所示:
Plaintext
```
[Login]
HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore
```
- **ignore**:表示不执行任何操作,即系统继续运行。
### 3. 重启服务使配置生效
保存并退出(在 nano 中按 `Ctrl + O`,回车,然后按 `Ctrl + X`)。执行以下命令重启服务:
Bash
```
sudo systemctl restart systemd-logind
```
> **注意:** 在执行此命令时,你的当前会话(包括图形界面或当前的 SSH 连接)可能会短暂断开或重新加载。
---
### 进阶:彻底禁用系统的休眠功能(可选)
如果你希望从内核级别彻底禁止休眠(防止任何情况下的自动待机),可以运行以下命令:
Bash
```
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
```
_如果以后想恢复将 `mask` 改为 `unmask` 即可。_