Using Disk2VHD for Hyper-V P2V (Physical to Virtual) Conversions

Using Disk2VHD for Hyper-V P2V (Physical to Virtual) Conversions

Bringing a physical operating environment into Hyper-V can be a challenging task, especially without a tool like Microsoft disk2vhd. It is recommended that you use some application-level migration rather than trying to convert a physical operating system installation directly. However, some systems do survive the transition well. With the  Sysinternal’s Disk2VHD, organizations have a freely available tool to convert physical hard disks to the VHD and VHDX formats supported by Microsoft Hyper-V.

What is Disk2VHD?

Sysinternals Disk2VHD is a software solution provided by Sysinternals. It reads the boot information, partition information, and data regions of a physical hard drive and produces a corresponding VHD or disk2vhd VHDX file. It is very important to understand that this is not a true physical-to-virtual conversion. The operating system is not prepared to run inside a virtual environment, nor is any cleanup work done on the source system to improve the odds of a successful migration.

Download the Hyper-V Sysinternals Disk2VHD Hyper-V P2V

Sysinternals offers this tool as a free download, allowing an easy way to download disk2vhd. Please read their overview and warnings. There is no actual “installation” of this product. Simply extract the “disk2vhd.exe” file from the ZIP archive and place it on the system whose drives you wish to convert. You can also extract the “Disk2vhd.chm” file; this is the software’s help manual.

Jeffery Hicks has also written a PowerShell script that will retrieve and update the entire Sysinternals catalog.

Pre-Flight Checks and Procedures

It’s a hard fact that physical to virtual conversions are fraught with peril. The older the operating system, the greater the risk. A few things that you should do to prepare:

  • Perform a complete backup to a safe location.
  • Verify that there aren’t any problems with the system. Check event logs, etc. Run CHKDSK.
  • Remove any unnecessary software and drivers, but do not make any changes to the system’s vital configuration that cannot be easily redone. If the P2V fails, you don’t want to be left with an unusable source system. RAID drivers are a common paint point but removing them will render your system unusable.
  • Optional: Remove the system from the domain. This will avoid post-conversion issues.
  • Stop as many services as possible, especially any that run databases. Disk2VHD essentially captures an application-consistent backup, but it will have superior results if all applications are closed when it runs. This also prevents anyone from using those services. Anything that happens to the system after the Disk2VHD process begins will be lost.

How to use Disk2VHD

Once you download disk2vhd, there are two ways to use the Disk2VHD tool for P2V in Hyper-V. The first is in interactive GUI mode. The second is via disk2vhd command-line, which is useful if you need to use scripting for such things as handling large batches.

Before starting, shut down all applications and stop any vital services especially if the machine to be converted runs any databases. I/O is paused for the conversion (if you choose the option for VSS) but many applications won’t know to flush active buffers.

Using Disk2VHD in GUI Mode

Copy the “disk2vhd.exe” file to the computer whose drive(s) is/are to be converted and double-click on it from that computer. You’ll be presented with a screen similar to the following:

Disk2Vhd Main Screen

Disk2Vhd Main Screen

That screenshot was taken from a Windows 2012 R2 computer; some older operating systems will not have the “System Reserved” partition. If the system that you’re creating a VHDX from has this partition, you’ll need to include it if you wish for the VHDX to be bootable.

You’ll first need to select a destination in the “VHD File Name” text box. The button at the end of that line with the triple dots serves as a browse button. If keeping the option for VSS snapshots, it’s perfectly acceptable to create the VHDX(s) on the same drive that you’re copying as long as there is enough room.

Unless you know that you’ll be using the generated file on Windows/Hyper-V Server 2008 R2 or earlier, check the box to Use Vhdx. It does not matter if the guest operating system is older than 2012.

Once you’re satisfied with all of your selections, click the “Create” button. The software will first indicate that it is creating the VSS snapshot. After that, it will begin the process of copying out the data. If you make any changes to the drive’s data after that, they will not be saved. You can continue to use the system during the copy process.

Disk2VHD command line examples

The primary purpose of using the command-line version would be if you need to script this. For instance, if you have purchased Software Assurance for all of your Windows 7 desktops and want to move them into a VDI environment, you could craft a specialized computer login script that relied on “Disk2vhd” to capture the physical Windows 7 systems in your organization.

The help file shows the usage syntax: disk2vhd [-h] <[drive: [drive:]…]|[*]> <vhdfile> 

There is one optional setting and two required ones.

Setting Required? Purpose
-h No If the drive to be converted is attached to a Windows XP or Windows Server 2003 system, this prepares its hardware abstraction layer
Drive: or * Yes You can enter drive letter designators separated by spaces OR you can use an asterisk to indicate all drives. You must use the asterisk for the “System Reserved” partition to be included.
vhdfile Yes Enter the full path and file name of the VHD[X] to be created. UNCs are acceptable.

Output

Both methods will result in the same type of output: one VHD file will be made for each disk in the source. If there is only one VHD to be created, it will be exactly the file name you specified. If there is more than one, each VHD will be the filename you specified with a hyphen and the disk number appended.

Sample drive layout:

Disk2VHD disk manager screenshot

With all drives checked, running the above system through Disk2VHD produces:

VHDs listed

Demo-0.VHD contains the System Reserved and C: volumes, Demo-1.VHD contains the D: volume, and Demo-2.VHD contains the E: and F: volumes.

Test the VHDX

On a system with Hyper-V 2012 or later installed, run the following, substituting in your actual path:

Test-VHD -Path C:LocalVMsVirtual Hard Disksdisk2vhded.vhdx

This testing isn’t overly comprehensive, but it can identify any immediate red flags that would prevent it from being usable with Hyper-V.

Create the Virtual Machine

All that the Disk2VHD Hyper-V P2V tool does is prepare the VHDX files. It does not create a virtual machine. You’ll need another tool for that. The following steps will demonstrate using Hyper-V Manager to create the VM using the VHDXs that were output by Disk2VHD in the steps above.

  1. Copy the created VHD files to a location that your Hyper-V host can access them. If you need some guidance on this, open Hyper-V Manager and ensure that the host you want to work with is selected. In the right pane, click on “Hyper-V Settings…” In the dialog box, click on “Virtual Hard Disks” in the “Server” section. The right pane of the dialog will show the folder that the host is currently set to access VHDs from. It isn’t required that you place them in that folder, but you can be certain that the Hyper-V host will be able to access VHDs there.
    copy VHD to Hyer-V host
  2. Once you have placed the files where you want them, go to the Actions pane at the right. Click New, then Virtual Machine to start the wizard.

    New VM: Start the Wizard

    New VM: Start the Wizard

  3. The first page of the New Virtual Machine Wizard is purely informational. Click Next when ready.
  4. The first data screen asks for the name of the virtual machine and the initial location. The name that you choose will be used as a label in all virtual machine tools, including Hyper-V Manager, Failover Cluster Manager, and PowerShell. The name of the guest operating system that you’ll eventually install will not be automatically set to this, and does not need to be the same.
    If you do not check the option to Store the virtual machine in a different location, then all of the virtual machine’s metadata (XML, BIN, VSV, and second-level paging files) will all be placed in the host’s default location. This path will be visible in the greyed out text box. Checking the box allows you to override this location. If it’s never held a virtual machine before, a subfolder named “Virtual Machines” will be created in the path that you specified. Whether that folder is new or existing, another subfolder will be created underneath it that will have the name of the automatically-generated GUID that represents the virtual machine. Security will automatically be configured for you.

    New VM: Name and Location

    New VM: Name and Location

  5. On the next screen (2012 and later), you’ll be asked to choose the Generation of the virtual machine. What you choose here will depend on the source physical machine. If the source ran in the traditional BIOS mode, you must choose Generation 1. If the source was operating in the newer UEFI mode, you must choose Generation 2.

    New VM: Generation

    New VM: Generation

  6. On the next screen, you set the preliminary memory settings for the virtual machine. You only have two options: the amount of Startup memory and whether or not you wish to Use Dynamic Memory for this virtual machine. If you do not wish to use Dynamic Memory, leave the box unchecked and set the startup memory to the amount of memory that you wish the virtual machine to have. If you do wish to use Dynamic Memory, you’ll have to configure the minimums and maximums later. They will be automatically set to 512 and 1TB, respectively.

    New VM: Memory Settings

    New VM: Memory Settings

  7. Next, you’ll need to determine how to connect the virtual network adapter. You can leave it at Not Connected, which means the virtual machine will begin its life without any network connectivity. Otherwise, you can connect it to a virtual switch right away. Be aware that you can’t set any advanced options such as the VLAN here. Whatever you choose, this adapter is always the newer synthetic adapter, which cannot be used to PXE boot a Generation 1 virtual machine. If you need that functionality, it is granted on a later screen.

    New VM: Network Connection

    New VM: Network Connection

  8. After networking, you’ll be asked to configure the first virtual hard disk for the virtual machine. The second option allows you to connect an existing virtual hard disk. Browse to the VHDX file that you created with Disk2VHD:

    VHDX Selection

    VHDX Selection

  9. The final screen is simply a confirmation and your last opportunity to go back and make any necessary changes.

    New VM Confirmation

    New VM Confirmation

  10. Once you click Finish, the wizard undertakes all of the options that you selected and creates the virtual machine. The wizard does not turn the virtual machine on, so you have an opportunity to make any desired modifications beforehand, such as to vCPU count or memory allocation.
  11. Start the VM in Hyper-V Manager. The operating system will go through a hardware detection phase; how problematic this is will depend on the operating system and the hardware involved. Also, the VHDs have been left in a “crash-consistent” state, meaning that they will act as though the machine they are attached to was shut down improperly. This might not mean anything more than answering the “Shutdown Event Tracker” dialog and perhaps restarting once or twice to finalize hardware changes, but you’ll want to validate any application data just to be certain.
Disk2VHD shutdown event tracker

(note: the comment was added for the screenshot, not by the Disk2VHD software)

To properly protect your Hyper-V virtual machines, use Altaro VM Backup to securely backup and replicate your virtual machines. We work hard perpetually to give our customers confidence in their Hyper-V backup strategy.

To keep up to date with the latest Hyper-V best practices, become a member of the Altaro DOJO | Hyper-V now (it’s free).

Wrap-Up

Test your new VM thoroughly. Some software that requires hardware-based activation may need to be reactivated. Some software may be hardware-dependent and won’t run in a virtual environment. If you didn’t connect the network adapter during VM creation, you’ll need to do so before attempting to utilize it. If you are working with a machine that is a domain member, be warned that there will be a name collision; the typical approach is to remove the new VM from the domain and then rename it prior to attaching it to the network. Once it is able to communicate with a domain controller, re-add it to the domain. Nonetheless, the disk2vhd utility is a tool that conveniently allows converting disks into the VHD and VHDX format.

Share this post

Frequently Asked Questions

The Disk2VHD utility is a free utility provided by Sysinternals that allows performing disk to VHD/VHDX conversions. The utility reads the information from a physical hard drive and creates a corresponding VHD or VHDX file for use in a Hyper-V virtualization environment. The operating system is not prepared in any way to run inside a virtual environment, so, given that fact, some consider this not to be a true P2V tool.
The VHDX Hyper-V disk format is the newest disk format supported by Hyper-V. It contains an advanced file format supported by Windows with up to 64 TB of storage capacity. The format is supported with Windows 2012 and higher and offers many benefits. These benefits include protection against data corruption, live resiginz is available, 4kb file sectors for better alignment and trimming capabilities.
Disk2VHD provides two modes of use, including an interactive GUI interface and also command-line operation. After downloading the utility, simply copy it to the source machine to be converted and run the executable.
The VHD format is the older of the two formats and does not support advanced features. It is limited to up to 2 TB of storage capacity and is limited in the protection it provides against corruption. It is supported with all Hyper-V versions. It does not support trimming or data alignment. The VHDX format provides the features lacking in VHD, such as larger storage size, metadata support, protection against corruption, 4 kb sectors. It is supported in Windows Server 2012 and higher.
SCVMM is System Center Virtual Machine Manager. It is a paid product that provides advanced operational capabilities for Hyper-V environments. It can even manage VMware vSphere virtualization environments. With SCVMM, organizations can migrate machines from VMware to Hyper-V, configure software-defined networking, and many other features.
As mentioned earlier, Disk2VHD is not considered a true P2V utility that proactively performs tasks to ensure the success of a P2V operation. It does work, however, there can be issues with storage drivers, and other software-related issues. To ensure success, you need to quiesce all activity and stop services that may lead to data corruption during the process, such as database services.
The latest version of disk2vhd was released in October 21, 2021 and is version v2.02.