【问题标题】:Download the VHD after running sysprep on Azure in DevTest labs在开发测试实验室中在 Azure 上运行 sysprep 后下载 VHD
【发布时间】:2017-09-25 21:25:59
【问题描述】:

我在开发测试实验室中使用 az lab vm apply-artifacts 命令在我的 VM 上运行了 sysprep 工件。

之后,当我运行az lab vm show 时,我得到一个computeId,其中包含资源id

计算 ID 如下所示:"computeId": "/subscriptions/#####/resourceGroups/###/providers/Microsoft.Compute/virtualMachines/####"。

如何从中获取磁盘路径。我对 SAS 密钥更感兴趣,我可以在 AzCopy 中使用它来下载与此 VM 关联的 vhd 文件。

【问题讨论】:

    标签: azure azure-devtest-labs


    【解决方案1】:

    目前,Azure 不支持使用 Azcopy 从 devtest lab 下载 VHD。

    作为一种解决方法,我们可以从该 VM创建自定义映像(创建快照),然后使用 PowerShell 通过 Azure PowerShell 将此快照复制到另一个存储帐户。

    然后我们可以使用这个PowerShell来复制这个快照,下面是脚本:

    #Provide the subscription Id of the subscription where snapshot is created
    $subscriptionId = "yourSubscriptionId"
    
    #Provide the name of your resource group where snapshot is created
    $resourceGroupName ="yourResourceGroupName"
    
    #Provide the snapshot name 
    $snapshotName = "yourSnapshotName"
    
    #Provide Shared Access Signature (SAS) expiry duration in seconds e.g. 3600.
    #Know more about SAS here: https://docs.microsoft.com/en-us/azure/storage/storage-dotnet-shared-access-signature-part-1
    $sasExpiryDuration = "3600"
    
    #Provide storage account name where you want to copy the snapshot. 
    $storageAccountName = "yourstorageaccountName"
    
    #Name of the storage container where the downloaded snapshot will be stored
    $storageContainerName = "yourstoragecontainername"
    
    #Provide the key of the storage account where you want to copy snapshot. 
    $storageAccountKey = 'yourStorageAccountKey'
    
    #Provide the name of the VHD file to which snapshot will be copied.
    $destinationVHDFileName = "yourvhdfilename"
    
    
    # Set the context to the subscription Id where Snapshot is created
    Select-AzureRmSubscription -SubscriptionId $SubscriptionId
    
    #Get the snapshot using name and resource group
    $snapshot = Get-AzureRmSnapshot -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName 
    
    #Generate the SAS for the snapshot 
    $sas = Grant-AzureRmSnapshotAccess -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName  -DurationInSecond $sasExpiryDuration -Access Read 
    
    #Create the context for the storage account which will be used to copy snapshot to the storage account 
    $destinationContext = New-AzureStorageContext –StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey  
    
    #Copy the snapshot to the storage account 
    Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $storageContainerName -DestContext $destinationContext -DestBlob $destinationVHDFileName
    

    关于这个脚本的更多信息,请参考这个link。


    更新:

    我们可以通过 Azure 门户创建镜像,如下所示:

    【讨论】:

    • 我仍然不确定创建自定义映像 (az lab vm custom-image) 将如何创建快照。他们不一样吗?
    • @PranavRaj 我们也可以使用门户创建图像,我会更新我的答案,请检查。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多