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是忽略該動作,即不進行任何電源事件響應