睡眠、休眠与恢复

Linux 系统的休眠(Hibernation)与恢复(Resume)可能需要额外的设置才能生效。此外,笔记本上的 Linux 系统从睡眠(Suspend)中恢复后,可能出现键盘(以及触摸板)无法使用的情况。

参考:

睡眠与休眠
Suspend to RAM (aka suspend, aka sleep)
The S3 sleeping state as defined by ACPI. Works by cutting off power to most parts of the machine aside from the RAM, which is required to restore the machine’s state. Because of the large power savings, it is advisable for laptops to automatically enter this mode when the computer is running on batteries and the lid is closed (or the user is inactive for some time).
Suspend to disk (aka hibernate)
The S4 sleeping state as defined by ACPI. Saves the machine’s state into swap space and completely powers off the machine. When the machine is powered on, the state is restored. Until then, there is zero power consumption.
Suspend to both
A hybrid of the aforementioned methods, sometimes called hybrid suspend. Saves the machine’s state into swap space, but does not power off the machine. Instead, it invokes usual suspend to RAM. Therefore, if the battery is not depleted, the system can resume from RAM. If the battery is depleted, the system can be resumed from disk, which is much slower than resuming from RAM, but the machine’s state has not been lost.

配置休眠与恢复

Since systemd v255 and mkinitcpio v38, when the system is running on UEFI, systemd-sleep(8) will automatically pick a suitable swap space to hibernate into, and the information of the used swap space is stored in HibernateLocation EFI variable. Upon next boot, systemd-hibernate-resume(8) reads the location off the EFI variable and the system resumes. This means the following steps are not necessary unless the system is using legacy BIOS or you want to choose a different swap space from the automatically-selected one. 从 systemd v255 和 mkinitcpio v38 开始,当系统在 UEFI 上运行时,systemd-sleep(8) 会自动选择合适的交换空间进入休眠状态,并且已使用的交换空间信息存储在 HibernateLocation EFI 变量中。下次启动时,systemd-hibernate-resume(8) 从 EFI 变量中读取位置,然后系统恢复。这意味着以下步骤不是必需的,除非系统使用的是传统 BIOS,或者您想从自动选择的交换空间中选择不同的交换空间。

1
HOOKS=(base udev systemd autodetect microcode modconf keyboard keymap block filesystems)

配置 initramfs

编辑 /etc/mkinitcpio.conf 文件,添加 resume 钩子(确保在 udev 后面):

1
HOOKS=(base udev autodetect keyboard modconf block filesystems resume fsck)

执行以下命令重新生成 initramfs

1
sudo mkinitcpio -P

添加内核参数

GRUB_CMDLINE_LINUX 中添加 resume 参数,通过 UUID 指定恢复所使用的交换设备,如:

1
2
GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 nvidia-drm.modeset=1"
GRUB_CMDLINE_LINUX="noquiet resume=UUID=8759088c-fdb3-4719-952d-a00cd91fa61b"

交换分区的 UUID 可以通过 lsblk -f 查看。

执行以下命令更新 grub.cfg 文件:

1
sudo grub-mkconfig -o /boot/grub/grub.cfg

其他问题

如果 swap 分区/文件不够大,或者想提升恢复速度,可以参考 About swap partition/file size

如果没有剩余的空间可作为 swap 分区,可考虑 swap 文件

休眠与键盘(及触摸板)

其他可能的解决方法

GRUB_CMDLINE_LINUX 添加一个或多个以下内核参数可能会有所帮助(添加方法同):

1
i8042.noloop i8042.nomux i8042.nopnp i8042.reset

关于 i8042.nomuxi8042.reset 的说明,可参考 StackExchange 上的这个问题。完整内核参数及说明参考回答中提到的这篇文档

锁屏或从睡眠中恢复后显示空白的黑色界面

鼠标可用,可选中中间不可见的密码框并输入密码解锁。

Enter any child page of Series.