Converting Windows Guests From VMWare ESX to KVM With Virtio Drivers

Tags: , , , , , , , , , , , , , , , , , , , , , , ,

The below steps were tested while pulling my hair out trying to migrate a Windows 2k3 guest from VMWare ESX to KVM managed by libvirt, hopefully this will save you from much windows related pain and suffering.

Prep the VM while it’s still running in VMware

Download and run MergeIDE.bat. This is a really important step that will prepare the system to boot using an IDE driver when we bring it up in KVM. Skipping this step will likely result in blue screen errors and much frustration.

MergeIDE can be downloaded at

Also, ensure that you know the local administrator password. This seems rather obvious but networking may not come up, so best to be prepared.

Now you’re ready to shut down and copy the vm.

Shutdown the VM and copy it’s vmdk

Gracefully shut down the VM. Once it’s down, ssh into your ESX server and navigate to the appropriate VMFS volume containing your VM.

[root@esx1 example-vm]# pwd
[root@esx1 example-vm]# ls
example-vm-flat.vmdk    example-vm.vmdk  example-vm.vmx   
example-vm.nvram      example-vm.vmsd  example-vm.vmxf 
vmware-0.log  vmware-2.log  vmware-7.log  vmware.log
vmware-1.log  vmware-6.log  vmware-8.log

SCP the “flat” .vmdk file (or files if your machine has multiple virtual disks) from your ESX host to your KVM host.

[root@esx1 example-vm]# scp -pr example-vm-flat.vmdk kvm1:/etc/libvirt/images/
root@kvm1 password: 
example-vm-flat.vmdk           100%   20GB  14.6MB/s   23:20

Prepare the libvirt/KVM instance

Create an XML file to define the attributes of the virtual machine. You’ll likely want to copy things like the memory size, number of CPUs and MAC address from the vmware vmx file, in our case this is /vmfs/volumes/VMFS1/example-vm/example-vm.vmx.

In order to set up virtio we first set our primry disk as bus type ide and create a secondary disk with a bus type of virtio. This will allow us to boot from the existing OS without special drivers. From there windows will detect the secondary virtio SCSI adapter and prompt for driver installation. We’ll also attach a virtio guest drivers floppy while we’re at it.

Virtio guest driver iso and floppy images can be downloaded at

<domain type='kvm'>
    <type arch='x86_64' machine='rhel5.4.0'>hvm</type>
    <boot dev='hd'/>
  <clock offset='utc'/>
    <disk type='file' device='disk'>
      <driver name='qemu' cache='none'/>
      <source file='/etc/libvirt/images/example-vm/example-vm-flat.vmdk'/>
      <target dev='hda' bus='ide'/>
      <driver name='qemu' cache='none'/>
      <source file='/etc/libvirt/images/example-vm/virtio-temp.raw'/>
      <target dev='vdb' bus='virtio'/>
    <disk type='file' device='floppy'>
      <source file='/root/virtio-win-1.1.16.vfd'/>
      <target dev='fda' bus='fdc'/>
    <interface type='bridge'>
      <mac address='00:50:56:b9:4e:50'/>
      <source bridge='virbr0'/>
      <model type='virtio'/>
    <serial type='pty'>
      <target port='0'/>
    <console type='pty'>
      <target port='0'/>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes' keymap='en-us'/>

Note: if you need to generate a new uuid simply run uuidgen

Now you’re ready to “Define” the new virtual machine in libvirt.

[root@kvm1 ~]# virsh define /etc/libvirt/qemu/example-vm.xml 
Domain example-vm defined from /etc/libvirt/qemu/example-vm.xml

Boot the KVM guest

Using virt-manager, start the virtual machine. It should boot up and allow you to log in as a local administrator or with cached credentials. If you are seeing a bsod (blue screen) with error 0x000007b boot errors, verify that the MergeIDE step was successful. This resolved my 0x7b errors.

Install the windows virtio guest drivers

Upon logging in, windows should detect the new virtio SCSI and network hardware and prompt you for drivers. You’ll want to point it at the floppy drive we attached to the guest.

A very detailed description of what to do is available at

Change the primary disk from ide to virtio

Finally, once the virtio drivers have been successfully installed you’re ready to change your boot disk to a bus type of virtio and can remove the temporary second drive. This can be done by executing virsh edit example-vm while the host is running and changing the disk dev= and bus= as follows:

    <disk type='file' device='disk'>
      <driver name='qemu' cache='none'/>
      <source file='/etc/libvirt/images/example-vm/example-vm-flat.vmdk'/>
      <target dev='vda' bus='virtio'/>

You can also remove the driver floppy at this time.

Perform a full reboot of the guest

To make the above change take effect simply shut the machine down completely and then re-start it with virt-manager. Don’t simply issue a reboot from within the VM, we need to apply the changes to the libvirt domain definition.

You’re done!

Your VM should now be up and running, free from vmware and benefiting from the performance gains of virtio.

6 Responses to “Converting Windows Guests From VMWare ESX to KVM With Virtio Drivers”

  1. Bookmarks for 1 lug 2012 through 2 lug 2012 | jtheo Says:

    […] Converting Windows Guests From VMWare ESX to KVM With Virtio Drivers | Backdrift – The below steps were tested while pulling my hair out trying to migrate a Windows 2k3 guest from VMWare ESX to KVM managed by libvirt, hopefully this will save you from much windows related pain and suffering. […]

  2. Mark Says:

    Hi, – What’s your experience with this conversion from esx to kvm? Are you running anything in a production environment? Best, Mark


    Keith Reply:

    I wrote this post after a very long night of migrating hosts from esx to kvm. Both esx and kvm were clustered prod environments, back ended by fc and iscsi storage. This method was successful for me, however it’s more manual than I would like because I was constrained by software available via rpm for the centos5 kvm hosts. If you’re running a more updated host OS for kvm, there may be better utilities available to inject the virtio drivers into windows guest systems.


  3. Converting a Windows 2008R2 vmdk to a KVM Image | A CloudBuilder's Notes Says:

    […] […]

  4. Cynthia Says:

    KVM is a virtualization tocnholegy that only works with Linux as host operating system; if your host operating system is Windows 7 this post is not very useful for you. If your objective is to run Debian or any other linux under Windows 7, then you should give a try to VirtualBox, a desktop virtualization tool that also supports Windows 7 as host. I’m pretty sure any linux can run as guest OS under VirtualBox.If on the other hand you want to exercise KVM, then you need to set up a linux box for that.


    Greg Reply:

    Not True Cynthia… You are confusing KVM with Container based VMs….
    Containers use the underlying kernel and services of the host, where a KVM is a standalone VM that has it’s own drivers, hooks,kernel and IO.


Join the Conversation