Virtual Server 2005 R2 SP1 Treasures: VHD Mount

Use VHD Mount to mount and edit the contents of VHD virtual hard disk files.

Over the next few weeks, I'm going to be writing about some of my favorite features in the recently released Microsoft Virtual Server 2005 R2 Service Pack 1. This week, I'll start with VHD Mount.

VHD Mount is installed by default by the Virtual Server R2 SP1 setup, but can be installed individually, as well. VHD Mount can be installed on any Virtual Server 2005 R2 SP1-supported OS, which includes Windows XP SP2, Windows Vista and Windows Server 2003.

To install just the VHD Mount utility on a Windows system, follow these steps:

  1. Download Virtual Server 2005 R2 SP1.
  2. Once the download completes, run setup.exe from the download location.
  3. When the Microsoft Virtual Server 2005 R2 SP1 setup window appears, click Install Microsoft Virtual Server 2005 R2 SP1.
  4. Click the I accept the terms in the license agreement radio button and click Next.
  5. Enter your name and organization and click Next.
  6. Choose Custom as the setup type and click Next.
  7. In the Custom Setup dialog box, click the drop-down menu next to each installation component and select the This feature will not be available option. For the VHD Mount option, click its drop-down menu and select This feature will be installed on local hard drive. The installation options are shown in Figure 1 below.
  8. Once you have set the correct installation options, click Next.
  9. In the Ready To Install dialog box, click Install.
Figure 1
[Click on image for larger view.]
Figure 1. Selecting to only install VHD Mount

Once the installation completes, you can use VHD Mount to mount any VHD file as a local hard disk.

VHD Mount uses the Virtual Disk Service to mount and assign a custom drive letter to a VHD file. The problem with this is that VDS was introduced in Windows Server 2003 and, thus, is not available on Windows XP and earlier operating systems. So if you're running Windows Server 2003, you would perform the following steps to mount a VHD file and assign a specific drive letter:

  1. Open the command prompt by clicking Start -- Run, typing cmd in the Run dialog box, and hitting Enter.
  2. Navigate to the Vhdmount installation folder. By default, this will be "C:\Program Files\Microsoft Virtual Server\Vhdmount." So assuming the default installation, you would run the following command:
    cd "C:\Program Files\Microsoft Virtual Server\Vhdmount"
  3. Mount a virtual hard disk to your system by using the following syntax:
    vhdmount /m [/f] <vhd file> <drive letter>
    For example, to mount the D:\XPVM\XP.vhd file and assign it the drive letter V, you would run:
    vhdmount /m /f D:\XPVM\XP.vhd V:

Note that when the /f switch is used, any changes made to the virtual hard disk will be directly written to the VHD file. If you just want to examine a virtual hard disk file and not commit any changes, then do not include the /f switch in the command. Without /f, the VHD file is still mounted, but any changes are written to an Undo Disk. If you want to commit the changes stored in the Undo Disk, you can do so by using the following syntax:

vhdmount /u /c <vhd file> | All

Following the previous example, if the VHD file was mounted without using the /f switch in the command, you can un-mount the disk (/u switch) and commit the changes (/c switch) by running this command:

vhdmount /u /c D:\XPVM\XP.vhd

Alternatively, if you wanted to commit changes and un-mount all locally mounted VHD files, you would run:

vhdmount /u /c all

If a virtual hard disk was mounted using the /f switch in the command, you will not need to use the /c parameter when you un-mount the disk. So, based on the original example, you would unmount the disk by running:

vhdmount /u D:\XPVM\XP.vhd

Now, if you would like to run this tool and have the OS treat any mounted VHD similarly to how it would handle a plugged-in USB drive, you would use the following command syntax:

vhdmount /p [/f] <vhd file>

Following the previous example, you could plug in a VHD file by running this command as a user with administrative rights:

vhdmount /p /f D:\XPVM\XP.vhd

Once the VHD is connected, it will be detected like any plugged-in USB drive, so Windows will automatically mount it and assign a drive letter. You can then open the drive in Windows Explorer, and view and edit its files. As you can see, using the /p switch is much simpler and can be run on Windows XP, Vista or 2003, but it does not give you the option to manually assign a drive letter.

When you're finished working with the virtual hard disk, you can unplug it by running vhdmount /u D:\XPVM\XP.vhd.

Finally, if you're looking to automatically plug in VHD files when you double-click on them in Windows Explorer, take a look at Ben Armstrong's excellent tip, "Double-Clicking on a VHD To Mount It." This tip uses the plug-in feature of VHD Mount, so it will work on Windows XP, Windows Vista and Windows Server 2003.

VHD Mount is ideal for both auditing and editing the contents of any Windows VHD-formatted virtual hard disk. I hope you find this tool as useful as I have.

About the Author

Chris Wolf is VMware's CTO, Global Field and Industry.