Mount a VHD file in Windows 2008 or SBS 2008

Mount a VHD file in Windows 2008 or SBS 2008

Note: This can also be used on Windows Server 2003 and SBS 2003

Finding yourself in a situation where you need to browse a vhd file, whether because you need to restore files from a backup and Windows Server Backup console doesn’t help you or you just need to get some files off a vhd file, the sad truth is that attaching/mounting a VHD file in Windows 2008 and SBS 2008 is a bit more complicated compared to the easiness that this happens in the newer versions 2008 R2 and SBS 2011( 2008 R2 article here ). Here we don’t have Attach VHD in Disk Management nor we have a smart Diskpart that can mount it for us. It comes to the help of another Microsoft product called Microsoft Virtual Server 2005 R2 SP1 which is FREE. http://www.microsoft.com/en-us/download/details.aspx?id=2994

You don’t need to install or use the whole software, you just need one of it’s features called VHD Mount and you can install only this component if you chose a Custom installation. It is a command line utility so after you are done with the Virtual Server installation you will have to open CMD and navigate to the installation path, usually C:\Program Files\Microsoft Virtual Server\vhdmount.

So here is how it goes to mount and unmount an image.

vhdmount /m “C:\blabla\blabla.vhd”

Then it mounts the image and it will appear in Computer as an additional partition

Do what you want to do with the image and once you are done you should unmount it. There are two ways to do it.

– If you have done any changes to the vhd file you can unmount it and save the changes:

vhdmount /u “C:\blabla\blabla.vhd” /c

– Or if you want to discard any changes:

vhdmount /u “C:\blabla\blabla.vhd” /d

A software engineer wrote a regkey script that should enable you to right-click a .vhd file and have the option of Mount and Dismount. Personally it didn’t work for me and command line is far too easy to use so it doesn’t really matter that much, but for those that want to give it a try here is the file.

These are the vhdmount switches you might be using. Chose the appropriate combo. Best advise if to use /m with F

/p – Plugs in the specified VHD as a virtual disk device without mounting the volume.

/m – Plugs in the specified VHD as a virtual disk device and mounts the volume.

/f – Performs the specified operation without creating an Undo Disk. This parameter is applicable for /p and /m. All changes to the mounted disk are directly written to the specified VHD.

/u – Unplugs the virtual disk device for the specified VHDFileName.

/c – Updates the original VHD with all changes that were stored in the Undo Disk anddeletes the Undo Disk after unplugging the disk. This parameter is only applicable if the VHD was mounted without using /f.

/d – Discards all changes to the mounted disk and deletes the Undo Disk after unplugging the disk. This parameter is only applicable if the VHD was mounted without using /f.

/q – Displays the disk name of the mounted virtual disk device for the specified VHDFileName.

VHDFileName – VHD name including full path.

DriveLetter – Optional parameter for /m option. If drive letter is specified the volumes are mounted starting at the specified drive letter. If drive letter is not specifiedit is automatically assigned.

All – Applies the operation on all mounted virtual disk devices. This parameter is applicable for /u and /q.

By default, VHDMount creates an Undo Disk in current user’s temporary folder. All changes to the mounted disk are written to this Undo Disk. Use /c to commit or /d to discard these changes at the time of unplugging the disk device. Use /f option to mount a VHD without an Undo Disk.

Examples:
VHDMOUNT /p [/f] VHDFileName
VHDMOUNT /m [/f] VHDFileName [DriveLetter]
VHDMOUNT /u [/c | /d] VHDFileName | All
VHDMOUNT /q VHDFileName | All