Tutorial: Migrate a Windows VM from vSphere to KVM
In this guide, we will migrate a Windows VM from vSphere to KVM.
Requirements
- A vSphere VM with one of the following operating systems (All 64 bit):
- Windows Server 2003
- Windows Server 2008
- Windows Server 2008 R2
- Windows Server 2012
- Windows Server 2012 R2
- Windows 7
- Windows 8
- Windows 8.1
- Windows XP
- Administrator privileges for the VM.
- The VM must only have one disk.
Step 1 – Clone the VM to be Migrated
Since we will modify the VM before converting formats, first clone the VM to keep the original VM intact.
Step 2 – Install Virtio Drivers
After cloning, power on the new VM. Download the Virtio drivers onto the machine running the vSphere client. Attach the ISO to the VM.
Open the Device Manager on the Windows VM. Then, right click on the root device and select “Add legacy hardware”.
Click Next. Then select “Install the hardware that I manually select…” and click Next.
Click Next again. Then, click “Have Disk…”.
Click “Browse…”.
Then, navigate to the directory of the ISO.
Click on “Balloon”. Then, select your operating system version.
Select the architecture (x86 or amd64). Then, select the INF file (There should only be one of these).
Click OK, then Next, and Next again. You may need to confirm the driver installation.
When installing the driver, you may receive an error saying that the device cannot start or is not working properly. This is normal, and the driver should be able to start when the VM boots on a KVM hypervisor.
Repeat the process above for the directories NetKVM, qemupciserial, viorng, vioscsi, vioserial, and viostor.
Ignore errors if the qemupciserial driver complains about the machine architecture.
Finally, install the QEMU guest agent on the VM. The installer is located in the ISO file.
Only use the installer that matches your architecture (x86 or x64).
Step 3 – Add the Virtio Drivers to the Windows Registry
Download the Virtio Registry File onto the VM.
Then, open the Windows Registry Editor by searching regedit from the start menu.
Click File -> Import…
Then select the Virtio Registry File that was downloaded.
Step 4 – Uninstall VMware Tools
From the control panel, click on “Uninstall a program”.
Fine the VMware Tools program. Right click on it and select Uninstall. Then, confirm the uninstall.
If prompted to reboot the machine, select Yes.
Step 5 – Install Cloudbase
Download the stable Cloudbase software.
Open the installer and click Next until the final the step is reached.
Select both the sysprep and the shutdown options. Then, click Finish.
Step 6 – Convert VMDK to QCOW2
Note the path of the hard disk of the VM by editing the settings of the VM and selecting the Virtual Disk.
Copy the flat VMDK from the ESX host to the Image Library, or a machine with the qemu-img command available.
After copying, convert the VMDK to a QCOW2 image.
[bash]qemu-img convert -O qcow2 <Input VMDK file> <Ouput QCOW2 file>[/bash]For example:
[bash]qemu-img convert -O qcow2 pf9-win7-copy-flat.vmdk pf9-win7.qcow2[/bash]Step 7 – Upload the Image to the Image Library Host
You can simply copy the converted qcow2 image to the Image library host’s image directory.
OR
Follow our support guide on Getting Started With The OpenStack Command Line if the openstack client is not yet installed.
Then, use the openstack command to upload the image.
–container-format bare
–file pf9-win7.qcow2
–visibility public
–name pf9-win7
–property pf9_description=”Windows VM migrated from vSphere”
–property pf9_virtual_size=<Size in bytes>[/bash]
For example:
[bash]openstack image create –disk-format qcow2–container-format bare
–file
–visibility public
–name
–property pf9_description=”Windows VM migrated from vSphere”
–property pf9_virtual_size=26422542336[/bash]
Step 8 – Create an Instance
Create an instance as you normally would. However, for Windows VMs using cloudbase-init, ensure cloud-init is enabled.
Enjoy your newly migrated Windows VM!