笔记本休眠与唤醒
基本概念
| 模式 | 英文 | 说明 |
|---|---|---|
| 挂起 | Suspend (S3) | 内容保存在内存,低功耗状态,恢复快 |
| 休眠 | Hibernate (S4) | 内容写入硬盘 swap 分区,完全断电,恢复较慢 |
| 混合睡眠 | Hybrid Sleep | 同时写入内存和硬盘,兼顾速度与安全 |
测试挂起
# 挂起到内存
sudo systemctl suspend
# 查看支持的睡眠模式
cat /sys/power/state配置休眠(Hibernate)
前提条件
休眠需要 swap 空间不小于物理内存大小。
# 查看内存和 swap
free -h
# 查看 swap 分区/文件
swapon --show使用 swap 文件休眠
如果使用 swap 文件而非 swap 分区:
# 创建与内存等大的 swap 文件(示例:16GB)
sudo fallocate -l 16G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
# 写入 /etc/fstab 持久化
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab配置内核参数
找到 swap 文件的物理偏移量:
sudo filefrag -v /swapfile | head -4记录第一行的 physical_offset 值。然后找到 swap 所在分区的 UUID:
findmnt -no UUID -T /swapfile编辑 GRUB 配置:
sudo nano /etc/default/grub修改 GRUB_CMDLINE_LINUX_DEFAULT:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=你的UUID resume_offset=偏移量"更新 GRUB 并 initramfs:
sudo update-grub
# 26.04 默认使用 Dracut 生成 initramfs:
sudo dracut -f --regenerate-all
# 旧的 initramfs-tools 环境改用:sudo update-initramfs -u -k all测试休眠
sudo systemctl hibernate混合睡眠
sudo systemctl hybrid-sleep合盖与电源按钮行为
编辑 /etc/systemd/logind.conf:
[Login]
HandleLidSwitch=suspend
HandleLidSwitchExternalPower=ignore
HandlePowerKey=poweroff
HandleSuspendKey=suspend可选值:ignore、poweroff、reboot、halt、suspend、hibernate、hybrid-sleep、lock
修改后重启服务:
sudo systemctl restart systemd-logind常见问题
挂起后无法唤醒
- 检查内核日志:
journalctl -b -1 | grep -i "suspend\|resume\|sleep"- 尝试在 GRUB 中添加内核参数:
acpi_osi=Linux acpi_backlight=vendor- 对于 NVIDIA 显卡用户,确保驱动版本较新并启用了电源管理:
sudo systemctl enable nvidia-suspend nvidia-resume nvidia-hibernate休眠后无法恢复
确认 resume 参数正确配置,并检查 initramfs 是否包含 resume 模块:
# 26.04 默认使用 Dracut,列出 initramfs 内容用 lsinitrd:
sudo lsinitrd /boot/initrd.img-$(uname -r) | grep resume
# 旧的 initramfs-tools 环境改用:lsinitramfs /boot/initrd.img-$(uname -r) | grep resume唤醒后 Wi-Fi 不可用
sudo systemctl restart NetworkManager
# 或重新加载无线模块
sudo modprobe -r iwlwifi && sudo modprobe iwlwifi唤醒后蓝牙不可用
sudo systemctl restart bluetooth
sudo rfkill unblock bluetooth电源管理优化
安装 TLP 进行笔记本电源优化:
sudo apt install tlp tlp-rdw
sudo systemctl enable tlp
sudo tlp start查看电池状态:
tlp-stat -bLast updated on