Thursday, July 23, 2009

Suspend Linux to swap

分享一個在console下將Linux系統休眠到swap的方法:

Tested on CentOS5.3:
Step1. 設定STD(suspend to disk)到swap:
[root@localhost ~]# fdisk -l
Disk /dev/hda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14         842     6658942+  83  Linux
/dev/hda3             843         907      522112+  82  Linux swap / Solaris
/dev/hda4             908        1044     1100452+   5  Extended
/dev/hda5             908         972      522081   83  Linux
[root@localhost ~]# ls -ld /dev/hda3
brw-r----- 1 root disk 3, 3 Jul 23  2009 /dev/hda3

由此得知swap partition的major與minor ID是3.3,接著修改參數如下 (預設是0:0):
[root@localhost power]# echo "3:3" > /sys/power/resume 

Step2. 啟動休眠:
[root@localhost ~]# echo "disk" > /sys/power/state 

此時系統將立刻進入休眠狀態,並於下次重開機時回到剛剛的環境。

Step3. 設定永久suspend到swap:
修改/boot/grub/grub.conf並設定Kernel參數如下:
kernel /vmlinuz-2.6.18-128.2.1.el5 ro root=LABEL=/ rhgb quiet resume=/dev/hda3

No comments: