VhdCapture & VhdPrep: Using these tools to P2V your physical server to USB, Network Share


In today’s post, I want to spend some time sharing how to use the virtualization tools that our team (MPSD Development) built as part of the Configuration Manager Physical-to-Virtual Migration Toolkit (ConfigMgr P2V).  In previous posts, I shared how ConfigMgr customers could utilize the toolkit for migration purposes as well as sharing how others can take advantage of some of the features for those who are not ConfigMgr customers (shame on you!)

The underlying libraries our team built include three key components:

  • VHD Capture:  This binary is used to create an exact replica of any MBR-based physical disk into Virtual Hard Disk (VHD) format.  It is driven fully as a command-line utility and is scriptable if you choose to utilize in this manner.
  • VHD Capture Wizard:  This provides a nice, graphical experience to select the proper disk to virtualize and storage location to save the VHD
  • VHD Prep:  This stand-alone utility is multi-faceted and I will cover below but its purpose is to optimize the VHD (e.g. compact) while also ensure that the VHD is fully Hyper-V ready.

In the coming sections, I will outline in detail how you can use these tools where ever you choose.

NOTE:  I've attached the tools for those of you who do not currently have access to the Configuration Manager console installed or handily available.

Getting The Tools:  Obtaining the Binaries

In order to use the tools, you obviously need to download the ConfigMgr P2V Toolkit.  After you install, all binaries that are part of the installation by default go in %programfiles%\Configuration Manager P2V Migration Toolkit.  For the purpose of this post, we will deal with binaries available in the BIN directory.


Using VHD Capture (vhdcapture.exe) to Virtualize a Physical Disk

The use of VHD capture requires you to understand the syntax and the easy way to determine the syntax is to use the simple /? syntax to understand the available options.  For simplicity, I’m going to share a screen shot of this output for you to review -


The key usages is to list all the physical disks (potential sources) that are available to capture using the list switch.  Beyond this, the typical syntax used to make action occur is the following:

  1: vhdcapture capture -savePath:{path to location}

For the purpose of this example, I would like to capture my physical volume named “Data” that has all my data I’d like to keep around during a migration.  Let’s take a look at that…

  1. Open path \VHDTools in a Command Prompt
  2. Type VHDCapture.exe capture -savePath:\\server\scratch\chrad\MyDataDrive –disk:1

This will result in a VHD created in the path \\server\scratch\chrad\MyDataDrive with the name Disk0.vhd.  This will take my data drive and create a virtualized copy of this single partition on Disk 0.


Using VHD Capture Wizard:  If your graphical, your golden

Because we realized that for some people, using command-line isn’t their preferred method if they are capturing only a single partition or disk.  It is because of this that we created a separate experience that provides a graphical experience for selecting the disk/partition to virtualize and also where you’d like to store the resulting VHD file.  This user experience still uses the same libraries used by the command-line so you shouldn’t worry if they are different – they are the exact same.

To use VHD Capture Wizard, do the following:

  1. Open path \bin\vhdtools
  2. Start VhdCaptureWizard.exe
  3. On the Welcome screen, click Nextimage
  4. On the Select Drives screen, check the Drives you’d like to virtualizeimage
  5. For Select Location, click Browse and input a location to save your VHD (2nd Drive, USB, Network Share)image
  6. After clicking Next, we will start creating a VHD at that locationimage

After this is completed, you will click Finish to close the wizard.  The end result for the demo listed above is that I will now see a VHD created on the share named Disk0.vhd.

Verifying VHD:  Did this thing really work?

To verify the success of the creation of your VHD it is rather simple assuming you have Windows 7 or 2008 available.  To effectively load the volume, and verify data integrity, do the following:

  1. Click Storage (Server 2008 Only)
  2. Open Disk Management
  3. Right-click, select Attach VHDimage
  4. Select the path to the newly created VHD
  5. In Windows Explorer, navigate the drive and verify the data is correctimage

Preparation:  The Key to a Happy Ending

The VHD Capture, and the wizard, both create pristine copies of the physical disk layout with partitions.  This includes unused sectors on the disk.  Obviously, this isn’t an optimized experience when attempting to re-use the disk.  This could be a satisfactory situation for some if doing data protection & backup.  To optimize the VHD, while also allowing it work work correctly in Hyper-V, we created the VHDPrep.exe tool that allows us to ensure that the VHD is ready to go.

The functions provided automatically by VHDPrep include the following:

  1. Use’s Hyper-V’s compact function to remove unused sectors
  2. Injects critical boot drivers to allow the VHD to properly boot the Windows OS (if necessary)
  3. Corrects NT Boot Sector issues for Windows Server 2003
  4. Aligns physical disk layout to virtual disk layout
  5. Modifies boot entries to leverage virtual storage drivers

The VHD prep tool is a separate tool designed to run after you’ve successfully captured the VHD.  For many, you might ask why we didn’t just do this automatically.  We separated this functionality because we felt that not everyone requires that the disks are bootable, etc. and so we wanted to create the pristine nature of the VHD created by the command-line & wizard.  We would love to hear your feedback if you believe this is the wrong design but for now we felt it offers you the maximum flexibility.

To utilize VHD Prep, please do the following:

  1. Open the path \bin\VHDPrep
  2. Type vhdprep.exe {path to VHD}

This will start the edit process of your prisitine VHD and make the modifications to make it successfully work with Hyper-V.  If you would like to retain the original, you should duplicate (copy) the VHD and then target the copy.  This is a nice fail safe to ensure that you still have the virtual copy of the physical disk.


This is it.  You’ve now gotten an introduction to the tools that can make P2V happen without using Task Sequences, ConfigMgr, or anything other than just your keyboard and a few libraries.


We feel good about the P2V Toolkit and it’s ability to aid IT professionals and administrators store offline copies of physical disks in a virtual format (VHD) that is supported by the popular Hyper-V.  In today’s post, I outlined using a non-VMM solution that support P2V’ing of any MBR-based disk in use today in the market place.  This toolkit is currently in CTP1 format and we will soon release the next non-RTW version with an impending final release date later this year.

For now, I hope you’ve enjoyed some of the details behind using the ConfigMgr P2V Migration Toolkit!