linux电源管理

·

查看suspend休眠配置模式

cat /sys/power/mem_sleep
echo deep | sudo tee /sys/power/mem_sleep

配置hibernate休眠

cat /etc/fstab
swapon --show
sudo swapoff -a
sudo dd if=/dev/zero of=/swapfile bs=1G count=17
sudo swapon /swapfile

# 获取swap文件的offset
sudo filefrag -v /swapfile | awk '{if($1=="0:") print $4}'
# 查看根分区 UUID
findmnt -no UUID -T /

sudo vim /etc/default/grub
# GRUB_CMDLINE_LINUX_DEFAULT="quiet splash mem_sleep_default=deep resume=UUID=<磁盘分区UUID> resume_offset=<swap文件偏移量>"
sudo update-grub

配置电源管理

cat <<EOF > /etc/systemd/sleep.conf.d/enable-sleep.conf
AllowSuspend=yes
AllowHibernation=yes
HibernateMode=platform shutdown
HibernateState=disk
AllowSuspendThenHibernate=yes
AllowHybridSleep=yes
SuspendState=mem standby freeze
EOF

sudo mkdir /etc/systemd/logind.conf.d
cat <<EOF | sudo tee /etc/systemd/logind.conf.d/override.conf
[Login]
HandlePowerKey=suspend-then-hibernate
HandleRebootKey=reboot
HandleRebootKeyLongPress=poweroff
HandleSuspendKey=suspend
HandleSuspendKeyLongPress=hibernate
IdleAction=suspend-then-hibernate
IdleActionSec=30min
EOF

systemd-analyze cat-config systemd/sleep.conf
systemd-analyze cat-config systemd/logind.conf