Auto-sync: 2026-04-22 08:02

This commit is contained in:
2026-04-22 08:02:59 +08:00
parent de096f2f88
commit 143d1fd105
62 changed files with 5232 additions and 1268 deletions

View File

@@ -0,0 +1,75 @@
---
title: "Ubuntu禁用合盖休眠"
type: source
tags: [ubuntu, systemd, 服务器配置]
date: 2026-04-14
---
## Source File
- [[raw/Home Office/Ubuntu禁用合盖休眠.md]]
## Summary (用中文描述)
- 核心主题Ubuntu Server 合盖不休眠的完整操作指南
- 问题域Ubuntu 笔记本作为服务器运行时,合盖触发系统休眠/待机导致服务中断的问题
- 方法/机制:通过修改 systemd-logind 的 logind.conf 配置文件,设置 HandleLidSwitch 系列参数为 ignore并重启服务生效进阶方案是通过 systemctl mask 彻底禁用内核级休眠目标
- 结论/价值:让 Ubuntu 笔记本在无外接显示器的情况下作为稳定服务器运行
## Key Claims (用中文描述)
- systemd-logind 是 Ubuntu 24.04 控制笔记本合盖行为的系统服务
- 修改 /etc/systemd/logind.conf 中的 HandleLidSwitch* 系列配置项并重启服务即可生效
- HandleLidSwitch=ignore 使系统合盖后继续运行
- systemctl mask 可从内核级别彻底禁用 sleep/suspend/hibernate/hybrid-sleep 四个休眠目标
## Key Quotes
> "HandleLidSwitch合盖时的动作通常指用电池时" — Ubuntu logind.conf 配置项说明
> "HandleLidSwitchExternalPower连接外接电源合盖时的动作" — Ubuntu logind.conf 配置项说明
> "HandleLidSwitchDocked连接扩展坞合盖时的动作" — Ubuntu logind.conf 配置项说明
> "在执行此命令时,你的当前会话(包括图形界面或当前的 SSH 连接)可能会短暂断开或重新加载。" — 重启 systemd-logind 的注意事项
## Key Concepts
- [[systemd-logind]]Linux 系统登录管理器,负责管理用户会话、电源事件和系统休眠行为
- [[HandleLidSwitch]]systemd-logind 的合盖动作配置项,支持 ignore/suspend/hibernate/poweroff/lock 等值
- [[休眠目标]]Linux 内核的电源管理目标,包括 sleep.target / suspend.target / hibernate.target / hybrid-sleep.target
## Key Entities
- [[Ubuntu Server]]Canonical 维护的 Linux 服务器操作系统,默认使用 systemd 作为初始化系统
- [[systemd]]Linux 系统和服务管理器,通过 logind 管理笔记本电源事件
## Connections
- [[Ubuntu Server]] ← 使用 ← [[systemd-logind]](电源管理机制)
- [[systemd-logind]] ← 配置项 ← [[HandleLidSwitch]](合盖行为控制)
- [[休眠目标]] ← 进阶禁用 ← systemd通过 systemctl mask
## Contradictions
- 无已知冲突页面
## Related Sources
- [[mac-mini服务器配置-防止自动锁屏与睡眠]] — macOS 等效配置(防止 Mac Mini 服务器自动睡眠)
- [[ubuntu服务器通过rsync实现日常增量备份]] — Ubuntu 服务器备份方案
- [[安装ubuntu-24-04-2在hp-zbook工作站笔记本上]] — HP ZBook Ubuntu 安装记录
## Operations (操作步骤)
### 基础方案:修改 logind.conf
```bash
# 1. 编辑配置文件
sudo nano /etc/systemd/logind.conf
# 2. 修改/添加以下配置(删除行首 #
[Login]
HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore
# 3. 重启服务使配置生效
sudo systemctl restart systemd-logind
```
### 进阶方案:禁用内核级休眠功能
```bash
# 彻底禁用所有休眠目标
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
# 恢复(如需)
sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target
```