How to do grub-install on a (non loading) virtual guest
Ehud Karni
ehud at unix.mvs.co.il
Sun Sep 20 13:32:52 IDT 2009
I had problems with repeated virtual guest crashing and the grub boot
loader destroyed. I found a way of doing grub-install to the virtual
guest (a file, not a partition) on Centos5 host.
I hope it may help anyone with a similar problem.
0) Ensure the virtual machine is not working (use `xm list' to check).
1) Mount the virtual disk (cooked file) on loop device. I use the
`loop7' device because other loop devices may be used by working
virtual guests.
losetup /dev/loop7 <virtual-guest-file>
2) Add all the partitions to the device mapper:
kpartx -a /dev/loop7
3) Mount the virtual root partition:
mkdir -p /mnt/virt
mount /dev/mapper/loop7p1 /mnt/virt
4) Check the Major/Minor values of the mounted devices
ls -l /dev/loop7* /dev/mapper/loop7*
5) Work in as root partition:
chroot /mnt/virt
6) create /dev/hda and /dev/hda1 devices:
mknod dev/hda b 7 7 - Major/minor of /dev/loop7
mknod dev/hda1 b 253 0 - Major/Minor of /dev/mapper/loop7p1
7) Fix the grub by re-install:
grub-install /dev/hda
8) Exit the `chroot' jail
exit
9) Unmount the virtual root partition:
umount /mnt/virt
rmdir /mnt/virt
10) Clear the /dev/mapper partitions:
kpartx -d /dev/loop7
11) Release the loop device:
losetup -d /dev/loop7
Now you can restart the virtual guest: xm create <virtual-guest-name>
Ehud
--
Ehud Karni Tel: +972-3-7966-561 /"\
Mivtach - Simon Fax: +972-3-7976-561 \ / ASCII Ribbon Campaign
Insurance agencies (USA) voice mail and X Against HTML Mail
http://www.mvs.co.il FAX: 1-815-5509341 / \
GnuPG: 98EA398D <http://www.keyserver.net/> Better Safe Than Sorry
More information about the Linux-il
mailing list