none
Error: specifying non-vhd SourcePath for CreateVirtualDisk

    Вопрос

  • 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;
    }

    26 апреля 2012 г. 22:55

Ответы

  • 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


    27 апреля 2012 г. 2:51
  • 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.

      

    30 апреля 2012 г. 19:59

Все ответы