Ho to convert VDH to an IMG and more
2 min read

Ho to convert VDH to an IMG and more

Ho to convert VDH to an IMG and more

Today is a weird day. I was trying to get some Windows Servers Evolution 2019 to get to work on VMs that do not support Windows software.
Don't get me wrong, I am not a fan of Windows and have nearly no need for it in my life, but unfortunately my day job requires from me to code in T-SQL, and I need to develop my skills in that language.
I decided that I need to test a lot of features like SSIS or SSRS etc. To do so I need Windows to test on (SQL Server etc.).

So here I am working on VMs with Windows...I know I could just get a VM on Azure and have it up and running in 5 minutes, but: 1. that's no fun:) 2. if you look how mych money MS want's for there infrastructure and compare that to, for example DigitalOcean, then you start to understand why MS is so rich.

I am not paying MS money for there infrastructure if I get get the same for way less. The software that I need, that's a different story, have to pay for it.

Okay, let's wrap this up...should be a short post if I stop taking :P

So I needed to get Windows into an IMG format to get it to work with the VM install process. The default when downloading from MS is: - ISO - Azure - VHD

downloaded from the MS site: EXTERNAL LINK

VHD is the most interesting format, as it already is in a Virtual container (Hyper-V) prepared to use in VMs or any KVM environment.
So I downloaded the VHD version and decided to convert it to IMG, as that is the format I want.

But how do we gonna do that? You ask;)
Well my good friend, that is very simple. All we need is Love and Linux :) The best operating system on this planet :)

On a Linux VM I installed a peace of software called:


To do I needed to execute this code in terminal:

sudo apt install qemu-utils -y 

After installing all the super duper utilities to use, we will focus on one for converting images to different format.

One by one with the code to go:
Depending on what do you actually need (what output format do you need) you will need to use certain arguments:

Source: QCOW2 (KVM, Xen) => Argument: qcow2 
Source: QED (KVM) => Argument: qed 
Source: raw => Argument: raw 
Source: VDI (VirtualBox) => Argument: vdi 
Source: VHD (Hyper-V) => Argument: vpc 
Source: VMDK (VMware) => Argument: vmdk 

To make this easy (examples):
This example will convert a raw image file named image.img (img is a rwa format) to a qcow2 image file:

qemu-img convert -f raw -O qcow2 image.img image.qcow2

Run this to convert a vmdk image file to a raw image file:

qemu-img convert -f vmdk -O raw image.vmdk image.img

Start's to make seans?

Now this is the last example and the command that I used to convert my file WindowsServer2019.vhd to an IMG file:

qemu-img convert -f vpc WindowsServer2019.vhd -O raw WindowsServer2019.img

Easy, right!

Hope this post was of some help for you:)

Enjoying these posts? Subscribe for more