How to do grub-install on a (non loading) virtual guest

How to do grub-install on a (non loading) virtual guest

Amos Shapira amos.shapira at gmail.com
Mon Sep 21 00:05:48 IDT 2009


kpartx is a godsend for (virtual+)LVM2 environments. We use it all the
time to access our virtual machines disks from the vm host (xen,
Centos 5).

I'm not sure why you have to create the device files, though - unless
the vm filesystem is too screwed up for chroot (which it doesn't
appear in your case), you shlould be able to (after your kpartx
command):
1. Mount the vm's root partition (e.g. On /mnt/root).
2. "mount -bind /$x /mnt/root/$x" for $x in "dev", "sys" and "proc"
3. Chroot /mnt/root
4. Do your stuff
5. Reverese the above.

That'a how, for instance, I used to install Ubuntu desktop version
with LVM2 (which didn't support setting up LVM2 in its installation
disk).

-Amos

On 9/20/09, Ehud Karni <ehud at unix.mvs.co.il> wrote:
> 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
>
> _______________________________________________
> Linux-il mailing list
> Linux-il at cs.huji.ac.il
> http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
>



More information about the Linux-il mailing list