IT Blog

Quick Tips

How to migrate Hyper-v vhdx VM to Proxmox qcow2

Hyper-v to Proxmox Virtual Machine migration

Today I will go through migrating a Windows Hyper-v Virtual machine with the VHDX dynamic disk format to Proxmox qcow2 format.

In my case I will be migrating a server 2012 R2 vm but this will work with 2016 and 2019 as well

It’s actually pretty straight forward but there are multiple guides out there so I thought I would try doing it step by step.

We are going to assume that the Virtual machine on Hyper-v is functioning correctly as-is.

Pre-requisites:

Downloads on the Windows Hyper-v hypervisor:

  1. Virtio Drivers : https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/We Will be using this download link as it’s the latest iso: https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.215-2/virtio-win.iso
  2. Qemu img convert programme to be run on the hypervisor : https://cloudbase.it/qemu-img-windows/
  3. FileZilla client : https://filezilla-project.org/download.php

 

Prepare the Hyper-v VM with Virtio Drivers

 

This step is crucial otherwise when the disk is on Proxmox then it will not load due to the drivers for the scsi or ide controller not being there.

You will get blue screens on the VM Console and maybe even a no bootable device found error.

 

Attach the Hyper-v VM with the virtio drivers iso file that has been downloaded on the hyper-v server:

Browse inside the Virtual Machine console to the attached Virtio DVD Drive:

Double click / Install “Virtio-win-gt-x64.msi” to Install Guest Tools, follow the steps and ensure all the options are selected for the drivers installation:

Press Next and allow the installation to finish.

Then install the correct msi inside the “guest-agent” folder:

 

After this step you can shutdown the Virtual machine ready to convert and export the new Disk to use inside of Proxmox.

Be sure to note down your VM information such as the IP configuration and assigned virtual mac address.

Our VM that we are migrating has a Disk of 127GB, of which only 15.2GB is free.

For you to cross reference between your hyper-v disk and ours, here is a screen shot of the settings we have:

Exporting VHDx to Qcow2 format using qemu-img.exe

Now time for the export to qcow2

Browse to the Qemu-img application that has been downloaded (link in pre-requisites) via powershell admin:

Then run the command, change your settings as desired. For us the command was:

.\qemu-img.exe convert ‘D:\rds-server-vmnew\Virtual Hard Disks\RDS-SERVER.vhdx’ -O qcow2 D:\rds-server.qcow2

When you start running this command, there is no sort of feedback in the powershell console window so be patient.

You can check the progress by going to the output directory and looking at the current file properties of the file to see how much it has done so far.

As you can see from our command we are reading and writing to the same disk so it will be slow – Bonus points if you use two different SSDs haha.

In our method we don’t want to export to an external hard drive, purely because in this guide I am migrating the Virtual machines remotely and will ship off the exported disk image over the internal network via filezilla later.

Filezilla being the sftp client and the proxmox being the server using ssh credentials over port 22.

 

This is a perfect time to go ahead and do some Proxmox Preparations:

Create a Virtual Machine on the Proxmox server without a Virtual disk and without a Network Device (for now)

Well, the proxmox wizard when creating a VM forces you to create a Virtual machine disk, just set the size to 1GB, then after it’s created, go into it and “Detach” and “Remove” that disk.

Go into the Proxmox VM settings and change the OS Type to Windows (if you didn’t do it at the creation wizard) and enable the “QEMU Guest Agent” setting:

As you can see the Hardware settings of the Virtual Machine is without both network adapter and without the disk:

 

Back to the VHDx to Qcow2 disk conversion

The command has finished and the exported disk is ready:

Now it’s time to send it over to the proxmox server.

The new Virtual Machine has been assigned a new VM id which in our case is 103.

So we want to place this vDisk in the directory relating to this VM folder.

In our case the location will be :

/var/lib/vz/images/

So we need to create the 103 folder and then give it the correct permissions:

 

mkdir /var/lib/vz/images/103

chmod 740 /var/lib/vz/images/103

Open up FileZilla and copy / move the vm disk over to the newly created folder. This might take some time depending on the network speed and file size.

 

Once the transfer is finished go back into the Proxmox shell and run the following command:

qm rescan

This will scan the directories and add unattached disks to the VM configuration:

Now if we go to the hardware settings of the proxmox VM we will be able to see the unused disk sat there.

We need to click on “Edit” at the top to associate it.

I’ve selected SCSI as the Bus/Device and then press Add:

As we can see it has successfully added the disk to the VM:

 

Now it’s time to turn on the bugger but before we do that, we have to enable the boot device and put it in the right order:

After this go to the Console and press start.

However for me it was booting up and then bluescreening. It did this a few times and then rebooted into the recovery window.

Technically all should be hunky dory. But we all know with systems it’s never the case!

When it booted into recovery mode, I loaded up command prompt and went into “diskpart” then “list disk” which shows no disks listed.

This means that the scsi bus driver is not liked.

To fix this, load up the virtio iso image to be accessible from the vm in proxmox settings:

CD Drive is hotplug so the VM does not need rebooting.

I found my cd drives contents on the “D” drive so in CMD console window I just typed in “D:” to be able to navigate to the contents of it.

Now we will use the drvload command like so:

drvload D:\vioscsi\2k12r2\amd64\vioscsi.inf

Of course, change the Operating system version to yours if its not Server 2012 R2

After this we run Diskpart and list disk to verify that the HDD is seen:

When I now do a “list volume” I am able to see that the letter “E” has been assigned to the operating system installation

 

However we still need to properly install all the drivers. We will use a DISM command to do that:

dism /image:E:\ /add-driver /Driver:D:\ /recurse

E: is my letter for Windows

D: is my letter for the virtio drivers image disc

Shut the VM down, Start it back up and you will see the “getting ready”

And Magic :

 

Sign in and go to device manager, make sure all is ok:

 

Now the easy part, add a network adapter, go into the vm, set the ip back to static, ignore the warnings. Go back into the adapter and ensure the gateway is there.

 

Some notes:

Sometimes if you’re unlucky, the VM will not even boot into recovery mode – in which case you need to boot into the installation media and load up command prompt from that window.

 

Thank you

ibrahim@broadband9.com for any edits / questions.