2022-07-24 systemd 休眠机器与苏醒机器

通过 systemd 实现机器的休眠与苏醒, 在这个过程中遇到很多问题, 主要是因为自己阅读文档不仔细导致的, 现在我将自己的设置路径大概记录一下。

  1. 查找用于电源管理的软件, 这些软件可能会导致恢复休眠不能稳定的工作, 我的是 tlp
1
sudo pacman -Rsn tlp
  1. 查看自己的 swap 分区的 uuid, 我用 fdisk 查找的 uuid 不对, 最后采用 gparted 分区工具可以查到相应的 uuid, 比如我的 uuid 为 7902e84c-cb6d-4362-b04b-ccb6c5dc8a99 ,根据自己的 uuid 修改 grub 的默认参数。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# file: /etc/default/grub
# Written by com.deepin.daemon.Grub2
GRUB_BACKGROUND="/boot/grub/themes/deepin/background.jpg"
GRUB_CMDLINE_LINUX="resume=UUID=7902e84c-cb6d-4362-b04b-ccb6c5dc8a99"
GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 quiet"
GRUB_DEFAULT=0
GRUB_DISABLE_RECOVERY=true
GRUB_DISTRIBUTOR="Arch"
GRUB_GFXMODE=auto
GRUB_GFXPAYLOAD_LINUX=keep
GRUB_PRELOAD_MODULES="part_gpt part_msdos"
GRUB_TERMINAL_INPUT=console
GRUB_THEME="/boot/grub/themes/deepin/theme.txt"
GRUB_TIMEOUT=5
GRUB_TIMEOUT_STYLE=menu

然后生成 grub.cfg 。

1
sudo grub-mkconfig -o /boot/grub/grub.cfg
  1. 修改 boot-image. 找到 /etc/mkinitcpio.conf 后修改相应的参数,其中修改 modules 和 hooks 设置, 下列是我的设置,其中 moudles, 要不会存在 capslock 按键不停的闪烁, 内核模块内存溢出。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# file: /etc/mkinitcpio.conf

# vim:set ft=sh
# MODULES
# The following modules are loaded before any boot hooks are
# run. Advanced users may wish to specify all system modules
# in this array. For instance:
# MODULES=(piix ide_disk reiserfs)
MODULES=( intel_lpss_pci )

# BINARIES
# This setting includes any additional binaries a given user may
# wish into the CPIO image. This is run last, so it may be used to
# override the actual binaries included by a given hook
# BINARIES are dependency parsed, so you may safely ignore libraries
BINARIES=()

# FILES
# This setting is similar to BINARIES above, however, files are added
# as-is and are not parsed in any way. This is useful for config files.
FILES=()

# HOOKS
# This is the most important setting in this file. The HOOKS control the
# modules and scripts added to the image, and what happens at boot time.
# Order is important, and it is recommended that you do not change the
# order in which HOOKS are added. Run 'mkinitcpio -H <hook name>' for
# help on a given hook.
# 'base' is _required_ unless you know precisely what you are doing.
# 'udev' is _required_ in order to automatically load modules
# 'filesystems' is _required_ unless you specify your fs modules in MODULES
# Examples:
## This setup specifies all modules in the MODULES setting above.
## No raid, lvm2, or encrypted root is needed.
# HOOKS=(base)
#
## This setup will autodetect all modules for your system and should
## work as a sane default
# HOOKS=(base udev autodetect block filesystems)
#
## This setup will generate a 'full' image which supports most systems.
## No autodetection is done.
# HOOKS=(base udev block filesystems)
#
## This setup assembles a pata mdadm array with an encrypted root FS.
## Note: See 'mkinitcpio -H mdadm' for more information on raid devices.
# HOOKS=(base udev block mdadm encrypt filesystems)
#
## This setup loads an lvm2 volume group on a usb device.
# HOOKS=(base udev block lvm2 filesystems)
#
## NOTE: If you have /usr on a separate partition, you MUST include the
# usr, fsck and shutdown hooks.
HOOKS=(base udev systemd autodetect modconf block filesystems keyboard fsck)

# COMPRESSION
# Use this to compress the initramfs image. By default, zstd compression
# is used. Use 'cat' to create an uncompressed image.
#COMPRESSION="zstd"
#COMPRESSION="gzip"
#COMPRESSION="bzip2"
#COMPRESSION="lzma"
#COMPRESSION="xz"
#COMPRESSION="lzop"
#COMPRESSION="lz4"

# COMPRESSION_OPTIONS
# Additional options for the compressor
#COMPRESSION_OPTIONS=()
1
2
sudo mkinitcpio -P
sudo grub-mkconfig -o /boot/grub/grub.cfg

现在就可以实现休眠与苏醒了。 如果需要通过笔记本。

  1. 配置 systemd-logind ,本人配置如下.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#  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. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the logind.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
#
# Use 'systemd-analyze cat-config systemd/logind.conf' to display the full config.
#
# See logind.conf(5) for details.

[Login]
#NAutoVTs=6
#ReserveVT=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#InhibitDelayMaxSec=5
#UserStopDelaySec=10
#按下电源键
HandlePowerKey=hibernate
#HandleSuspendKey=suspend
#HandleHibernateKey=hibernate
#合上笔记本盖子
HandleLidSwitch=hybird-sleep
HandleLidSwitchExternalPower=hybird-sleep
#HandleLidSwitchDocked=ignore
#HandleRebootKey=reboot
#HandleRebootKeyLongPress=poweroff
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
#LidSwitchIgnoreInhibited=yes
#RebootKeyIgnoreInhibited=no
#HoldoffTimeoutSec=30s
#IdleAction=ignore
#IdleActionSec=30min
#RuntimeDirectorySize=10%
#RuntimeDirectoryInodesMax=400k
#RemoveIPC=yes
#InhibitorsMax=8192
#SessionsMax=8192

2022-07-24 systemd 休眠机器与苏醒机器
https://www.supermew.top/2022/07/24/systemd-休眠机器与苏醒机器/
作者
八月
发布于
2022年7月24日
许可协议