https://wiki.archlinux.org/index.php/Power_management/Suspend_and_hibernate_(简体中文)
https://wiki.archlinux.org/index.php/Power_management/Suspend_and_hibernate
https://wiki.archlinux.org/index.php/Power_management
https://wiki.archlinux.org/index.php/HP_Compaq_6510b

三种挂起方式
名称 挂起方式 电源状态

  • 1. suspend 挂起,待机,暂停 (str: suspend to RAM)保存到内存 通电 低功耗
  • 2. hibernate 休眠,冬眠 (std: suspend to disk)保存至硬盘swap 断电 关机
  • 3. HybridSleep 混合睡眠 (strd:suspend to both)保存到内存和硬盘 通电 低功耗

睡眠模式,比如笔记本电脑:若电池还有电,就等同于挂起;若电池电量耗尽,则等同于休眠模式。

========================
ArchLiux的休眠功能需要用户设置后才能使用。
这里介绍使用systemd休眠。
需要swap分区或者swap文件,大小要求大于等于系统内存。

==== 1. 在bootloader 中增加resume内核参数
需要添加resume=/dev/sdxY (sdxY 是swap分区的名字) ,让系统在启动时读取swap分区中的内容。
$ lsblk
├─sdb6 ... /
└─sdb9 ... [SWAP]
当前使用了grub2作为bootloader,swap的分区是/dev/sda9。
== 1.1 编辑/etc/default/grub文件,在GRUB_CMDLINE_LINUX_DEFAULT中添加resume=/dev/sda9
若原本是: GRUB_CMDLINE_LINUX_DEFAULT=”quiet intel_pstate=enable”
则添加后: GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_pstate=enable resume=/dev/sda9"
注:这里的 intel_pstate=enable 只针对intel处理器中SandyBridge(含IvyBridge)及更新的构架的CPU。 

当前系统:
原本是: GRUB_CMDLINE_LINUX_DEFAULT="quiet"
添加后: GRUB_CMDLINE_LINUX_DEFAULT="quiet resume=/dev/sda9"

== 1.2 更新 grub 配置:
备份 grub.cfg 这里有手动添加的启动项目,
menuentry 'windows2008r2' {
set root=(hd0,1)
chainloader +1
}

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

==== 2. 配置 initramfs的resume钩子
== 2.1 添加resume钩子 编辑 /etc/mkinitcpio.conf ,在HOOKS行中添加resume钩子:
若原本是: HOOKS="base udev autodetect modconf block filesystems keyboard fsck"
则添加后: HOOKS="base udev resume autodetect modconf block filesystems keyboard fsck"

注意: 如果使用lvm分区,需要将resume放在lvm后面
lvm分区: HOOKS="base udev autodetect modconf block lvm2 resume filesystems keyboard fsck"

当前系统:
原本是: HOOKS=(base udev autodetect modconf block filesystems keyboard fsck)
添加后: HOOKS=(base udev resume autodetect modconf block filesystems keyboard fsck)

== 2.2 重新生成 initramfs 镜像:mkinitcpio -p linux

$ sudo mkinitcpio -p linux
==> Building image from preset: /etc/mkinitcpio.d/linux.preset: 'default'
-> -k /boot/vmlinuz-linux -c /etc/mkinitcpio.conf -g /boot/initramfs-linux.img
==> Starting build: 5.0.4-arch1-1-ARCH
-> Running build hook: [base]
-> Running build hook: [udev]
-> Running build hook: [resume]
-> Running build hook: [autodetect]
-> Running build hook: [modconf]
-> Running build hook: [block]
-> Running build hook: [filesystems]
-> Running build hook: [keyboard]
-> Running build hook: [fsck]
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: /boot/initramfs-linux.img
==> Image generation successful
==> Building image from preset: /etc/mkinitcpio.d/linux.preset: 'fallback'
-> -k /boot/vmlinuz-linux -c /etc/mkinitcpio.conf -g /boot/initramfs-linux-fallback.img -S autodetect
==> Starting build: 5.0.4-arch1-1-ARCH
-> Running build hook: [base]
-> Running build hook: [udev]
-> Running build hook: [resume]
-> Running build hook: [modconf]
-> Running build hook: [block]
==> WARNING: Possibly missing firmware for module: wd719x
==> WARNING: Possibly missing firmware for module: aic94xx
-> Running build hook: [filesystems]
-> Running build hook: [keyboard]
-> Running build hook: [fsck]
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: /boot/initramfs-linux-fallback.img
==> Image generation successful
$

参照:https://wiki.archlinux.org/index.php/Mkinitcpio
==> aic94xx-firmware:适用于AIC94xx驱动程序的Adaptec SAS 44300,48300,58300定序器固件
==> wd719x-firmware:Western Digital WD7193,WD7197和WD7296 SCSI卡的驱动程序
大多数人都没有SAS / SCSI磁盘控制器,因此请忽略这些警告,不要安装这些驱动程序。
这些对任何Arch Linux用户都是有用的,特别是那些没有安装这些固件模块的用户。如果您不使用使用这些固件的硬件,则可以忽略此警告消息。

安装: https://gist.github.com/imrvelj/c65cd5ca7f5505a65e59204f5a3f7a6d
git clone https://aur.archlinux.org/aic94xx-firmware.git
cd aic94xx-firmware
makepkg -sri
git clone https://aur.archlinux.org/wd719x-firmware.git
cd wd719x-firmware
makepkg -sri
再mkinitcpio -p linux一次。

=========================
==== 设置低电量自动休眠, 用于带有内置电池的设备。
修改/etc/UPower/UPower.conf相关配置.示例,在电量低至%5时自动休眠:
PercentageLow=15          #<=15%低电量
PercentageCritical=10      #<=10%警告电量
PercentageAction=5         #<=5%执行动作(即CriticalPowerAction)的电量
CriticalPowerAction=Hibernate       #(在本示例中是电量<=5%)设备会自动休眠。
##CriticalPowerAction的取值有Poweroff、Hibernate和HybidSleep。

===================

==== 3. 设置盖上笔记本盖子或按下电源键休眠
== 3.1 编辑 /etc/systemd/logind.conf  
盖上盖子休眠,添加:HandleLidSwitch=hibernate
按下电源键休眠添加:HandlePowerKey=hibernate

== 3.2 执行以下命令使其立即生效:
$ sudo systemctl restart systemd-logind

===================

https://github.com/levinit/itnotes/blob/master/linux/laptop笔记本相关.md

#NAutoVTs=6
#ReserveVT=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#InhibitDelayMaxSec=5
#HandlePowerKey=poweroff #按下电源键
#HandleSuspendKey=suspend #按下挂起键HandleSleepKey
#HandleHibernateKey=hibernate #按下休眠键
#HandleLidSwitch=suspend #合上笔记本盖
#HandleLidSwitchExternalPower=suspend
#HandleLidSwitchDocked=ignore #插上扩展坞或者连接外部显示器情况下合上笔记本盖子
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
#LidSwitchIgnoreInhibited=yes
#HoldoffTimeoutSec=30s
#IdleAction=ignore
#IdleActionSec=30min
#RuntimeDirectorySize=10%
#RemoveIPC=yes
#InhibitorsMax=8192
#SessionsMax=8192

poweroff和halt均是关机(具体实现有区别)
supspend是挂起(暂停),设备通电,内容保存在内存中
hybernate是休眠,设备断电(同关机状态),内容保存在硬盘中
hybridSleep是混合睡眠,设备通电,内容保存在硬盘和内存中
lock是锁屏
kexec是从当前正在运行的内核直接引导到一个新内核(多用于升级了内核的情况下)
ignore是忽略该动作,即不进行任何电源事件响应