Converting Virtual Machine disk formats

There are many Virtual Disk formats, VDI, VMDK, VHD, VHDX, IMG, RAW, HDD, and many more. Unfortunately VHD and VHDX formats are amongst the least popular ones, but if you’re running a Hyper-V server these are the only formats you can work with.

Don’t fret, there is a way to convert a lot of these common formats to the VHD Micrsosoft disk image. Oracle includes a conversion tool with their Virtual Box application VBoxManage.Virtual box is a free tool available for download, and use. You can find the software over here: https://www.virtualbox.org/ .

I found that this works better than the actual tool that Microsoft offers and have since successfully converted many formats with Virtual Box to the VHD disk image. Usually I go from a IMG to VHD file. I capture the drive using dd from within a Linux Mint boot drive and then proceed to convert it. But I have sometimes setup test VMs in VirtualBox that I needed to run on a Hyper-V server after.

To perform the conversions have a look at the following two commands.

Install Virtual Box and use it by opening a command prompt and navigate to the VirtualBox installation directory. Usually located in C:\Program Files\Oracle\VirtualBox.

Usage:

VBoxManage clonehd  <uuid|inputfile>  <uuid|outputfile>
                    [--format VDI|VMDK|VHD|RAW|<other>]
                    [--variant Standard,Fixed,Split2G,Stream,ESX]
                    [--existing]

A baisc command and output of this would look something like this.

C:\Program Files\Oracle\VirtualBox>VBoxManage.exe clonehd "c:\VMs\Windows 10\Windows 10.vmdk" "f:\temp\Windows10.vhd" -format vhd
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone hard disk created in format 'vhd'. UUID: 1f6e118a-f0e2-49ed-a352-6b842791cdfa

C:\Program Files\Oracle\VirtualBox>

VHD is a Hyper-V generation 1 format, where as VHDX is a Hyper-V generation 2 format.

Alternatively if you have a DD captured raw IMG file you can convert it to VHD by using the following command first:

 C:\Program Files\Oracle\VirtualBox>VBoxManage.exe convertdd file.img file.vmdk

…once converted follow this up by the “clonehd” command which converts to vhd. Prior to converting to vhd make an attempt to boot the vmdk in VirtualBox. Attempt to boot it in to the OS, either normally or via safe mode. The reason for this is that sometimes the OS will need to run a chkdsk before booting into itself, you should let it run as this chkdsk will allow the vhd to properly mount in Hyper-V. It seems that either the VMDK format is more forgiving than VHD, or only VirtualBox can fix the conversion errors.

If you’re only looking to only mount a volume and not boot off the virtual disk and into an OS you can try a tool called Disk2vhd. Also since windows 7 the backup software built into the OS created vhd backup sets. That could be an option as well.

6 thoughts on “Converting Virtual Machine disk formats

Add yours

  1. Thank you! Worked like a charm.

    I combined this with another step-by-step that highlighted:
    – Creating a blank VM first, then
    – Detaching the empty boot volume and
    – Creating a new volume from the converted VHDX and attach it as the IDE boot volume.

    Viola’! Running clone from Hyper-V. Slower than molasses though on a dual Xeon X5675 48 GB ECC DDR3 and SATA SSDs! That’s next to conquer – make it usable. Seems like allocating 8 cores and 18 GB RAM would run a Win Server 2019 Essentials quite easily – maybe not perfect like Hyper-V did with 1/3 less resources, but not the heartburn inducing experience I’m currently suffering.

  2. Great post thanks. I needed to convert a Google Cloud RAW drive to VHD for archiving purposes. Some revisions you might like to consider, at least with VirtualBox 6.0.14:

    – The command is now clonemedium, tho clonehd is mapped internally to clonemedium
    – For the RAW disk exported from a Google Cloud image I had to use convertfromraw. The clonemedium command does not support RAW as an input format.

    Jon

  3. Changing the format of cloudready-free-85.3.2-64bit.bin using VBoxManage {to .iso extension!}
    I’ve used this in the past but damned if I can find it!

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create a free website or blog at WordPress.com.

Up ↑