ArchLinux 添加 hibernate 休眠模式

hibernate 休眠

休眠(hibernate)是指把挂起后的内存写入磁盘并完全关机。

步骤

1 创建交换文件

查看休眠需要的空间大小

cat /sys/power/image_size

创建文件

# dd if=/dev/zero of=/swapfile bs=1M count=4096 status=progress

修改文件权限

# chmod 0600 /swapfile

格式化交换文件

# mkswap -U clear /swapfile

激活交换文件

# swapon /swapfile

/etc/fstab文件中添加对应的条目

/etc/fstab
===============================
/swapfile none swap defaults 0 0

2 配置initramfs

查看/etc/mkinitcpio.conf文件,将resume添加在udev后(默认在后面可以不用修改)
HOOKS=(base udev autodetect keyboard modconf block filesystems resume fsck)

3 添加内核参数

命令查看resume uuid

findmnt -no UUID -T /swapfile

命令查看resume offset参数。

# filefrag -v /swapfile | awk '{ if($1=="0:"){print $4} }'

修改/sys/power/resume_offset文件

###  38912  ->  resume_offset
echo 38912 > /sys/power/resume_offset

修改/etc/default/grub文件,并重新生成启动选项(不同bootloader配置不同,参考Kernel parameters

/etc/default/grub
==========================================
### 添加
GRUB_CMDLINE_LINUX="resume=UUID=87fe434b-ecf9-4417-a5b2-3aea84f8259f resume_offset=38912"


--------------------------------------------------------
### 重新生成grub.cfg文件
# grub-mkconfig -o /boot/grub/grub.cfg

参考

https://wiki.archlinux.org/title/Kernel_parameters
https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Hibernation
https://wiki.archlinux.org/title/Swap#Swap_file
https://harttle.land/2019/10/19/hibernate-archlinux.html
https://docs.kernel.org/power/swsusp-and-swap-files.html

posted @ 2023-01-13 18:59  3yude  阅读(138)  评论(0)    收藏  举报