How to convert VMware virtual machines to Hyper-V

How to convert VMware virtual machines to Hyper-V

Occasionally, you will need to convert a VMware VM to a Hyper-V VM. Maybe you have a multi-hypervisor environment, or maybe you need to perform some testing, or maybe you need a more rational licensing model for some software, etc. Understanding the VM conversion process is important due to the key differences between these two platforms. This post discusses some of the most affordable methods and tools for converting VMware VMs into Hyper-V VMs.

Whatever platform you use, you must back up your virtual machines to prevent data loss and downtime. Through the advanced Cross-Platform Recovery feature, NAKIVO Backup & Replication can not only back up VMware VMs and Hyper-V VMs, but also allow you to run VMs recovered from VMware backups on Hyper-V and vice versa. In some of our other blog posts, you'll learn how to export VMware VMs to Hyper-V from backups and export Hyper-V VMs to VMware ESXi hosts from backups using this functionality.

Download NAKIVO Backup & Replication now for a free trial. At a starting price of $149 per socket, our product is flexible, fast, and reliable.

Conversion Methods Overview

Microsoft provides the following conversion methods:

  1. MVMC (Microsoft Virtual Machine Converter). The program has a graphical user interface (GUI) and can convert virtual machines. As well as converting physical machines to virtual machines, the tool can migrate VMs to Hyper-V or Azure. You can use this method to convert VMware ESXi virtual machines to Hyper-V virtual machines.
  2. PowerShell can convert VMDK to VHD and attach the converted virtual disk to a new Hyper-V VM. This method can be used when you have the virtual disk files, but not all the VM files (such as the VMX configuration files). It is possible to convert both VMware Workstation VMs and VMware ESXi VMs using this method.
  3. Using SCVMM (System Center Virtual Machine Manager) to convert VMs. SCVMM can centrally manage Hyper-V and VMware environments, including VMs, hosts, and clusters. VMs can also be converted using this tool.

Preparing a VM for Migration

For the migration process to run smoothly, the following steps must be followed before converting a VMware VM to Hyper-V format:

  • Remove unnecessary virtual devices and eject the virtual CD to prevent disruptions. Compatibility may be improved by removing virtual floppy drives, COM, and LPT controllers. When creating a Generation-1 Hyper-V virtual machine, you can add these devices later. (VMs running on Hyper-V Generation 2 are not supported by MVMC 3.)
  • Ensure that the virtual hard disks are clean. You can free up virtual disk space by deleting temporary files and other unnecessary files. You can also uninstall any programs that you do not use. This approach can be used if your destination virtual disk is dynamically expanded (thin provisioned).
  • All VM snapshots should be consolidated/removed. When your VM does not contain snapshots, conversion errors can be reduced.
  • Uninstall VMware Tools before converting a VMware-based virtual machine to Hyper-V. VMware Tools are not required if you are running Hyper-V. Integration Services, which are included in Hyper-V, are designed to enhance virtual machine performance.

NOTE

MVMC takes a snapshot of the VM before uninstalling VMware Tools to preserve state during conversion. Following the copying of the virtual machine's source disks to the machine that performs the conversion process, the virtual machine is restored to its original state. VMware can then turn on the source machine if necessary.

VMware Tools are not uninstalled by MVMC during an offline conversion. As a result, VMware services, drivers, and programs are only disabled for Windows Server guests. During file conversion with Linux guest operating systems, VMware Tools are not disabled or uninstalled. VMware Tools should be manually uninstalled when converting an offline virtual machine.

"Data Protection with NAKIVO Backup & Replication

NAKIVO Backup & Replication delivers high-end data protection for SMBs and enterprises with multiple backup, replication and recovery features, including VMware Backup, Hyper-V Backup, Office 365 Backup and more."

Using Microsoft Virtual Machine Converter to convert virtual machines

MVMC shows how to convert a VMware-based virtual machine into a Hyper-V virtual machine. The input parameters are: a VM (version 7) is running on ESXi 6.5. There is only one virtual disk in the VM. No VMware Tools suite is installed.

Download the converter from Microsoft's website first. MVMC version 3.1 is available for download. You can download two files: a .msi installer and a .doc with a description of the Windows PowerShell cmdlets that get installed along with the converter. Running the setup wizard, accepting the license agreement, selecting the installation directory, and clicking Install completes the installation process.

Run the converter once the installation has been completed. Go to Start > Microsoft Virtual Machine Converter to run the converter. There is a short description on the Before You Begin screen; if you don't want to see this screen every time you run the converter, check the Do not show this page again checkbox. Next, click Continue.

The type of machine. Choose the type of the source machine. In this case, choose Virtual machine conversion. Press Next.


Choose a migration destination. At this stage, two options are available: migration to Microsoft Azure cloud and migration to Hyper-V. As this blog post covers converting a VMware VM to a Hyper-V VM, the Migrate to Hyper-V option should be selected. Press Next.


Select a Hyper-V host as the destination. The Hyper-V server runs on a local host (the converter and Hyper-V server are on the same machine). A converted VM can also be saved to a network destination host. If your converter and Hyper-V host are running on different machines, make sure that your firewalls are properly configured. Remote access via Windows Management Instrumentation must be enabled. Enter the name or IP address of your destination host, then enter the credentials of a user who has the necessary access privileges to connect to a Hyper-V host (the local administrator of the destination Hyper-V host, as well as the domain administrator). Click Next to continue.


Disk options can be set. To store the converted virtual hard disks, specify a network path. This walkthrough assumes that the VM is being converted and transferred to a Hyper-V server installed on the same machine as the converter. To do this, follow these steps:

"\\localhost\c$\Virtual\Hyper-V\converted"

It is recommended to avoid using the system disk (usually C:) for storing VMs in production environments. For example, if your Hyper-V host is a remote machine, your chosen path might look like: \\10.10.10.12\d$\Virtual\Hyper-V

Select the type of virtual disk to be used after conversion. There are two types of virtual disks: a fixed size disk (the equivalent of a thick-provisioned disk) and a dynamically expanding disk (the equivalent of a thin-provisioned disk). The purpose of this walkthrough is to save storage space by using a dynamically expanding disk.

Choosing the virtual hard disk format: .vhdx is a more modern and progressive format that is used by both Gen1 and Gen2 virtual machines. This walkthrough uses .vhdx files. Continue by clicking Next.


Specify the details for connecting to a vCenter server or an ESXi server. An ESXi server running a VM must be converted in this example. In this step, the IP address, login, and password for the ESXi server must be entered. Click Next to continue.


Choose the virtual machine you wish to convert from the ESXi server you selected. The current example involves converting a lightweight Windows VM running on an ESXi host. Click Next to select the VM.


Connecting a virtual machine. For the converter to be able to uninstall VMware Tools from a Linux virtual machine, you must provide the username and password of the root account on the source VM. This example uses a Windows machine without VMware Tools - therefore, these fields are inactive. Establish the final state of the source and destination machines (On or Off). Press Next.


Defining the workspace is important. During the conversion process, temporary files are stored in the workspace. This folder should be located on the machine where the converter is installed for optimal performance. Select the folder or enter the path. Select Next.


Review the summary. Check the configuration details. These warnings do not prevent conversion if they are not critical. Click Finish to begin the virtual machine conversion.


Wait until the VM conversion is complete. Depending on the size and speed of the virtual disks of the source VM, the process can be time-consuming. Once the conversion is complete, click Close to exit the virtual machine converter.


VM settings can now be edited. Select Settings from the context menu when right-clicking the VM. A folder containing the VM is created. For older guest operating systems, remove the network adapter and add a legacy network adapter. To connect the VM to the network, select the appropriate virtual switch or create a new one.


Start the VM and configure the guest OS after configuring the VM settings. Wait for the OS to recognize the virtual devices. Installation of Hyper-V Integration Services will improve performance and user experience. Install Integration Services manually by inserting the vmguest.iso image into the virtual DVD drive of the VM and running the installer. When the installation is complete, reboot the VM and eject the virtual ISO disc.


Using PowerShell to convert VMDK to VHD

In the previous example, the Microsoft Virtual Machine Converter GUI was used to convert a VM running on an ESXi host. Let's now consider another use case for VM conversion. You cannot use MVMC and its GUI if you only have VMware VM virtual disks, or if you only have a VM for VMware Workstation (not for ESXi). You will also find some useful PowerShell cmdlets included when you install the MVMC. The following examples demonstrate how to convert a VMDK virtual disk into a Hyper-V format disk using the command line interface (CLI) and how to run a Hyper-V VM using the virtual disk.

Converting VMware Workstation based Virtual Disks

The converter module will be added to the current PowerShell session. It can be found in the directory where Microsoft Virtual Machine Converter is installed. The default location for the converter will be used in this example. Use the following PowerShell commands:

"Import-Module “C:\Program Files\Microsoft Virtual Machine Converter\MvmcCmdlet.psd1”

If your converter is installed in another directory, type the path of your directory instead of C:\Program Files\Microsoft Virtual Machine Converter\


Go to the directory of your VM and list the files of that directory. In the current example the VM is located in C:\virtual\StorageLinux

cd C:\virtual\StorageLinux

dir

The VM files can be viewed here. Note the name of the VMDK file, as it will be required in the following steps. We use a Linux virtual machine with one virtual disk in the current example. In addition, the VM does not have snapshots and VMware Tools is not installed (see below screenshot).


Run the converter in PowerShell by using the following command and arguments:

"ConvertTo-MvmcVirtualHardDisk -SourceLiteralPath "C:\Virtual\StorageLinux\StorageLinux 3.x kernel 64-bit.vmdk" -DestinationLiteralPath "C:\Virtual\Hyper-V\converted\01" -VhdType DynamicHardDisk -VhdFormat Vhd"

Where:

SourceLiteralPath specifies the path to a VMware virtual disk that should be converted.

-DestinationLiteralPath specifies the path to the directory where the virtual disk of the Hyper-V format should be stored.

-VhdType specifies the type of virtual disk - either dynamically expanding or fixed.

The VHDFormat parameter specifies the format of the Hyper-V virtual disk (VHD or VHDX).

Wait until the conversion process is complete. You will see a progress bar.


The following should be displayed on the screen upon successful conversion of the virtual disk from VMDK to VHD:


Use the converted VHD disk to create a new VM. Refer to the blog post that explains how to create a new virtual machine in Hyper-V for this part. Connecting the virtual disk is the key. Choose Use an existing virtual hard disk from the New Virtual Machine Wizard and specify the location of your newly created VHD file.


Run the virtual machine on your Hyper-V host after configuring a VM.


This method can also be used to convert VMs with multiple virtual disks. The virtual disks must be attached to the VM after conversion in this case.

Converting VMware ESXi virtual disks

ESXi host's datastore must be copied to the machine with Microsoft Virtual Machine Converter installed first. VMware virtual disks include two files - diskname.vmdk and diskname-flat.vmdk. Vmdk files contain information about virtual disk configuration and point to a -flat.vmdk file. -flat.vmdk contains the virtual disk data itself. vmdk files are only a few kilobytes in size, while -flat.vmdk files are much larger. With the VMware vSphere client or any SCP (secure copy protocol) client, you can copy VMware virtual disk files from an ESXi host.

Copying files using VMware vSphere client

If you manage your ESXi hosts with vCenter Server, you can use this method. Log in with the vSphere client (enter the IP address of your vCenter Server in the address bar of your web browser). Click the Storage tab, choose the datastore containing your VM's files, select the VM directory, and select the virtual disk you wish to convert. Click Download and save the vmdk and -flat.vmdk files to the machine with MVMC installed after selecting the disk. Note the virtual disk's size. In this example, Win-test2 (which was converted previously with MVMC through the GUI) uses an 8GB thin-provisioned virtual disk that consumes about 1.64 GB on the VMFS datastore. (You can find more information about thick and thin provisioning in a separate blog post.)


Note: There is only one VMDK file visible on the web interfaces of both the VMware Host client and VMware vSphere client. There are two files on the datastore (vmdk and -flat.vmdk). Logging into your ESXi host using the SSH client and listing the files within the directory of your VM on the datastore will enable you to verify that both of these files are present on the datastore.



Once the zip archive is downloaded, extract the virtual disk files.


When you extract the files, you can see that the -flat.vmdk virtual disk file consumes 8 GB of disk space (the maximum provisioned size of the current virtual disk), and not 1.64 GB. Later, you can convert this virtual disk to a dynamically expanding virtual disk for Hyper-V.


Copying files using WinSCP client

For data transfer, WinSCP supports SCP, SFTP (SSH Secure Shell File Transfer Protocol), FTP, and WebDAV protocols. If possible, we recommend using SFTP. Here is a link to download WinSCP.

Log in to your ESXi server using WinSCP by entering the IP address, port number, and root credentials.


WinSCP's intuitive GUI allows users to access files and directories using two main panels. Navigate to your VMDK files' directory in the left panel before converting. On the right panel of the ESXi datastore, select the VM directory. The path to that directory in this example is /vmfs/volumes/SSD2/Win-test2. Choose two virtual disk files (vmdk and -flat.vmdk) and copy them to your local directory. The process is as simple as dragging and dropping.

The conversion of a VMDK virtual disk copied from ESXi

VMware virtual disk files were copied from ESXi to Windows using Microsoft Virtual Machine Converter. The main difference is that instead of one file (vmdk), you now have two files (vmdk and -flat.vmdk).

Import the appropriate converter module in PowerShell. If it's not already installed, type:

"Import-Module “C:\Program Files\Microsoft Virtual Machine Converter\MvmcCmdlet.psd1”

Now enter the following command to convert a virtual disk.

"ConvertTo-MvmcVirtualHardDisk -SourceLiteralPath "C:\Virtual\Hyper-V\converted\FromESXi\Win-test2.vmdk" -DestinationLiteralPath "C:\Virtual\Hyper-V\converted\Win-test2PS" -VhdType DynamicHardDisk -VhdFormat Vhd"

Define the path to the vmdk file (not to a -flat.vmdk file) for the -SourceLiteralPath argument.


Once the conversion is complete, you can then modify the virtual machine's configuration and start it. After the conversion is complete, create a new Hyper-V virtual machine and attach the VHD virtual disk that has been prepared (as explained above).

Troubleshooting

We will discuss a few issues that may prevent the conversion process from working.

The first entry in the descriptor is not supported.

When Microsoft Virtual Machine Converter attempts to convert a virtual disk from VMDK format to VHD format, this error occurs. The entry number may be 2, 3, or 4, instead of 1. This can be resolved by editing the virtual disk descriptor.


Using the VMware Workstation format to fix the issue.

By using a free utility kit (DS File Ops Kit), you can edit the virtual disk descriptor published as a VMDK file and import the edited descriptor into the virtual disk file.

Click here to get it.

Extract the files from the archive, for example to C:\Virtual\_tools\dsfok

"Run CMD (Press Win+R, type cmd and press Enter). Go to the directory with dsfok tools:

cd C:\Virtual\_tools\dsfok

Run dsfo.exe with the following parameters:

dsfo.exe “C:\virtual\win7x64\win7x64.vmdk” 512 1024 descriptor-win7x64.txt"

where:

"512 bytes is the offset;

the exported data is 1024 bytes;

Descriptor-win7x64.txt is the name of the file to which the descriptor is exported."


It has now been extracted to the file descriptor-win7x64.TXT in the directory with dsfok tools.


Text editors that correctly recognize the layout, like Notepad++, can be used to edit the descriptor. Find the part of the descriptor with ddb.toolsInstallType = "1" and comment that bit out by replacing the first “d” character with a “#” character. The format of the descriptor is not violated in this case and you have #db.toolsInstallType = "1" string as a result. The commented-out string will not be processed when reading the descriptor's configuration. Save the file after editing.


The edited descriptor needs to be imported again into the VMDK file of VMware Workstation format. In order to do this, run dsfi.exe with the following parameters:

"dsfi.exe "C:\virtual\win7x64\win7x64.vmdk" 512 1024 descriptor-win7x64.txt"


Now you can convert the VMDK virtual disk to VHD format by running the following command in PowerShell:

"ConvertTo-MvmcVirtualHardDisk -SourceLiteralPath "C:\Virtual\win7x64\Win7x64.vmdk" -DestinationLiteralPath "C:\Virtual\Hyper-V\converted\01" -VhdType DynamicHardDisk -VhdFormat Vhd"

The error is no longer thrown, and the conversion process begins.


The virtual disk can be attached to a Hyper-V VM and run. You can also see a blinking cursor on a black background if the virtual machine fails to load. To fix it, fix the boot sector on the virtual disk.


This walkthrough example shows Windows 7 installed on a virtual disk.

Use the built-in repair tools of the installation disc to repair the boot sector, including the master boot record (MBR), by inserting the ISO installation image of your Windows distribution.


Once the Windows installer loads, click Repair your computer.


Then select your operating system and click Next.


Run the following commands at the command prompt:

bootrec /fixmbr

bootrec /fixboot

Boot from the virtual hard disk and restart the virtual machine.


You should now be able to boot the virtual machine.


Fixing the issue for a virtual disk of VMware ESXi format

Let’s explore how to fix a similar issue when you export a virtual machine from VMware ESXi to Hyper-V. A Linux VM is used in this example (the VM name is NAKIVO-clone) and Microsoft Virtual Machine Converter returns the following error: The entry 4 is not a supported disk database entry for the descriptor. The method for fixing this issue is similar to the one explained in the previous example; you need to edit the descriptor of each virtual disk of the VM.


Recall that a virtual disk of a VM running on VMware Workstation has an embedded descriptor (the descriptor is integrated into the VMDK file). By contrast, if a VM runs on an ESXi host, then the virtual disk data and descriptor are stored in two different files. Enable SSH access on the ESXi host where the VM you want to convert is registered. Log into the ESXi console with an SSH client such as PuTTY.

Go to the directory where the VM files are stored. In this example, the VM files are located in /vmfs/volumes/SSD1/NAKIVO-clone. The name of the datastore is SSD1 in this case.

cd /vmfs/volumes/SSD1/NAKIVO-clone

Type ls -al to list the files in the VM directory. As you can see from the screenshot below, the VM has two virtual disks.


Edit the descriptor of the virtual disk using vi (the console text editor):

vi NAKIVO-clone.vmdk

Find the following string:

ddb.toolsInstallType = "4"

Edit the string by replacing the first “d” character with a “#” character. After editing the section, it should say: #db.toolsInstallType = "4"

Use the arrows to move your cursor. Press “a” to switch from navigation mode to editing mode for appending symbols. Once you have made the alteration, press Esc to exit the editing mode. Then type :wq to write the changes to the file and exit.


Check the virtual disk consistency after saving changes to the descriptor file:

"vmkfstools -e Win7PMM.vmdk"


Edit the descriptor of the second virtual disk in the same way. When the descriptors of all the VM’s virtual disks are edited, initiate VM conversion with MVMC once again. The virtual disks of your VM can now be converted without errors.


Receiving response from VMware failed after multiple attempts. See inner exception

This error can occur if an ESXi host is defined as a source in the GUI of MVMC. If you use vCenter Server to manage ESXi hosts including the current host, define the name or IP address and the credentials for the vCenter Server rather than the ESXi host in the Source section.


A task may only be disposed if it is in a completion state (RanToCompletion, Faulted or Canceled)


If you get this error when using Microsoft Virtual Machine Converter to convert a VM from ESXi to Hyper-V format, copy the virtual disk files (vmdk and -flat.vmdk) to the machine with the converter installed, convert the virtual disks in PowerShell, then create a new Hyper-V VM and attach the disks to that VM.

Conclusion

In this blog post, we will discuss how to convert VMware VMs to Hyper-V format. Microsoft Virtual Machine Converter (MVMC) is one of the most affordable tools available for this purpose. It includes GUI tools and PowerShell commands. You can convert entire VMs running on ESXi hosts with the MVMC GUI. VMware virtual disks in ESXi format and Workstation format can be converted using PowerShell cmdlets. You can use the recommendations and walkthroughs provided in this blog post to resolve some of the issues that may occur during VM conversion.