Migrate VMWare VM (.vmdk) to KVM (.qcow2)

This migration was done on a CentOS 6.5 host. I’m sure Ubuntu is not a whole lot different other than the network configs and some package names.

First, install libvirt, kvm and other necessary packages.

yum -y install kvm qemu-kvm python-virtinst libvirt libvirt-python virt-manager libguestfs-tools bridge-utils

Next, I created a new directory because of the way my paritioning was done, but you could just copy the existing .vmdk to the libvirt images directory.

sudo mkdir /your/vm/path
sudo cp -av /path/to/old/vm.vmdk /your/vm/path

Once it’s copied, convert it to .qcow2 for KVM compatibility

sudo qemu-img convert /your/vm/path/vm.vmdk -O qcow2 /your/vm/path/vm.qcow2

Now you will need to configure a bridge so virtual networking will work as needed. Since your NIC ports will become slaves to the bridge, this config will now be the one with all the IP configuration.

To avoid any issues on startup, I first remove NetworkManager (on CentOS). Make sure your existing interface(s) are not NM_CONTROLLED before you remove it.

Next, create the bridge (replace as needed with your LAN information):


For a seamless transition to the bridge (without your session being dropped), I first bring up the new bridge

sudo ifup br0

After that, we will re-configure your NIC port(s) to be slaves to the bridge. Delete all the lines in your eth0/em0 except for the following:


Then you can restart networking to see your changes take full effect

sudo service network restart

Now that our networking and virtual disk are ready, we can start libvirtd and spin up the new VM. Amend the various parameters in the virt-install command to your needs. In this case, I was migrating a Windows 7 VM. The –import at the end is important as it tells virt-install to use the existing virtual disk.

service libvirtd start
chkconfig libvirtd on
#install the vm with virt-install
virt-install --connect qemu:///system --virt-type kvm --ram 1024 -n win64 -r 1024 --os-type=windows --os-variant=win7 --disk path=/your/vm/path/vm.qcow2,device=disk,format=qcow2 --vcpus=1 --vnc --noautoconsole --import

Now you can connect to your VM with VNC, SSH, RDP or whatever you have configured.

Leave a Reply

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