【问题标题】:How to get the VHD of an Azure managed disk?如何获取 Azure 托管磁盘的 VHD?
【发布时间】:2017-07-12 08:19:28
【问题描述】:

我创建了一个带有托管磁盘的 VM。默认情况下,托管磁盘不再存储到 blob 存储中。问题是我现在需要 osdisk 的 vhd 文件,但我找不到合适的方法来检索它。

我找到的唯一方法是在 azure 门户中打开磁盘,然后按导出以创建指向 vhd 文件的下载链接。这种方法是不受欢迎的。

【问题讨论】:

  • 需要osdisk的vhd文件吗?您的意思是要使用此映像创建另一个 VM?

标签: azure virtual-machine vhd azureportal


【解决方案1】:

您可以使用 PowerShell 将托管磁盘的 VHD 复制/导出到存储帐户

#Connect to Azure and set your azure subscription

#Declare Variables
$resourceGroupName = 'xxxxx-rg'
$snapshotName = 'xxxxxx.md'
$resourceGroupNameStorageAccount = 'xxxx-rg'
$storageAccountName = 'xxxx-storage'
$storageContainerName = 'xxxxx'
$destinationVHDFileName = 'xxxxxx.vhd'

#Get the Storage Account Key of the Destination Storage Account
$storageAccountKey = Get-AzStorageAccountKey -resourceGroupName $resourceGroupNameStorageAccount -AccountName $storageAccountName

#Generate the SAS for the snapshot
$sas = Grant-AzSnapshotAccess -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName -DurationInSecond 3600 -Access Read

#Create the context of the destination storage account for the snapshot
$destinationContext = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey ($storageAccountKey).Value[0]

#Copy the snapshot to the destination Storage Account
Start-AzStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $storageContainerName -DestContext $destinationContext -DestBlob $destinationVHDFileName

【讨论】:

    【解决方案2】:

    确保您的 AzureRM Powershell 模块是最新的:

    Install-Module AzureRM -allowclobber -force
    

    您的 Set-AzureRMVMOSDisk 命令现在应该具有 -ManagedDiskID。只需输入托管磁盘的资源 ID 即可。

    例子

    $NewVM = New-AzureRMVMConfig -VMName VMName - VMSize "Standard_A1_V2"
    Set-AzureRMVMOSDisk -VM $NewVM -Name "DiskName" -CreateOption Attach -Caching ReadWrite -Windows -ManagedDiskID "ManagedDiskResourceID"
    New-AzureRmVM -ResourceGroupName "ResourceGroupName" -VM $NewVM -Location CanadaEast
    

    【讨论】:

      【解决方案3】:

      对于托管磁盘,您不使用 vhd。相反,对于磁盘部分,您使用这样的模板

      "osDisk": {
          "osType": "Linux",
          "name": "[parameters('VMName')]",
          "createOption": "FromImage",
          "caching": "ReadWrite",
          "managedDisk": {
              "id": "ManagedDiskID"
          }
      }
      

      您通过托管磁盘 ID 而不是 uri 引用磁盘

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-07-03
        • 2019-02-02
        • 2017-07-08
        • 2019-07-03
        • 2017-11-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多