Convert KVM images to Virtual Box (VDI)

It took a while to get the KVM image working with Sun virtual box.

The advantages of a virtual box image is, you can run it on any platform (linux, mac or windows), works without virtualization enabled processor and will work on a 32bit machine
Here are the steps to create an image that works with virtual box:

From the KVM installed server

$ qemu-img convert kvm-os.img -O raw kvm-os-raw.img

Copy the image (kvm-os-raw.img) to virtual box machine

$ VBoxManage convertfromraw --format VDI kvm-os-raw.img vbox.vdi

Converting from raw image file=”kvm-os-raw.img” to file=”vbox.vdi”…
Creating dynamic image with size ….

This will create a virtual box compatible image
Incase required you can compact the image to actual size

$ VBoxManage modifyvdi /home/user/vbox.vdi compact

Here the path to vdi image must be absolute.

Now you can create a new virtual machine from virtual box console/command line, with the vdi image as storage.
Boot the machine and hope for the best :)
But it wasn’t easy for me even after this beautiful vdi image, boot hangs with a kernel panic, file system not found.

To fix this issue, we need to recreate the initrd image in the virtual machine:
instructions to do it for redhat:
– Boot the virtual machine in rescue mode with Redhat CD

> linux rescue

# chroot /mnt/sysimage

take a backup of existing initrd

# cp /boot/ initrd-2.6-old

create new initrd image

# mkinitrd -v /boot/initrd-new.img kernel-version

// eg: mkinitrd -v /boot/initrd-new.img 2.6.18-194.8.1.el5

edit the grub configuration and replace the initrd image name with new one

# cat /boot/grub/menu.lst

Reboot the machine and see if it boots :)

Hope this will be helpful for someone, I spent hours to get it working :) .

6 thoughts on “Convert KVM images to Virtual Box (VDI)”

  1. Thanks it worked
    I wanted to migrate to VBOX because KVM doesn’t support bridging with network manager enabled on Fedora and I use network manager on my laptop so I moved to VBOX and it worked perfectly with bridging mode and network manager enabled, Iam not sure why KVM make it harder some times.

  2. KVM usually works with bridge interface, hope at some point network manager supports bridging, other wise just forget about the network manager and do the manual configuration :)

  3. Thanks Arun, I had the same issue and the same solution (mkinitrd), when migrating an Oracle VM OL5u8 PVM to VBox.

  4. Find 1 error ;)

    $ VBoxManage convertfromrow –format VDI kvm-os-raw.img vbox.vdi

    $ VBoxManage convertfromraw –format VDI kvm-os-raw.img vbox.vdi

Leave a Reply

Your email address will not be published. Required fields are marked *