Dealing with Grub on KVM images

From WikiOAR

Revision as of 11:11, 21 April 2010 by Bzizou (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

... without having to boot the appliance, and doing it from the outside, by using NBD

dd if=/dev/zero of=/var/guests/test.img bs=1M count=1 seek=4000
modprobe nbd max_part=8
kvm-nbd -c /dev/nbd1 /var/guests/test.img
fdisk /dev/nbd1
mkfs /dev/nbd1p1
mount /dev/nbd1p1 /mnt
cp -a /boot /mnt/
echo "(hd0) /dev/nbd1" > /boot/grub/device.map
grub-install /dev/nbd1 --root-directory=/mnt --modules="biosdisk part_msdos"
   Installation finished. No error reported.
umount /mnt
kvm-nbd -d /dev/nbd1
kvm /var/guests/test.img
   GNU GRUB version...
Image:Note.png Note

This only works with GRUB 2

You should also create a grub.cfg file in the /boot/grub directory. Here is a minimum:

set default=0
set timeout=5
set root='(hd0,1)'
menuentry "Kameleon" {
  linux /boot/vmlinuz-2.6.32-3-amd64 root=/dev/hda3
  initrd /boot/initrd.img-2.6.32-3-amd64
}
Personal tools