Disk2vhd is a utility that creates .VHD (Virtual Hard Disk) a virtual disk version of physical “bare-metal” disk or disks for use in Microsoft Hyper-V, System Center Virtual machine Manager, AppController and Microsoft Azure. The difference between Disk2vhd and other physical-to-virtual tools is that you can run Disk2vhd on a system that’s online. Disk2vhd uses Windows' Volume Snapshot capabilities to create consistent “point-in-time” snapshots of the volumes you want to include in your conversion. You can even have Disk2vhd create VHDs on local volumes, even ones being converted. Performance is better when the VHD is on a disk different from the one it’s being converted on.
Using Disk2VHD to migrate your Physical Server to a Virtual Machine
We’ll take a “Step-by-Step” approach to how you can use the Disk2vhd Utility. After we migrate a physical hard drive to a virtual machine, we’ll then bring it into Hyper-V Manager as a virtual machine. You can also add it to Microsoft Azure or by using the Microsoft Azure Pack on your Windows Server 2012 R2 host machine.
Start with unzipping the extracted files for disk2vhd.exe
When the tools starts, you can see that it has an Administrator share, but you can change this to something friendly, and remember that .VHDX files are not supported in Microsoft Azure.
Upload only fixed VHD’s (not dynamic, and not .VHDX). When using Microsoft Azure PowerShell cmdlets you can use Add-AzureVHD to automatically convert dynamic VHD’s to fixed VHD’s while uploading them to Microsoft Azure, but many other tools do not have that capability. Here is where you’re going to uncheck Use Vhdx, which will change the path to .VHD format.
So I’ve unchecked the Use vhdx and unchecked my E:\Images as I do not want this Volume in my .VHD file when it’s being created. I also pick the location to copy the .VHD to, which is E:\VM.vhd which will be approximately 90GB in size.
Note – The maximum .VHD size is 127GB for OS Disks and 1023GB for data disks.
The Utility will create one VHD for each disk on which selected volumes reside and include your boot information! It preserves the partitioning information of the disk, but only copies the data contents for volumes on the disks that are selected. This enables you to capture just system volumes and exclude data volumes.
Once everything is configured, I can click on Create.
The speed will depend on the size of the physical disks / partitions you have selected or the destination location for storing the converted VHD file if it is the same as the source. Since Disk2vhd.exe performs I/O operations it will be much slower. It’s recommended to specify the VHD file path to a location other than the volumes you have selected. In my case I’m copying it to my secondary bay drive E:.
.VHD is being created.
To use VHDs produced by Disk2vhd, create a VM with the desired characteristics and add the .VHD to the VM's configuration as IDE disks.
On first boot, a VM booting a captured copy of Windows will detect the VM's hardware and automatically install drivers, if present in the image. If the required drivers are not present, install them via Hyper-V integration components. You can also attach to VHDs using Windows Server Disk Management or Diskpart utilities.
Caution: do not attach to VHDs on the same system on which you created them if you plan on booting from them. If you do so, Windows will assign the VHD a new disk signature to avoid a collision with the signature of the VHD’s
source disk. Windows references disks in the boot configuration database (BCD) by disk signature, so when that happens Windows booted in a VM will fail to locate the boot disk.
Using the Command-Line Interface
Disk2vhd includes command-line options that enable you to script the creation of VHDs. Specify the volumes you want included in a snapshot by drive letter (e.g. c:) or use "*" to include all volumes.
Example: disk2vhd.exe * E:\VM.vhd
So to convert your C: drive to a VHD file, use the following command and store on E:\
Example: disk2vhd.exe C: E:\VM.vhd Creating a new VM from your P2V .vhd on your bare-metal Hyper-V host Home Now that we’ve went through the P2V conversion from the Physical Disk to a Virtual Disk, we can now add it to a Hyper-V host. Make sure and use a Hyper-V host different from the one you created the virtual hard disk from and/or change your networking to support this. If you want to use the .VHD as an image, Sysprep it to make sure it is generalized. Open Hyper-V Manager on your “bare-metal” host and click New – Virtual Machine … Read the Wizard Pane and then click Next Typically I put my VM’s in my own default storage location. If you want to hard code a path to keep your VHD’s and VM’s in, go to Hyper-V Settings and change the default paths. Next, Specify Name and Location. Here I put in a name for my VM and my default path where I want to VM’s to be created and reside. Specify Generation, in this case we created a .VHD so we will select Generation 1, instead Generation 2 Assign Memory, click next Configure Networking, I choose Not Connected for now. I can then move this VM to another Hyper-V Host or to Microsoft Azure to run it. On the Connect Virtual Hard Disk pane, do not select Create a virtual hard disk or Attach a virtual hard disk later, but select Use an existing virtual hard disk, the .VHD that you convert and go to the path and select it. Browse to the folder where your .VHD resides, Select the .VHD, click Next, then Finish. The virtual machine will be created. Click Next Next go to your local “bare metal” host and open Hyper-V Manager and you will see your new virtual machine under Virtual Machines. Right-click or on in the Actions pane, select Start Here's a screenshot of my Windows Server 2012 R2 Hyper-V system running in a virtual machine on top of the system it was created from running from. This .VHD file can now be used with other Hyper-V hosts, I suggest you put this on another Hyper-V host or the two VM’s will conflict as they have the same setting and configuration. The .VHD can also be used with System Center Virtual Machine Manager as well as uploaded to Microsoft Azure using the Add-AzureVHD Azure PowerShell cmdlet or by using the Microsoft Azure Pack from a bare metal host on your private cloud integrated with Microsoft Azure Portal in the public cloud. Adding your migrated .VHD to the System Center Home You can create a Virtual Machine from this .VHD within System Center Virtual Machine Manager. You can also create a VM Template as well form the .VHD you created.