Using Disk2VHD for Hyper-V P2V (Physical to Virtual) Conversions34
Microsoft’s System Center Virtual Machine Manager up through 2012 has a built-in utility to convert existing physical machines to Hyper-V virtual machines (P2V), but not every deployment is large enough to justify the cost of that product. For instance, you may only have one host and two or three machines to virtualize. In VMM 2012 R2, the P2V tool was removed entirely, leaving System Center customers in the lurch. In such cases, Sysinternal’s free “Disk2VHD” (Disk to VHD) tool for Hyper-V P2V conversions may be exactly what you need.
Updated March 6, 2016
Microsoft Virtual Machine Converter 3.0
Before using this P2V tool, you might try Microsoft’s Virtual Machine Converter. It has been expanded to include P2V capability. The tool is provided free-of-charge. Visit the TechNet article for more information. The first link on that page will take you to the download.
Obtaining and Installing Disk2VHD for Hyper-V P2V
Sysinternals (now owned by Microsoft) offers this tool as a free download from TechNet. 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 might do to prepare:
- Verify that there aren’t any problems with the system. Check event logs, etc. Run CHKDSK.
- Remove any unnecessary software and drivers. 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.
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 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.
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:
That screenshot was taken from a Windows 2012 R2 computer; some older operating systems will not have the “System Reserved” partition. If the system you’re creating a VHD from has this partition, you’ll need to include it if you wish for the VHD 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 VHD(s) on the same drive that you’re copying as long as there is enough room.
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.
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.
|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 *
|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.|
|Enter the full path and file name of the VHD[X] to be created. UNCs are acceptable.|
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:
With all drives checked, running the above system through Disk2VHD produces:
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.
Create the Virtual Machine
All that the Disk2VHD Hyper-V P2V tool does is prepare the VHD 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 VHDs that were output by Disk2VHD in the demonstrations 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.
2. Once you have placed the files where you want them, go to New->Virtual Machine in the Action pane of Hyper-V Manager. If it starts on the “Before You Begin” screen, click “Next”. Name the virtual machine appropriately and relocate it if you like. Click “Next”.
3. On the next two screens (not pictured), you’ll establish how much memory to assign and what network to connect the virtual network adapter to. You may wish to leave the network adapter unconnected to avoid coexistence problems with the original VM. Configure these as desired and click Next to reach the “Connect Virtual Hard Disk” screen. You have three choices.
a. If you want to install a new operating system and just connect those drives to be read as standard data disks, you can “Create a virtual hard disk”. You’ll need to install the operating system to it.
b. If you want to attach the bootable VHD now, click “Use and existing virtual hard disk” and type in or browse to the name of the VHD to use. You cannot attach any other drives at this time.
c. You can choose to “Attach a virtual hard disk later”. Once the wizard is complete, you can change the properties of the VM to connect the drives.
4. Click “Next”, ensure everything is as desired, and click “Finish”.
5. The VM will be created and left in the “Off” state. If you didn’t attach any VHDs or if you have more than one to attach, right-click on it in Hyper-V Manager and click “Settings…” Highlight any drive controller (IDE Controller 0, IDE Controller 1, or SCSI Controller) and click “Add” on the right.
6. This will present the following screen. You can select the controller (it will default to whichever you highlighted) and then browse to the VHD file (or you can create a new one). Remember that boot drives must ALWAYS be connected to the IDE chain. Repeat this step until you have added all drives. You don’t need to click “OK” or “Apply” between adds; just click on a controller in the left pane and continue attaching/created drives until you’re finished. If for some reason a SCSI controller wasn’t created or if you need more than one, you can add it using the “Add Hardware” button at the top-left of the “Settings” window.
7. Modify any other settings of the virtual machine as desired. Click OK.
8. 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.
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.
Have any questions or feedback?
Leave a comment below!
Backing up Hyper-V VMs
If you’d like to make backing up your Hyper-V VMs hassle-free, effective and affordable, check out Altaro VM Backup. It’s free for up to 2 VMs per host, forever!
Download your copy (free OR a 30-day trial of our Unlimited Edition) here: http://www.altaro.com/hyper-v-backup/.