Virtualization is an useful tool for IT trainers. We use virtual machines for our custom trainings to give our attenders a convenient way to try the technology. However, due to the diversity of VM hypervisors, it also can become a headache: some people have VirtualBox, some people have Hyper-V, others have even different one. In most cases OVF format can be used to load the VM, but there is one exception: Hyper-V. Our walkaround is to convert the disk image file and create a VM basing on it – much faster than creating the whole virtual machine from scratch.
Step 1: unpacking
A OVA file is actually an achrive containing VM metadata file and VMDK (virtual disk image) file. To import the drive into a Hyper-V VM, we must extract the latter one. To do so, any archive extractor will be sufficient (eg. 7z on Windows, tar command on Linux). Nothing fancy here, just get .vmdk file from the archive. The .ovf file will not be used.
Step 2:Tweaking disk image metadata
Before converting the VMDK file to VHDX format a little tweaking is necessary. VirtualBox adds some metadata to the disk image, which is not recognized by the converter. As a result, a little ambiguous error is reported:
ConvertTo-MvmcVirtualHardDisk : The entry 0f297912-0dc7-4fdb-9c4a-a510edd5a5b9 is not a supported disk database entry for the descriptor. At line:1 char:1 + ConvertTo-MvmcVirtualHardDisk -SourceLiteralPath '.\Cassandra Trainin ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : WriteError: (Microsoft.Accel...nversionService:DriveConversionService) [ConvertTo-MvmcVirtualHardDisk], VmdkDescriptorParseException + FullyQualifiedErrorId : DiskConversion,Microsoft.Accelerators.Mvmc.Cmdlet.Commands.ConvertToMvmcVirtualHardDiskCommand
Basically, some entries from the metadata must be removed before running the converter. However, the drive image file is way too big to be manipulated directly. Instead, dfso/dfsi (available on the author’s homepage as dfsok) tools may be used to extract and write the descriptor of the disk image.
dsfo.exe '.\Cassandra Training VM.vmdk' 512 1024 desc.txt
As the result, a new file called desc.txt is created. It can be opened using any text editor, eg. notepad or nano. Inside, apart from valid and required metadata, some VirtualBox-exclusive entries may be found:
ddb.uuid.image="0f297912-0dc7-4fdb-9c4a-a510edd5a5b9" ddb.uuid.parent="00000000-0000-0000-0000-000000000000" ddb.uuid.modification="00000000-0000-0000-0000-000000000000" ddb.uuid.parentmodification="00000000-0000-0000-0000-000000000000" ddb.comment=""
To make the disk image working with Hyper-V, comment out (add # char at the beginning of each line) or remove those lines and save changes. Next, write changed descriptor back into the disk image file using dfsi tool:
dsfi.exe '.\Cassandra Training VM.vmdk' 512 1024 desc.txt
Step 3: Converting to Hyper-V format
With metada fixed, the image finally can be converted to Hyper-V format. To do so, Microsoft Virtual Machine Converter can be used. The package can be downloaded here. After installing, it can be accessed from the PowerShell console, but only after importing it:
Import-Module “C:\Program Files\Microsoft Virtual Machine Converter\MvmcCmdlet.psd1”
Now, the MVMC can be used to convert VMDK image into VHDX one:
ConvertTo-MvmcVirtualHardDisk -SourceLiteralPath '.\Cassandra Training VM.vmdk' -DestinationLiteralPath '.\Cassandra Training Hyper-V\'
After few moments (depending on the computer speed, disk read/write speed and image file size) a VHDX file will be created inside DestinationLiteralPath directory. If the descriptor have been edited correctly, no error message should pop up and the VHDX file should be created.
The result file can be used to create a Hyper-V virtual machine. This task is pretty easy and straightforward: create a Hyper-V virtual machine, but use existing disk image instead of creating a new one. After booting it up, the installed OS should run – no need to reinstall it.