How to Convert VMware VMs to Hyper-V

For one reason or another, you might need to convert a VMware VM to a Hyper-V VM. Perhaps you have a multi-hypervisor environment, or you need to perform testing, or you want a more rational licensing model for some software etc. As these two platforms have some key differences, understanding the VM conversion process is important. Today’s blog post explains some of the most affordable methods and tools for converting VMware VMs into Hyper-V VMs.

NAKIVO for VMware vSphere Backup

NAKIVO for VMware vSphere Backup

Complete data protection for VMware vSphere VMs and instant recovery options. Secure backup targets onsite, offsite and in the cloud. Anti-ransomware features.

Overview of Conversion Methods

The following are the best-known conversion methods provided by Microsoft:

  • Using Microsoft Virtual Machine Converter (MVMC). MVMC is a free standalone tool with a GUI (graphical user interface) that can convert virtual machines. (The tool can also convert a physical machine to a virtual machine.) VMs can be moved either to Hyper-V or Azure. This method is suitable for conversion of VMware ESXi VMs to a Hyper-V format VMs.
  • Converting VMDK to VHD and attaching a converted virtual disk to a new Hyper-V VM with PowerShell. This method can be used when you have the virtual disk files available, but not all the VM files (such as VMX configuration files). You can use this method to convert both VMware Workstation VMs and VMware ESXi VMs.
  • Converting VMs using SCVMM (System Center Virtual Machine Manager). SCVMM is a commercial software solution that enables centralized management for Hyper-V and VMware environments including VMs, hosts, and clusters. This tool includes VM conversion features.

Preparing a VM for Migration

There are certain steps to be taken before converting a VMware VM to Hyper-V format in order to prevent errors and make the migration process go faster:

  • Remove unnecessary virtual devices and eject the virtual CD to prevent possible disruptions. Devices such as virtual floppy drives and COM or LPT controllers can be removed for the purpose of improved compatibility. You can add these devices later if you are creating a Generation-1 Hyper-V VM. (Be aware that MVMC 3 provides no support for Hyper-V Generation 2 VMs.)
  • Clean up the virtual hard disks. Delete temporary files and other unnecessary files that consume space on the virtual disks of your VM. Remove unused programs and components. This approach allows you to save disk space and time if your destination virtual disk is dynamically expanded (thin provisioned).
  • Remove/consolidate all VM snapshots. The probability of errors during VM conversion can be reduced if your VM doesn’t contain snapshots.
  • Uninstall VMware Tools before online conversion (online only) to provide a clean way to migrate VMware-based virtual machines to Hyper-V. VMware Tools suit is not needed in a Hyper-V VM. Hyper-V provides Integration Services utilities suite, designed to enhance the performance of a virtual machine’s guest operating system.

Note: MVMC takes a snapshot of the VM that is being converted before you uninstall VMware Tools, and then shuts down the source machine to preserve state during conversion. The virtual machine is restored to its previous state after the source disks that are attached to the virtual machine are successfully copied to the machine where the conversion process is run. At that point, the source machine in VMware can be turned on, if required.

MVMC does not uninstall VMware Tools in an offline conversion. Instead, it disables VMware services, drivers, and programs only for Windows Server guest operating systems. For file conversions with Linux guest operating systems, VMware Tools are not disabled or uninstalled. It is highly recommended that you manually uninstall VMware Tools when you convert an offline virtual machine.

Converting with Microsoft Virtual Machine Converter

Let’s consider converting of a VMware-based VM to a Hyper-V VM using MVMC, as in the following example. The input parameters are as follows: a VM (version 7) is running on ESXi 6.5. The VM has one virtual disk, with no snapshots. VMware Tools suite is not installed.

First, download the converter from the Microsoft’s site. The current version of MVMC is version 3.1. There are two files available for download – an executable installer .msi file and a .doc file with a description of the Windows PowerShell cmdlets that get installed on your system together with the converter. The installation process is straightforward: run the installer, accept the license agreement, select the installation directory, and click Install in the setup wizard.

Once the installation process is complete, run the converter. Click Start > Microsoft Virtual Machine Converter to run the converter. On the Before You Begin screen, you can read a short description; tick the Do not show this page again checkbox if you don’t want to see this screen each time you run the converter. Click Next to proceed.

Machine Type. Select the type of the source machine to be converted. In this case, select Virtual machine conversion. Click Next.

Selecting virtual machine conversion in the MVMC wizard.

Select a migration destination. There are two options available at this stage: migration to Microsoft Azure cloud and migration to Hyper-V. This blog post covers conversion of a VMware VM to a Hyper-V VM, thus the Migrate to Hyper-V option should be selected in this case. Click Next.

Selecting Hyper-V as the migration destination.

Select a destination Hyper-V host. In this example, the Hyper-V server is running on a local host (the converter and the Hyper-V server are installed on the same machine). MVMC can also save a converted VM to an off-site destination host over the network. Make sure that your firewalls are configured accordingly if your converter and Hyper-V host are running on different machines. Remote access through Windows Management Instrumentation must be enabled. Select the name or IP address of your destination host, select the credentials of a user who has sufficient access privilege to connect to a Hyper-V host (the local administrator of the destination Hyper-V host and the domain administrator have such access privilege). Then click Next to proceed.

Selecting a Hyper-V host as the destination for the virtual machine.

Set the disk options. Specify a network path to store the converted virtual hard disks. For the purpose of this walkthrough, the VM is being converted and transferred to a Hyper-V server installed on the same machine that is running the converter. Thus, the following network path is applied:

\\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

Choose the type of virtual disk to be used after conversion. The virtual disk can be of two types: a fixed size disk (the analog of a thick-provisioned disk) or a dynamically expanding disk (the analog of a thin-provisioned disk). In this walkthrough, a dynamically expanding disk is chosen for the purpose of saving storage space.

Choose the format of the virtual hard disk: .vhdx is a newer and a more progressive file format that is used by both Gen1 and Gen2 VMs. .vhdx is chosen for the purposes of this walkthrough. Click Next to continue.

Configuring the virtual disk options for the destination Hyper-V based VM.

Specify the source details for connection to a vCenter server or ESXi server. In this example, a VM running on an ESXi server must be converted. Hence, the IP address, login, and password for the ESXi server should be entered at this step. Click Next to proceed.

Specifying the details for connection to an ESXi server.

Now, select the virtual machine for conversion from the ESXi server you have chosen. In the current example, a lightweight Windows VM running on an ESXi host is being converted. After selecting the VM, click Next.

Selecting a virtual machine to convert.

Virtual machine connection. If VMware Tools are installed on a Linux virtual machine, you must provide the username and password of the root account on the source VM to enable the converter to uninstall VMware Tools. In this example, a Windows machine without VMware Tools is used – hence, these fields are inactive. Define the final state of the source machine and the final state of the destination machine (On or Off). Click Next.

Connection options for the VM.

Define the workspace. The workspace is a temporary folder that is used to store temporary files during the conversion process. For better performance, this folder should be located on the machine where the converter is installed. Enter the path or click the Browse button and select the appropriate folder. Then click Next.

Selecting a temporary folder for the workspace.

Check the summary. Review the configuration details you have specified. If the warnings are not critical, you can proceed; these do not prevent conversion. Click Finish to start the virtual machine conversion process.

Checking the summary in Microsoft Virtual Machine Converter.

Wait for the VM conversion to complete. The process can be time-consuming, depending on the size of the virtual disks of the source VM as well as network speed. If conversion is successful, click Close to exit the virtual machine converter.

The virtual machine conversion was successful.

You can now edit the VM settings. Right-click the VM and select Settings from the context menu. The VM is stored in the directory you specified earlier. Remove the network adapter and add a legacy network adapter for older guest operating systems to enable networking. Then select the appropriate virtual switch or create a new one for VM connection to the network.

Editing the virtual machine settings with Hyper-V Manager.

After configuring the VM settings, start the VM and configure the guest OS. Wait until the OS recognizes new virtual devices. Don’t forget to install Hyper-V Integration Services for better performance and user experience. For manual installation of Integration Services, insert the vmguest.iso image in the virtual DVD drive of the VM and run the installer. Once installation is complete, reboot the VM and eject the virtual ISO disc.

Running a converted VM and installing Hyper-V Integration Services.

Converting VMDK to VHD Using PowerShell

In the previous example, converting a VM running on an ESXi host was explained and the Microsoft Virtual Machine Converter GUI was used. Let’s now consider a different use case for VM conversion. If you have only VMware VM virtual disks, or if you have a VM for VMware Workstation (not for ESXi), the MVMC and its GUI cannot be used. Recall that when you install the MVMC, some useful PowerShell cmdlets are also provided. In the following examples, you can learn how to convert a VMDK virtual disk to a Hyper-V format disk using the command line interface (CLI) and how to run a VM using that virtual disk on Hyper-V.

Converting VMware Workstation based Virtual Disks

Add the converter module to the current PowerShell session. The module is located in the directory where Microsoft Virtual Machine Converter is installed. In the current example, the default location is used for the converter. Type the following command in PowerShell:

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\

Importing a module for conversion to PowerShell.

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

You can see the VM files here. Make a note of the name of the VMDK file, as it is needed for further operations. In the current example, a Linux virtual machine with one virtual disk is used. Importantly, the VM has no snapshots and VMware Tools is not installed (see the screenshot below).

Viewing the files of a VM with the VMware Workstation format.

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 <path> is the path to a VMware virtual disk that should be converted.

DestinationLiteralPath <path> is the path to a directory where the virtual disk of the Hyper-V format should be saved.

VhdType <type> defines the type of the virtual disk – either dynamically expanding or fixed.

VhdFormat defines the format of the Hyper-V virtual disk (VHD or VHDX).

Wait until the conversion process is finished. A progress bar indicates the current state.

A VMDK virtual disk is being converted to VHD format.

When the virtual disk is successfully converted from VMDK to VHD, the following should be displayed on the screen:

A virtual disk has been converted successfully from VMDK to VHD.

Create a new VM and use the VHD disk created from the conversion. For this part, refer to the blog post that explains how to create a new virtual machine in Hyper-V. The key point is to connect the virtual disk. At the appropriate stage of the New Virtual Machine Wizard, select Use an existing virtual hard disk and specify the location of your newly created VHD file.

Using an existing virtual disk (created through conversion) to create a new Hyper-V VM.

After finishing configuring a VM, run the virtual machine on your Hyper-V host.

Running a VM that uses a virtual disk converted from VMDK format for VMware Workstation to VHD format for Hyper-V.

You can also use this method for converting VMs with multiple virtual disks. Each virtual disk must be attached to the VM after conversion in this case.

Converting Virtual Disks of VMware ESXi Format

First, you need to copy virtual disk files from the ESXi host’s datastore to the machine with Microsoft Virtual Machine Converter installed. In this case, one VMware virtual disk consists of two files – diskname.vmdk and diskname-flat.vmdk. A vmdk file is a descriptor that contains information about the virtual disk configuration and points to a -flat.vmdk file. The virtual disk data itself is stored in the -flat.vmdk file. The size of a vmdk file is a few kilobytes, while the size of -flat.vmdk file is much larger. You can copy VMware virtual disk files from an ESXi host using the VMware vSphere client or any SCP (secure copy protocol) client.

Copying files using VMware vSphere client

This method can be used if you manage your ESXi hosts with vCenter Server. Log into your vCenter with the vSphere client (enter the IP address of your vCenter Server in the address bar of your web browser). Go to the Storage tab, select the datastore with the files of your VM, select the VM directory, and select the virtual disk that should be converted. Once you have selected the disk, click Download and save a zip archive with the vmdk and -flat.vmdk files to the machine with MVMC installed. Pay attention to the size of the virtual disk file. The VM used in this example (Win-test2, which was converted earlier with MVMC through the GUI) has an 8GB thin-provisioned virtual disk that consumes about 1.64 GB on the VMFS datastore. (You can read more about thick and thin provisioning in a separate blog post.)

Note: You can see only one VMDK file in the web interface of the VMware vSphere client and the VMware Host client. Don’t be alarmed; there are two files (vmdk and -flat.vmdk) on the datastore. You can confirm that both of these files are present on the datastore if you log into your ESXi host using the SSH client and list the files in the directory of your VM on the datastore.

Downloading VMware virtual disk files from a datastore with VMware vSphere client.

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

A zip archive with virtual disk files downloaded from the VMware ESXi server.

After extracting 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 the dynamically expanding virtual disk for Hyper-V.

Virtual disk and descriptor files.

Copying files using WinSCP client

WinSCP is a free application that uses SCP, SFTP (SSH Secure Shell File Transfer Protocol), FTP, and WebDAV protocols for data transfer. SFTP is preferred, if possible. You can download WinSCP from the official web site.

Run WinSCP and log into your ESXi server by entering the IP address, port number, and root credentials.

Connecting to the ESXi server with WinSCP.

WinSCP has an intuitive GUI with two main panels where you can access files and directories. In the left panel, navigate to the directory where your VMDK files are stored before conversion. In the right panel, go to the VM directory on your ESXi datastore. In the current example, the path to that directory is /vmfs/volumes/SSD2/Win-test2. Select the two virtual disk files needed (vmdk and -flat.vmdk) and copy them to your local directory. Simply drag and drop the files.

Copying virtual disk files from an ESXi server to a local machine with MVMC installed.

Converting a VMDK virtual disk copied from ESXi

The VMware virtual disk files copied from ESXi are now located on the Windows machine with Microsoft Virtual Machine Converter. Converting the virtual disks of an ESXi VM is similar to converting the virtual disks of a VMware Workstation VM. The main difference is that you now have two files (vmdk and -flat.vmdk) rather than a single file.

Open PowerShell and make sure that the appropriate converter module is imported. If it isn’t, type the following command:

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.

Converting a VMDK virtual disk of ESXi format to a VHD format for use in Hyper-V.

When the conversion process is successfully completed, create a new Hyper-V VM and use the existing virtual disk option to attach the VHD virtual disk that is ready after conversion (as explained above in this article). You can then edit VM configuration and run the virtual machine.

Issues That May Occur

There are various errors that could prevent the conversion process from working. Let’s consider what issues can occur and how to resolve them.

The entry 1 is not a supported disk database entry for the descriptor.

If you see this error when converting a virtual disk from VMDK format to VHD format, it means that Microsoft Virtual Machine Converter cannot recognize some of the disk database entries. The number of the entry can vary – e.g. you might see 2, 3, 4, etc., instead of 1. In order to fix this issue, edit the virtual disk descriptor.

An error is thrown when conversion of the VM disk is attempted: the entry 1 is not a supported disk database entry for the descriptor.

Fixing the issue for a virtual disk of VMware Workstation format.

A VMDK virtual disk of VMware Workstation format has an embedded descriptor (the descriptor is integrated into the VMDK file with the disk data). You need to download a free utility kit that can extract the virtual disk descriptor to a TXT file. You can then edit the descriptor and import the edited descriptor from the TXT file back into the VMDK file. The name of the utility kit is dsfok tools (DS File Ops Kit). You can download the dsfok kit here.

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;

1024 bytes is the size of the exported data;

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

Extracting a virtual disk descriptor from a VMDK file of the VMware Workstation format.

The descriptor is now extracted to the descriptor-win7x64.TXT file in the directory with dsfok tools.

The virtual disk descriptor has been extracted to a TXT file.

Edit the .txt file of the descriptor with a text editor (choose one that correctly recognizes the layout, such as Notepad++). 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 is not processed when reading the descriptor’s configuration. Save the file when editing is finished.

Editing a virtual disk descriptor.

You now need to import the edited descriptor back 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

Importing the edited descriptor to a VMDK virtual disk file of the VMware Workstation format.

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 is started.

Converting VMDK to VHD after importing the edited descriptor.

Once the virtual disk is converted to VHD format, you can create a new Hyper-V VM and attach the virtual disk (this process was explained earlier in this blog post). You can then run the VM on Hyper-V. However, another issue may occur. If your virtual machine doesn’t load and you see a blinking cursor on black background, you need to fix a boot sector of the virtual disk.

Note: Windows 7 is installed on the virtual disk shown in this walkthrough example.

A started Hyper-V VM cannot boot.

Insert the ISO installation image of your Windows distribution and boot from the virtual CD/DVD drive. The built-in repair tools of the installation disc can be used to fix the boot sector, including the master boot record (MBR).

Mounting the ISO image with Windows installer to a virtual CD/DVD drive of the Hyper-V VM.

Once the Windows installer is loaded, click Repair your computer.

Entering the “Repair your computer” mode.

Select your operating system on the appropriate virtual disk and click Next.

Selecting the operating system in system recovery options.

Run the command prompt and execute the following commands:

bootrec /fixmbr

bootrec /fixboot

Restart the virtual machine and boot from the virtual hard disk.

Fixing MBR and a boot sector of the virtual disk.

Your VM should now boot successfully.

A Hyper-V VM is booting after fixing a boot sector and MBR.

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.

An error is thrown when attempting to convert the VM: the entry 4 is not a supported disk database entry for the descriptor.

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.

Viewing the VM files on the datastore of the ESXi server.

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.

Editing the virtual disk descriptor file of a VM on an ESXi server.

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

vmkfstools -e Win7PMM.vmdk

Checking the virtual disk consistency.

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.

Virtual disks are being converted in the framework of VM conversion.

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.

An error is thrown during attempted VM conversion: Receiving response from VMware failed after multiple attempts.

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.
: A task may only be disposed if it is in a completion state (RanToCompletion, Faulted or Canceled)

Conclusion

Microsoft Virtual Machine Converter (MVMC) is one of the most affordable tools for this purpose. It includes GUI tools and command line tools for PowerShell. With the MVMC GUI, you can convert entire VMs running on ESXi hosts. PowerShell cmdlets allow you to convert individual VMware virtual disks of ESXi format and Workstation format. You can use the recommendations and walkthroughs provided in this blog post to resolve some of the issues that may occur during VM conversion.

1 Year of Free Data Protection: NAKIVO Backup & Replication

1 Year of Free Data Protection: NAKIVO Backup & Replication

Deploy in 2 minutes and protect virtual, cloud, physical and SaaS data. Backup, replication, instant recovery options.

People also read