Archive for the ‘Virtualization’ Category.

Virtualbox to KVM Migration

I needed to migrate 4 Virtual Machines to KVM from Virtualbox due one of my client’s request.

KVM is relatively new technology compared to Virtualbox but it is expected to provide better performance than Virtualbox because Virtual box is level 1 hypervisor where in KVM is level 2 hypervisor.

I struggled a lot during the migration but managed to complete migration.I could not find enough details about the complete migration so i am writing this post so that i can share my experience with you guys.

Steps to Migration:

  • First you need to convert Virtualbox (VDI) image to KVM’s format (QCOW2).It is a two stage process.First you need to convert VDI to RAW format and then you can convert RAW image to QCOW2 format.

For example,

#VBoxManage clonehd --format RAW /storage/node1.vdi /storage/node1.img

#qemu-img convert -f raw /storage/node1.img -O qcow2 /storage/node1.qcow
  • Once you have VDI image converted to QCOW2 format , you need to install virt-manager.
#yum install virt-manager
  • After you have install the virt-manager, start the virt-manager and create new VM with existing qcow2 image as HDD.
  • Now you have VM configured to run with KVM but when you try to start the VM you may end up with following error.

“not a bootable device”

  • If you end up with about error then you need to follow the following steps to make VM working.

It appears that virt-manager does not read the hard drive image format of a pre-existing image when creating a new virtual machine and instead chooses the “raw” format. Since virt-manager seems to store it’s setting internally, you cannot just edit the /usr/libvirt/qemu/VMNameHere.xml file.

You must export the libvirt vm settings to xml, fix the hard drive image formatting, and import the vm settings back into libvirt.

  • Get vm name:
virsh -c qemu:///session list --all
  • Export vm settings:
virsh -c qemu:///session dumpxml VMName > /tmp/VMName.xml
  • Update the hard drive format in the xml file:

From

<devices>

<emulator>/usr/bin/kvm</emulator>

<disk type='file' device='disk'>

<driver name='qemu' type='raw'/>

<source file='/storage/node1.qcow'/>

<target dev='hda' bus='ide'/>

</disk>

To

<devices>

<emulator>/usr/bin/kvm</emulator>

<disk type='file' device='disk'>

<driver name='qemu' type='qcow2'/>

<source file='/storage/node1.qcow'/>

<target dev='hda' bus='ide'/>

</disk>
  • Remove old vm settings in virt-manager:

Open virt-manager and delete the problem vm but make sure to leave the hard drive image

  • Import in the fixed xml file:
virsh -c qemu:///session define /tmp/VMName.xml

The vm will automatically appear in virt-manager.

The vm should boot fine now.

You also need to create a bridged networking device if you want to use bridge networking.

Here are the steps to create bridged interface.

  • Create bridged interface config in /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=bridge
IPADDR=192.168.1.100
NETMASK=255.255.255.0
ONBOOT=yes
GATEWAY=192.168.1.254
  • Change the bond0 config in /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BRIDGE=br0
ONBOOT=yes


  • brctl show , it will show bond0 as an enabled bridged interface which kvm can use.
bridge name     bridge id               STP enabled     interfaces

br0             8000.001cc45b7c06       no              bond0