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 @   3yude  阅读(109)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示