Converting a Hyper-V vhdx for use with KVM or Proxmox VE

5
Export Hyper V Vhdx
Export Hyper V Vhdx

Recently we removed a 1/2 rack of servers from one of our data centers. That included our last two Microsoft Hyper-V 2012 R2 servers that hosted two VMs with historical STH Bench data for development. To make things slightly more interesting, the domain controller had been removed so we had Hyper-V hosts that were not responding to GUI tools and we had one day to move data off them. Not a great situation, but we wanted to show how you can quickly convert a Hyper-V VM to KVM. In this case, we are putting the VMs on a Promxox VE cluster so we can get the VMs on an all-flash Ceph storage array. Proxmox VE is a Debian Linux based platform that combines features such as KVM virtualization, containers, ZFS, GlusterFS and Ceph storage as well as cluster management all with a nice Web GUI. If you are simply using a Ubuntu, RHEL or CentOS KVM virtualization setup, these same steps will work minus the Proxmox GUI views.

Converting Hyper-V vhdx Virtual Machine for KVM Usage

The total process took a long time as we only had 100mbps of bandwidth between the three data centers free for this project. The actual hands-on-keyboard time took a matter of minutes for both VMs. The trick is that our KVM system did not work with vhdx Hyper-V virtual machine drives so we needed to convert them into a qcow2 image (more on why later.)

Step 1: Export the VM to get a clean VHDx snapshot

Hyper-V has a great snapshot and replication feature. The Hyper-V hypervisors we had setup had a very fast 40GbE interconnect and SSD storage so we could take many snapshots. The first step is to export the VM so you can have one vhdxx virtual drive to transfer and convert. If you can use the GUI, this is a few clicks away.

Export Hyper V Vhdx
Export Hyper V Vhdx (demonstrated on a desktop copy and Hyper-V Manager)

If you cannot get to a Hyper-V Manager GUI, then you will likely want to use the Export-VM command via PowerShell. If you get really stuck and cannot open a remote PowerShell session to the Hyper-V host, you can use RDP (if enabled) or iKVM on the server to get to a PowerShell prompt.

Using the Export-VM command via PowerShell or via the Hyper-V Manager GUI ensures that you get a single vhdx file ready to transfer and convert.

Step 2: Send the vhdx to the target KVM virtualization host

This step is really easy, especially if you exported the VM to a network share location. If so, you can simply copy the resultant vhdx to the new server. If you cannot, we have seen various other combinations of USB drives, SFTP clients and other methods to get the vhdx drive to the target server.

Step 3: Check the image before proceeding

Since the transfer was likely many GB in size and we are going Windows to Linux, it is always good to check that the vhdx image does not have errors before proceeding. Here is the command where “Bench-Dev.vhdx” is the file we transferred.

# qemu-img check -r all Bench-Dev.vhdx

Hyper V Vhdx To Proxmox Qcow2 Qemu Img Check
Hyper-V Vhdx To Proxmox Qcow2 Qemu-Img Check

As you can see, the vhdx file passed with no errors reported.

Step 4: Create the VM you want to use

At this point, we wanted to create a VM that we are going to use with the image we transferred. Here the key is to ensure that you make a VM that mirrors the Hyper-V VM in terms of CPU, RAM, network and disk options. Most modern OSes are supported via KVM so you should have little issue getting things to work, especially with Linux guests.

Hyper V Vhdx To Proxmox Qcow2 Create VM With Qcow2 Local Storage
Hyper V Vhdx To Proxmox Qcow2 Create VM With Qcow2 Local Storage

Step 5: Find the VMs qcow2 image

There are a few different ways you can do this, including creating the VM and attaching the disk after converting the vhdx. Since we want to keep Proxmox VE’s naming convention (and make the process easy), we are going to simply overwrite the qcow2 image that the virtual machine wizard created. First, we need to find the VM.

Since you can see that the disk in the shot above is named vm-112-disk-1.qcow2, we can search for that on our Linux/ Proxmox VE host.

Hyper V Vhdx To Proxmox Qcow2 Find Qcow2 Disk To Overwrite
Hyper V Vhdx To Proxmox Qcow2 Find Qcow2 Disk To Overwrite

Now that we know the location, we can set the output of the conversion operation to overwrite the empty disk.

Step 6: Convert the vhdx to qcow2 and verify

The command to convert our image and overwrite the empty qcow2 is very simple. We are going to use qemu-img convert, specify the output type and then the vhdx followed by the full path to the qcow2 image.

Hyper V Vhdx To Proxmox Qcow2 Qemu Img Convert
Hyper V Vhdx To Proxmox Qcow2 Qemu Img Convert

Here is the command you can adapt to your setup:

qemu-img convert -O qcow2 Bench-Dev.vhdx /var/lib/vz/images/112/vm-112-disk-1.qcow2

We also validated that the disk is indeed written int eh correct place.

Step 7: Boot the VM

At this point, you should be able to boot the VM. There are still some tasks that will need to be completed. For example, updating network settings. Generally, this type of conversion will yield a different network interface so there are likely steps like setting that up in the guest OS that will need to happen. Platforms like Proxmox VE have built-in console viewer applications so we were able to do this post-transfer. Another option is to complete these steps before transferring/ converting the VM so that you can power-up and verify that the operation works.

Hyper V Vhdx To Proxmox Qcow2 Boot To Verify
Hyper V Vhdx To Proxmox Qcow2 Boot To Verify

These 7 quick steps take only a few minutes (save for the inter-data center transfer) and helped us move our Hyper-V VMs to KVM quickly and painlessly.

5 COMMENTS

  1. Hi, followed the guide but it appears that the disk isn’t bootable. I converted using qemu-img on Windows (https://cloudbase.it/qemu-img-windows/) prior to transferring the files to Proxmox as I was getting an error as indicated below:

    root@proxhost:/var/lib/vz/raid1/temp# qemu-img convert -O qcow2 sourceimage.vhdx /var/lib/vz/raid1/images/105/vm-105-disk-1.qcow2
    qemu-img: error while reading sector 24641536: Input/output error

    I’m running qemu-img 2.2.1, is a newer version required in order to accomplish this conversion?

  2. I tried this. My UEFI Linux VMs came across fine, but the UEFI 2012 R2 servers just blue screen on startup (came from Hyper-V Server 2016).

LEAVE A REPLY

Please enter your comment!
Please enter your name here