如何获取Azure托管磁盘的VHD?

3

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

我找到的唯一方法是在 Azure 门户中打开磁盘,然后按“导出”以创建一个下载链接到 vhd 文件。但这种方法是不理想的。


需要osdisk的vhd文件吗?你的意思是要使用这个映像创建另一个虚拟机吗? - Jason Ye
3个回答

3
您可以使用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

0

请确保您的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

-2
对于托管磁盘,您不使用vhd。相反,对于磁盘部分,您可以使用以下模板。
"osDisk": {
    "osType": "Linux",
    "name": "[parameters('VMName')]",
    "createOption": "FromImage",
    "caching": "ReadWrite",
    "managedDisk": {
        "id": "ManagedDiskID"
    }
}

你需要通过托管磁盘 ID 而非 URI 引用磁盘。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接