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