Linux 休眠
2016-03-30 10:17
513 查看
http://hi.baidu.com/red_woods/blog/item/721676123f5ced56f819b8d5.html
Linux休眠(STD)有shutdown和platform两种方式,platform需要BIOS支持,shutdown不需要。可以休眠到分区或文件,一般用swap来做。
一、休眠到swap分区
1. 准备swap分区,比如 /dev/sda5,将其激活,并加入到/etc/fstab
2. 编辑 /etc/uswsusp.conf
# /etc/uswsusp.conf(8) -- Configuration file for s2disk/s2both
resume device = /dev/sda5
#compress = y
early writeout = y
#image size = 335111045
#RSA key file = /etc/uswsusp.key
#shutdown method = platform
shutdown method = shutdown
3. 编辑 /etc/initramfs-tools/conf.d/resume
RESUME=/dev/sda5
4. 重新生成 /boot/initrd.img
改变以上两个配置文件后,要重新生成 /boot/initrd.img,特别是改变‘resume device’参数后。否则恢复时initrd找不到休眠镜像,并出现“Unable to find swap-space signature”的错误。
二、休眠到swap文件
1. 准备swap文件,比如 /swapfile(不要超过2G),将其激活,并加入到/etc/fstab
2. swap-offset /swapfile
resume offset = 22528 (文件swapfile在文件系统中的偏移量为22528)
3. 编辑 /etc/uswsusp.conf
# /etc/uswsusp.conf(8) -- Configuration file for s2disk/s2both
resume device = /dev/sda2
resume offset = 22528
#compress = y
early writeout = y
#image size = 335111045
#RSA key file = /etc/uswsusp.key
#shutdown method = platform
shutdown method = shutdown
4. 编辑 /etc/initramfs-tools/conf.d/resume
RESUME=/dev/sda2
5. 重新生成 /boot/initrd.img
改变以上两个配置文件后,要重新生成 /boot/initrd.img,特别是改变‘resume device’和‘resume offset’参数后。否则恢复时initrd找不到休眠镜像,并出现“Unable to find swap-space signature”的错误。
PS:与上面两种方法不同,如果系统启动时没有initrd.img,则要把休眠恢复的参数加在grub配置文件的内核参数之后,如加上:
resume=/dev/sda5 (休眠到分区)
OR
resume=/dev/sda2 resume_offset=22528 (休眠到文件)
这时重新生成 /boot/initrd.img的步骤自然也不用了。
三、执行休眠
1. 普通用户要加入/etc/group的'powerdev'组才有执行休眠的权限。
2. 执行休眠的几种方法:
a. echo shutdown > /sys/power/disk; echo disk > /sys/power/state
b. sudo pm-hibernate
c. sudo hibernate-disk
d. 从关机菜单上点“休眠”
P.S.:这篇文章主要是针对搬过“家”,或修改过swap位置的系统来说的,如果是直接安装的系统,休眠功能不需这样的配置,只是启不启用的事情。
Linux休眠(STD)有shutdown和platform两种方式,platform需要BIOS支持,shutdown不需要。可以休眠到分区或文件,一般用swap来做。
一、休眠到swap分区
1. 准备swap分区,比如 /dev/sda5,将其激活,并加入到/etc/fstab
2. 编辑 /etc/uswsusp.conf
# /etc/uswsusp.conf(8) -- Configuration file for s2disk/s2both
resume device = /dev/sda5
#compress = y
early writeout = y
#image size = 335111045
#RSA key file = /etc/uswsusp.key
#shutdown method = platform
shutdown method = shutdown
3. 编辑 /etc/initramfs-tools/conf.d/resume
RESUME=/dev/sda5
4. 重新生成 /boot/initrd.img
改变以上两个配置文件后,要重新生成 /boot/initrd.img,特别是改变‘resume device’参数后。否则恢复时initrd找不到休眠镜像,并出现“Unable to find swap-space signature”的错误。
二、休眠到swap文件
1. 准备swap文件,比如 /swapfile(不要超过2G),将其激活,并加入到/etc/fstab
2. swap-offset /swapfile
resume offset = 22528 (文件swapfile在文件系统中的偏移量为22528)
3. 编辑 /etc/uswsusp.conf
# /etc/uswsusp.conf(8) -- Configuration file for s2disk/s2both
resume device = /dev/sda2
resume offset = 22528
#compress = y
early writeout = y
#image size = 335111045
#RSA key file = /etc/uswsusp.key
#shutdown method = platform
shutdown method = shutdown
4. 编辑 /etc/initramfs-tools/conf.d/resume
RESUME=/dev/sda2
5. 重新生成 /boot/initrd.img
改变以上两个配置文件后,要重新生成 /boot/initrd.img,特别是改变‘resume device’和‘resume offset’参数后。否则恢复时initrd找不到休眠镜像,并出现“Unable to find swap-space signature”的错误。
PS:与上面两种方法不同,如果系统启动时没有initrd.img,则要把休眠恢复的参数加在grub配置文件的内核参数之后,如加上:
resume=/dev/sda5 (休眠到分区)
OR
resume=/dev/sda2 resume_offset=22528 (休眠到文件)
这时重新生成 /boot/initrd.img的步骤自然也不用了。
三、执行休眠
1. 普通用户要加入/etc/group的'powerdev'组才有执行休眠的权限。
2. 执行休眠的几种方法:
a. echo shutdown > /sys/power/disk; echo disk > /sys/power/state
b. sudo pm-hibernate
c. sudo hibernate-disk
d. 从关机菜单上点“休眠”
P.S.:这篇文章主要是针对搬过“家”,或修改过swap位置的系统来说的,如果是直接安装的系统,休眠功能不需这样的配置,只是启不启用的事情。
相关文章推荐
- 《Linux运维之道》的截图 2-网路简单排错
- linux下 生成 resin-admin的 md5加密的密码
- 35款基于terminal的Linux应用
- Linux kernel中断子系统之(五):驱动申请中断API
- 教你在Linux用飞信(fetion)免费发短信
- Linux命令学习笔记(3)——理解SUID,SGID,stick
- 初学者学习LINUX之困惑?方向迷失?GUI?
- linux kernel的中断子系统之(四):High level irq event handler
- centos 7 删除 virbr0 虚拟网卡
- Linux下刻录光盘—cdrecord
- centos 7 删除 virbr0 虚拟网卡
- Linux 6初体验:桌面性能堪比新版Ubuntu
- Writing Linux LCD drivers—深入分析framebuffer设备驱动的结构
- linux kernel的中断子系统之(三):IRQ number和中断描述符
- Linux kernel的中断子系统之(二):IRQ Domain介绍
- install torch7 on centos6.5
- Linux kernel的中断子系统之(一):综述
- CentOS5.5 FTP安装配置
- 服务器领域Linux击败Windows的5大理由
- 好玩的Linux命令