none
Error: specifying non-vhd SourcePath for CreateVirtualDisk

    Pregunta

  • according to http://msdn.microsoft.com/en-us/library/windows/desktop/dd323661(v=vs.85).aspx,
    the SoucePath in the CREATE_VIRTUAL_DISK_PARAMETERS structure is
    "Optional fully qualified path to pre-populate the new virtual disk object with block data from an existing disk.
    This path may refer to a virtual disk or a physical disk."

    I was able to specify SourcePath as an existing .vhd file and it works fine.
    However, I was not able to specify SourcePath as any of the followings (vss shadowcopy):
    1. \\\\?\\GLOBALROOT\Device\\HarddiskVolumeShadowCopy31
    CreateVirtualDisk returns error 0x57, the parameter is incorrect
    The shadowcopy was created by using vshadow.exe

    2. \\Device\\HarddiskVolumeShadowCopy31
    CreateVirtualDisk returns error 0x57, the parameter is incorrect
    The shadowcopy was created by using vshadow.exe

    3. \\\\?\Volume{71591178-04af-11e1-9ebf-806e6f6e6963}\\
    CreateVirtualDisk returns either error 0x5, access denied when mount point has been created, or
    error 0x15, device is not ready when no mount point has ever been created.
    This volume is either a volume on physical disk, or an exposed shadow copy volume.

    My question is how to specify SourcePath to a VSS snapshot? or to a physical disk?
    or anything other than .vhd? 
    If SourcePath only supports .vhd (or .vhdx), should the manual be revised accordingly?

    Found similar posts with identical question without answers.
    http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/thread/5e37d0c7-8c76-4547-a3f0-41ffa8dc2ea4/
    http://social.technet.microsoft.com/Forums/zh/winserverhyperv/thread/a4d9af1f-6e21-491b-9d4f-e3bc2426555f
    http://stackoverflow.com/questions/6485579/creating-vhd-files-with-the-virtualdisk-api
    http://stackoverflow.com/questions/3205811/error-access-denied-when-using-the-function-createvirtualdisk-in-win7
    http://go4answers.webhost4life.com/Example/error-access-denied-function-25070.aspx

    Thanks.

    p.s.
    env: VS2010 + sp1, Windows SDK 7.1 and 7.0a, on Windows 7 professional x64 + sp1,
    running with elevated privileges
    source code: assign the fully qualified path to "params.Version1.SourcePath" in the following code.

    BOOL CreateVHD_Fixed(PCWSTR pszVhdPath, ULONG sizeInMB)
    {
        BOOL bRet = FALSE;
        HANDLE hvhd = NULL;
        CREATE_VIRTUAL_DISK_PARAMETERS  params;
        VIRTUAL_DISK_ACCESS_MASK        mask;
        VIRTUAL_STORAGE_TYPE            vst =
        {
            VIRTUAL_STORAGE_TYPE_DEVICE_VHD,
            VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT
        };

        wprintf(L"CreateVHD_Fixed %s, size (MB) %d\n", pszVhdPath, sizeInMB);

        params.Version1.UniqueId            = GUID_NULL;
        params.Version1.BlockSizeInBytes    = CREATE_VIRTUAL_DISK_PARAMETERS_DEFAULT_BLOCK_SIZE;
        params.Version1.MaximumSize  = sizeInMB * 1024 * 1024;
        params.Version1.ParentPath  = NULL;
        params.Version1.SourcePath          = NULL;
        params.Version1.SectorSizeInBytes   = CREATE_VIRTUAL_DISK_PARAMETERS_DEFAULT_SECTOR_SIZE;
        params.Version         = CREATE_VIRTUAL_DISK_VERSION_1;
        mask                                = VIRTUAL_DISK_ACCESS_CREATE;

        DWORD ret = CreateVirtualDisk(&vst,
            pszVhdPath,
            mask,
            NULL,
            // To create a dynamic disk, use CREATE_VIRTUAL_DISK_FLAG_NONE instead.
            CREATE_VIRTUAL_DISK_FLAG_FULL_PHYSICAL_ALLOCATION,
            0,
            &params,
            NULL,
            &hvhd);

        if (ret == ERROR_SUCCESS)
        {
            bRet = TRUE;
      if (INVALID_HANDLE_VALUE != hvhd)
      {
       CloseHandle(hvhd);
      }
        }
        else
        {
            bRet = FALSE;
            printf("failed to create vdisk...err 0x%x\n", ret);
            PrintErrorMessage(ret);
        }

        return bRet;
    }

    jueves, 26 de abril de 2012 22:55

Respuestas

  • Hi,

    According to the description, it seems that you want to develop some application. If so, it is recommend you to get further support in the corresponding community so that you can get the most qualified pool of respondents. Thanks for your understanding.
     
    For your convenience, I have list the related link as followed.
     
    MSDN Forums
    http://social.msdn.microsoft.com/Forums/en/categories


    viernes, 27 de abril de 2012 2:51
    Moderador
  • This works: \\\\.\\PHYSICALDRIVE1

    (Note it is drive, not disk.)

    The other part I am working on is to create VHD from a VSS snapshot.  It seems SourcePath cannot be a VSS snapshot (which is at volume level).  In order to create a VHD from a VSS snapshot, one needs to copy directory tree and meta data (ACLs, NTFS streams, etc.) from VSS snapshot to VHD.  Is there any efficient way to do this?  Any pointers are welcome.

      

    lunes, 30 de abril de 2012 19:59

Todas las respuestas

  • try something like

    \\.\physicaldisk1

     

    viernes, 27 de abril de 2012 1:42
  • Hi,

    According to the description, it seems that you want to develop some application. If so, it is recommend you to get further support in the corresponding community so that you can get the most qualified pool of respondents. Thanks for your understanding.
     
    For your convenience, I have list the related link as followed.
     
    MSDN Forums
    http://social.msdn.microsoft.com/Forums/en/categories


    viernes, 27 de abril de 2012 2:51
    Moderador
  • Also note that VHD and VHDX differencing disks support vastly different parent options.  They are not interchangeable.


    Brian Ehlert
    http://ITProctology.blogspot.com
    Learn. Apply. Repeat.
    Disclaimer: Attempting change is of your own free will.

    viernes, 27 de abril de 2012 14:41
    Moderador
  • try something like

    \\.\physicaldisk1


    several more tries without luck:
    (harddisk1 is present and has one partition)

    \\\\.\\PHYSICALDISK1
    error 0x2, the system cannot find the file specified

    \\Device\\Harddisk1
    error 0x6, the handle is invalid

    \\Device\\Harddisk1\\DR1
    error 0x57, the parameter is incorrect

    \\\\?\\GLOBALROOT\\Device\\Harddisk1Partition1
    error 0x2, the system cannot find the file specified

    \\Device\\Harddisk1Partition1
    error 0x2, the system cannot find the file specified

    \\\\?\\GLOBALROOT\\Device\\HarddiskVolume4
    error 0x57, the parameter is incorrect

    \\Device\\HarddiskVolume4
    error 0x57, the parameter is incorrect

    any suggestions?

    viernes, 27 de abril de 2012 18:00
  • Hi,

    According to the description, it seems that you want to develop some application. If so, it is recommend you to get further support in the corresponding community so that you can get the most qualified pool of respondents. Thanks for your understanding.
     
    For your convenience, I have list the related link as followed.
     
    MSDN Forums
    http://social.msdn.microsoft.com/Forums/en/categories


    I already submit to

    Server Virtualization, Windows Desktop SDK, General Windows Desktop Development Issues.

    So far, no luck yet.


    • Editado likong viernes, 27 de abril de 2012 18:13
    viernes, 27 de abril de 2012 18:11
  • Also note that VHD and VHDX differencing disks support vastly different parent options.  They are not interchangeable.


    Brian Ehlert
    http://ITProctology.blogspot.com
    Learn. Apply. Repeat.
    Disclaimer: Attempting change is of your own free will.

    version2 (for Windows 8) of the CREATE_VIRTUAL_DISK_PARAMETERS structure now has SourceVirtualStorageType, which is "A VIRTUAL_STORAGE_TYPE structure describing the source virtual disk specified in the SourcePath member".  Within VIRTUAL_STORAGE_TYPE, the valid device type includes iso, vhd, and vhdx.  This seems to suggest physical disk and vss shadow volumes are not valid type for SourcePath???

    viernes, 27 de abril de 2012 18:20
  • This works: \\\\.\\PHYSICALDRIVE1

    (Note it is drive, not disk.)

    The other part I am working on is to create VHD from a VSS snapshot.  It seems SourcePath cannot be a VSS snapshot (which is at volume level).  In order to create a VHD from a VSS snapshot, one needs to copy directory tree and meta data (ACLs, NTFS streams, etc.) from VSS snapshot to VHD.  Is there any efficient way to do this?  Any pointers are welcome.

      

    lunes, 30 de abril de 2012 19:59