locked
Mount VHD in parent partition? RRS feed

  • Question

  • Hi guys,

    I was tring to mount a VHD file in the parent partition: no luck at all.
    I was using this VB code, but after the disk is "mounted", the parent detects new hardware and nothing else happens.
    There is no adittional disk displayed in Disk Management, no error in the event viewer...

    Help?

    Dim WMIService  
    Dim VHDService  
    Dim strVHD, strAction  
     
    Set args = WScript.Arguments  
    Set WMIService = GetObject("winmgmts:\\.\root\virtualization")  
    strAction = WScript.Arguments.Item(0)  
    strVHD = WScript.Arguments.Item(1)  
     
    Set VHDService = WMIService.ExecQuery("SELECT * FROM Msvm_ImageManagementService").ItemIndex(0)  
     
    Select Case strAction  
        Case "mount" 
            VHDService.Mount(strVHD)  
            msgbox "Disk mounted" 
        Case "unmount" 
            VHDService.UnMount(strVHD)  
            msgbox "Disk unmounted"    
        Case else  
            'do nothing  
    End Select 

    Thanks!
    Tuesday, July 8, 2008 10:14 PM

Answers

  •  

    Hi,

     

    I would double check if the virtual disk is being used. I saw the same problem when the virtual machine was running. Besides, would you please try creating a new virtual disk to see if the problem remains? And if possible, restart your physical machine and then try this script to see how it goes.

     

    Best regards,

    Chang Yin

    Tuesday, July 22, 2008 11:48 AM

All replies

  •  

    Hi Carlos,

     

    Please note that if you want to run this script, you need an elevated command prompt. To do this:

     

    Click Start, type CMD in the Start Search box, then right-click the CMD icon in the Programs list, select Run as administrator. Click Continue in the UAC prompt box.

     

    This is because mounting/unmounting a disk needs administrative privilege. Usually, with the default setting (UAC enabled), you need to elevate the CMD prompt when you run the script.

     

    I have verified this script, it runs very well on my system after elevating the command prompt.

     

    Best regards,

    Chang Yin

    • Proposed as answer by John Paul Cook Friday, July 11, 2008 10:14 PM
    • Unproposed as answer by Charly Albert Saturday, July 12, 2008 7:22 PM
    Friday, July 11, 2008 11:31 AM
  • Hello,

    Please help me understand what you are trying to do as it sounds interesting.

    Are  you mounting a VHD to be viewable within the Host OS as a disk or something else?
    Friday, July 11, 2008 8:17 PM
  • I'm [trying] mounting a VHD to be viewable withing the Parent [Host] OS as a disk.
    Same as I could mount a VirtualPC VHD or VMware VMDK.

    It should be possible, but so far, no luck.
    Friday, July 11, 2008 8:48 PM
  • OK that is what I thought you were trying to do.

    I will try this myself and see what I get as this will be very helpful for restore functionality.

    Are you trying to view a Hyper-V VHD on the w2k8 parent Host?

    I will try this in the next few days and get you back my info- Have you tried to mount the VHD on a separate system to see if the host is the issue- oh and do you have any Antivirus that may be getting in the way?
    Omar
    Friday, July 11, 2008 9:04 PM
  • Yes, indeed. It can be very helpful in several scenarios.

    Yes, I tried with the parent Host. I didn't try with a child partition (I gues it should be possible?).

    I only tried with this installation (and it feels to me that is a particular problem of this installation).

    No antivirus, or nothing that should be getting in its way.

    Cheers.

    Saturday, July 12, 2008 1:36 AM
  • Check this blog post out: http://blogs.msdn.com/virtual_pc_guy/archive/2008/02/01/mounting-a-virtual-hard-disk-with-hyper-v.aspx

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Saturday, July 12, 2008 5:01 AM

  • Chang Yin-MSFT said:

     

    Hi Carlos,

     

    Please note that if you want to run this script, you need an elevated command prompt. To do this:

     

    Click Start, type CMD in the Start Search box, then right-click the CMD icon in the Programs list, select Run as administrator. Click Continue in the UAC prompt box.

     

    This is because mounting/unmounting a disk needs administrative privilege. Usually, with the default setting (UAC enabled), you need to elevate the CMD prompt when you run the script.

     

    I have verified this script, it runs very well on my system after elevating the command prompt.

     

    Best regards,

    Chang Yin



    Thanks Chang.
    Yes... I'm using elevated privilege (it doesn't work at all if you don't have elevetad privilege).
    I'm sure is something else I'm missing. :(

     
    Mike Sterling [MSFT] said:

    Check this blog post out: http://blogs.msdn.com/virtual_pc_guy/archive/2008/02/01/mounting-a-virtual-hard-disk-with-hyper-v.aspx


    This posting is provided "AS IS" with no warranties, and confers no rights.



    Hi Mike,

    The post uses the same code I'm using. As a matter in fact, I've already read it. But with different result (it works for him, not for me, hehe).
    • Edited by Charly Albert Saturday, July 12, 2008 7:22 PM Additional comments
    Saturday, July 12, 2008 7:20 PM
  •  

    Hi Carlos,

     

    Let's go through the whole steps to see if there are any mistakes:

     

    1.    Make sure the virtual disk is not used by any virtual machines. If the disk is being used by one virtual machine, the process will fail. If you are not sure about this, you can simply copy the existing VHD file to another location and try the script.

     

    2.    Open an elevated command prompt, then type the following command (I name the script to MountVHD.vbs and want to mount the F:\WinSrv2008-01.vhd):

     

    Cscript MountVHD.vbs mount F:\WinSrv2008-01.vhd

     

    Then, after pressing Enter, the prompt box should show up and the VHD should be mounted.

     

    If the script is still not working, please check the Event Viewer, located at Applications and Services Logs\Microsoft\Windows\Hyper-V-Image-Management-Service, to see if any error or warning exists.

     

    By the way, this is really a wonderful script to easily mount/unmount the virtual disk.J

     

    Best regards,

    Chang Yin
    Monday, July 14, 2008 12:07 PM
  • Ok I just went through a round of this testing and here are my results:

    Started with a USB Drive that was designated for Windows Backup (w2k8)

    I tried to use this script to mount the VHD file- that of course represented the Host OS and the script failed over and over- "The file or directory is corrupted and unreadable (0x80070570)

    So then I put the USB drive into my workstation and used Virtual Server 2005 VHDMount.exe and I was able to mount the Windows backup host VHD file.

    Next I took browsed to the X:\VirtualMachines\MyGuestOS\ directory and I copied the Hyper-V VHD file of my guest.

    I took that Hyper-V VHD file and copied it to my W2k8 machine and ran the script and it mounted without issue- but of course I needed to bring the disk online using disk manager.

    Now I know I am not the original poster but- conclusion: If you need to manually extract data from a Windows backup VHD file- use Virtual Server 2005 VHDMount.exe or use Windows Backup and get to the data using a UNC path or directly from a local drive if you give it a drive letter.

    To manually extract data from a Hyper-V  VHD Disk- use the script above within an elevated command prompt or use the Virtual Server 2005 VHDmount.exe

    of course after each of these manipulations will the disk be considered supported or usable?

    Isnt this how the offline patching of hyper-V VHD Operating Systems going to be performed in some derivation of this mount and dismount?
    Omar
    Wednesday, July 16, 2008 12:41 AM
  • Chang Yin-MSFT said:

     

    Hi Carlos,

     

    Let's go through the whole steps to see if there are any mistakes:

     

    [...]

     

     

    By the way, this is really a wonderful script to easily mount/unmount the virtual disk.J

     

    Best regards,

    Chang Yin



    Hi Chang,

    Yes, everything just fine: it says that is mounted, Windows detects a new device (Storage Miniport Driver) and says is installed and ready to be used, an informational event is created saying that the VHD was mounted by the system, even the file is being taken by the system, yada yada.
    But the disk is nowhere to be found! I'm not sure where even start looking at. =(

    Omar Droubi said:

    Ok I just went through a round of this testing and here are my results:

    [...]

    Now I know I am not the original poster but- conclusion: If you need to manually extract data from a Windows backup VHD file- use Virtual Server 2005 VHDMount.exe or use Windows Backup and get to the data using a UNC path or directly from a local drive if you give it a drive letter.

    To manually extract data from a Hyper-V  VHD Disk- use the script above within an elevated command prompt or use the Virtual Server 2005 VHDmount.exe

    of course after each of these manipulations will the disk be considered supported or usable?

    Isnt this how the offline patching of hyper-V VHD Operating Systems going to be performed in some derivation of this mount and dismount?
    Omar


    I don't have Virtual Server 2005 installed... And I don't want to install it either.
    It just seemed natural to mount a VHD, since the parent partition should have the same "abilities" that the childs...

    Cheers.

    Sunday, July 20, 2008 10:36 PM
  •  

    Hi,

     

    I would double check if the virtual disk is being used. I saw the same problem when the virtual machine was running. Besides, would you please try creating a new virtual disk to see if the problem remains? And if possible, restart your physical machine and then try this script to see how it goes.

     

    Best regards,

    Chang Yin

    Tuesday, July 22, 2008 11:48 AM