Friday, June 23, 2006

Reading xen guest disk image from the outside (FC5)

On Fedora's Xen wiki, there's a tutorial on how to read a xen guest OS's disk from the outside. The instruction works for a physical LVM, but when the disk is actually an image file,
the instruction there does not really work. Here I share my experience, step by step, in the hope of saving somebody else's time. The problem that the original instruction doesn't work is because many people (including myself) simply use Fedora's default
Volume Group name, VolGroup00 in both dom0 and guest systems. Therefore, vgscan will be confused by two volume groups with the same name and gathers only the info of the one currently working, i.e. the one used in dom0. Since LVM basically
provides a unique name for volume accessing, there is no way that we can assign a particular logical volume within a particular volume group, without having a unique name for it. The solution is to change the name of one of them. Since we usually deal
with many guest systems on the same dom0, I choose to change the name for dom0. (It's also possible to change the guest system instead by steps similar to the below, but note that it can only be done from the inside.)
Use Rescue Mode to access the system's root file system
  1. Reboot into the rescue mode (insert FC5 DVD, CD1, or Rescue CD, and at the boot prompt, type linux rescue).
  2. Choose language and keyboard layout.
  3. Choose No when asked about bringing up the network.
  4. When prompted about mounting the original file system, press F2 to bring up a shell.
  5. Wait for a while (for the background lvm process to find necessary info).
Change the volume group's name
  1. At the # prompt, type lvm vgrename VolGroup00 VGHost00
Change original references to the volume group's name
  1. # cd /mnt
  2. # mkdir root boot
  3. # mount /dev/mapper/VGHost00-LogVol00 /mnt/root
  4. # vi root/etc/fstab (replace VolGroup00 with VGHost00, you can use :%s/VolGroup00/VGHost00/g to do so and use ZZ to quit vi)
  5. # umount root; rm -rf root
  6. # mount /dev/hda1 /mnt/boot
  7. # vi boot/grub/grub.config (do the same substitution)
  8. # umount boot; rm -rf boot
Now we need to build a new init ramdisk that knows about the new volume group (reference from this blog)
  1. Press F1 to go back to the rescue menu where it asks about mounting the original system,select Continue (you can also manually mount it -- see the blog reference above)
  2. # chroot /mnt/sysimage
  3. # cp /boot/initrd-2.6.16-1.2133_FC5xen0.img /boot/initrd-2.6.16-1.2133_FC5xen0.old.img
  4. # mkinitrd -v -f /boot/initrd-2.6.16-1.2133_FC5xen0.img 2.6.16-1.2133_FC5xen0
Reboot
  1. # exit
  2. # exit
  3. Remember to remove the Fedora DVD/CD1/RescueCD to boot from your HD
Read the disk image of the guest OS
  1. Use losetup -f to find a free loopback device. Here we assume it's /dev/loop0
  2. # losetup /dev/loop0 your_disk_image_file
  3. # kpartx -av /dev/loop0 (this should give us loop0p1 loop0p2 under /dev/mapper)
  4. # vgscan (this should report both VolGroup00 and VGHost00)
  5. # vgchange -ay VolGroup00
  6. # mkdir /mnt/guest_root
  7. # mount /dev/mapper/VolGroup00-LogVol00 /mnt/guest_root
Voila!

To unmount it, basically we just reverse the steps:
  1. umount /mnt/guest_root
  2. rm -rf /mnt/guest_root
  3. vgchange -an VolGroup00
  4. kpartx -d /dev/loop0
  5. losetup -d /dev/loop0

Monday, June 5, 2006

回應「作弊VS.100分的"好"學生」

在網路上看到一篇「作弊VS.100分的"好"學生」的文章,有感而發而作出回應。

也許唯有讀書高的價值觀現已不如從前,唯有分數高才是真的。只求結果不問過程的功利主義在緊密的社會結構下讓孩子們(以及家長們)想跟別人稍稍有點不同都很不容易。更何況,成長中的孩子很需要肯定(那怕是騙來的肯定),在面對驚人的競爭時,希望用最少的努力得到最大成就感的心態,實在也讓人心疼。

另一篇文章提及電玩,也是孩子們為了得到成就感。成就感不一定得來自過關破台;如您所言,失敗了可以reset重來,可以在沒有進展時關機離開,這些都讓孩子們覺得自己至少有掌控的權力。但現實生活中,他們時時刻刻都要被評分鑑級,使得常得低分的人想作弊,常得高分的人受不了挫折。

同篇文章中的小和尚有一個有智慧明事理的老和尚在生活中教導他人生智慧,我們孩子們能親近的善知識卻沒這麼多,家長們在人格教育上也少有能真正作孩子們好榜樣的。不過,雖然面對大環境難免有無力感,但孩子受教育的過程中,有一兩個老師曾經堅持一些原則,曾經用誠懇真心感動他們,對他們的一生就有無形的影響了。


向您這樣的好老師致敬

路人丁