Sunday, January 18, 2009

Hibernation with lvm-based root

最近常常把工作帶回宿舍, 每次回到宿舍總要重新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

Sunday, December 28, 2008

MFC寫的網路俄羅斯方塊

最近清理硬碟時,
發現以前修丁老大MFC的課時寫的作業網路俄羅斯方塊,
因為早就幾百年不用Windows了,

用Wine試試看
什麼都不用改就可以動了,
但是中文不見了, 可能是Wine沒有中文字形的關係
自己玩得不亦樂乎...

雖然Linux裡面就內建俄羅斯方塊了, 作得也比我的好太多, 但是玩自己寫的
就是比較有趣味啊...而且還有雙方互相陷害的功能(就是自己堆起來超過3層的會跑到對手那邊去)

From Public




下載位置

兩個人擠在電腦前也可以玩,
用網路的話
如果TCP RTT很短的話還可以玩
但是如果TCP RTT 時間太長的話,
可能會照成兩個人都怪怪的情況
懶得修了, 反正只是個作業

當年寫完這個作業後本來想繼續寫Server版的,
但是Compiler課太操了...
寫完期末作業後就開始準備研究所考試了
所以就沒再寫下去了

現在年紀大了
反而對寫程式一點熱情都沒有, 尤其是寫不會賺錢自己寫爽的程式

年輕果然是本錢啊, 尤其是閒閒大學生...

這個程式的前身是Java俄羅斯方塊, 也是Java程式期末作業,
我還load到老師的電腦裡面Demo, 在老師面前玩俄羅斯, 開了四個視窗
玩了好久還沒辦法把垃圾丟到另外一邊, 越玩越緊張, 老師最後就給我分數叫我不要再玩下去了, Orz...

From Public


不知道為什麼, 每次老師出沒有主題的期末作業, 我就只想到俄羅斯方塊....

Wednesday, November 12, 2008

這真是一隻不屈服於主人淫威之下的好狗啊~

還會用台語三字經罵主人~



Sunday, November 9, 2008

好聽的歌

Thursday, November 6, 2008

GIT empty directory problem using subversion as backend

When using git, there might be a problem that the empty directory will not be tracked.

In several embedded device projects, this would cause a serious problem. For instance, the firmware won't work when /mnt, /proc, /etc are missed.

Try the following instruction to work around.

Save the following script as touch_if_empty.sh, and chmod +x it.


#!/bin/bash
echo $1| grep -v .svn > /dev/null
if [ $? -eq 0 ]; then
let count=`find $1 -maxdepth 1|grep -v .svn|wc -l`;
else
let count=2;
fi

if [ $count -eq 1 ]; then
echo "Touching $1";
touch $1/.gitignore;
svn add $1/.gitignore;
fi



 Firstly, use the following instruction to checkout svn workcopy first.
Note that you should use this solution under a pristine working copy since at the last step we want to commit back into svn.

svn co http://myrepository working_copy

Then use find to examine each directory to see if the directory is empty.

cd working_copy
find -type d -exec touch_if_empty.sh '{}' \;
svn commit -m "Added .gitignore in each empty directory for GIT empty directory issue"

After all, you could git-svn clone your repository...and enjoy the powerful GIT.