Mounting a VHD disk file under the Windows platform is similar to mounting an ISO file;
To mount a VHD file using the Vhdmount tool
It's a little difficult to start an external VHD file in Hyper-V. If you have a VHD file on the backup drive and need to access the file from its virtual machine, Hyper-V requires that the virtual machine be imported. If you need to get some files quickly, the process is very time-consuming and annoying.
Another way is to access the hard disk by mounting the VHD directly on the desktop. Just like the ISO image that mounts the DVD, or the OS image of the Windows Imaging format file, the VHD file of the virtual machine may be mounted through the command line. The result is that the virtual machine's disk is like its own standalone disk, with a specific drive letter.
The Vhdmount tool can mount a VHD directly on the desktop to access the hard disk and can be used with Microsoft Virtual Server 2005. Vhdmount provides a command-line interface (CLI) for mounting and accessing VHDs. However, the first time you use it, you need to place the VHD on the desktop or server.
Download MVS 2005 to start the installation, but only install the Vhdmount function, do not load other. This process installs the necessary components required for the Vhdmount tool, rather than the full installation of MVS 2005. If you want to extract vhdmount faster, you can use the following two commands. They can get the MSI from the setup file and then run the components required by the Vhdmount tool:
SETUP.EXE/C/t C:\{targetfolder} msiexec/i "C:\{targetfolder}\virtual Server 2005 Install.msi"/qn ADDLOCAL=VHDMount
After installing Vhdmount, use the command vhdmount/m {TARGETVHD} to mount the VHD on the available drive letter. After the VHD is mounted, any changes will be written to the differencing disk unless the VHD is unloaded. If an error occurs, this will allow you to revert to the original disk. Use the command vhdmount/u {TARGETVHD} to unload the VHD. If you want to eliminate the change--the contents of the differencing disk--Just like uninstall, use the command vhdmount/u/d {TARGETVHD}. These commands can be run under Windows Vista, but using Vhdmount under Windows XP has some problems.
Mount a VHD file using PowerShell
If using Vhdmount doesn't work for you, you can use the PowerShell tool to achieve the same effect. However, the PowerShell installation process is not that simple. The following two commands can start a VHD:
$objVHDService = Get-wmiobject-class "Msvm_imagemanagementservice"-namespace "Root\virtualization"-computername "." $objVHDService. Mount ("{targetvhd}")
The first line above uses PowerShell to establish a connection to the local computer's Windows Management Instrumentation store and obtains an instance of the Msvm_imagemanagementservice category. This category requires the use of Mount methods, similar to the role of scripts.
Upon completion of this step, the mounted drive arrives at an offline disk. You need to get the disk online by using the Windows Disk Management or Diskpart.exe command-line tool. The complexity of accomplishing this task through PowerShell. If you want a direct PowerShell solution, check out the "using PowerShell to Mount VHDs" blog.
After you have finished working with a virtual disk, you need to put the disk back offline by running the following uninstall script:
$objVHDService = Get-wmiobject-class "Msvm_imagemanagementservice"-namespace "Root\virtualization"-computername "." $objVHDService. Unmount ("{targetvhd}")
If you are using Hyper-V in a small environment, you may also use Microsoft internal Windows Server backup tools to back up virtual machines. Because this tool can only be backed up at a single volume level, these backups are stored at the VHD level at a single virtual machine level. This means that individual files and folders from Hyper-V machines require tricky mounting and unloading.
Windows platform VHD disk file mount