最近常常把工作帶回宿舍, 每次回到宿舍總要重新setup一次環境, 非常麻煩.
於是我想起了之前曾經用過的Linux的休眠方法,
但聽說initrd+休眠會非常的危險, 所以我拿另一台也是Linux
但只是拿來測試iperf或Chariot用的Notebook來試, 目前看來沒問題, 至少filesystem沒有跟我說要check fs,
所以寫了這篇記錄一下, 不保証會Work.
Hibernation is not that simple with just doing echo disk into /sys/power/state if you use lvm on root.
Using lvm on root requires initrd.
In accordance with the swsusp documentation, it's very dangerous to use initrd with hibernation.
The most important thing is, don't mount any filesystem that is under hibernation.
Someone may abandon doing extra work just for using lvm as root.
However, using lvm as root has many advantages.
For example, backing up the root fs without shutdowning the system using lvm snapshot capability.
Enrypting your partition using AES to protect your private data, or even create raid-device under the lvm device
for the sake of performance/stability.
This note describes how I achieved hibernation on a lvm-root.
I won't guarantee that these should work, and it might cause data loss.
But it works for me, and there is no data loss so far.
At least the kernel filesystem module won't complain at mouting.
The following script is the init script of my initrd and it resumes from /dev/hda2.
#!/bin/nash
echo "Loading dm-mod.ko module"
insmod /lib/dm-mod.ko
echo Mounting /proc filesystem
mount -t proc /proc /proc
mount -t sysfs /sys /sys
echo Creating block devices
mkdevices /dev
echo Creating root device
echo 0xFE00 > /proc/sys/kernel/real-root-dev
mkrootdev /dev/root
lvm vgscan --ignorelockingfailure
lvm vgchange -ay --ignorelockingfailure
lvm lvscan --ignorelockingfailure
lvm lvchange -ay --ignorelockingfailure /dev/backup_vg/backup_lv
echo 3:2 > /sys/power/resume
echo Mounting root filesystem
mount -o noatime --ro -t ext3 /dev/root /sysroot
pivot_root /sysroot /sysroot/initrd
umount /initrd/proc
# Please refert to initrd.txt in kernel documentation.
# This is the different instruction from the origianl documentation in the preliminary section.
exec /sbin/init 3
Note that the 3:2 means the major number and minor number of the /dev/hda2.
It might be different in your environment.
You could use the following instruction to figure out your own number pair.
ls -l `fdisk -l 2> /dev/null | grep "Linux swap" | awk '{print $1}'` | awk '{print $5 $6}'
For instance, in my environment , it will output the following number pair:
3,2

