none
Generate a VHD from a managed disk? RRS feed

  • Question

  • Hi all,

    When performing a restore of managed disks by going into the VM, then selecting “Create new” and then clicking the “Restore disks” option, then selecting the Storage Account I want to use as a staging location.

    It carries out a restore correctly and I can see it in the Disks pane. Azure gives it a predetermined name. I now want to deploy a new VM using these disks based on the json template Azure provides for me and changing the parameters as necessary.

    My main query is because the name of the restored managed disk is not in the correct name format (and I know that I cannot simply rename it), I want to add a new disk based on the storage blob vhd and name it correctly (I also know that vhd’s are not created when restoring managed disks).

    How can I obtain the vhd from my restored VM managed disk into a storage account to enable me to create a new managed disk?

    Thursday, September 12, 2019 9:34 AM

Answers

  • =======================
    You can simply copy the restored VHDs by following your naming convention and re-create the VM using PowerShell.

    $restoredDiskName = " "
    $newDiskName = " "
    $RgName = " "

    $restoredDisk = Get-AzureRmDisk -ResourceGroupName $RgName -DiskName $restoredDiskName
    $targetDiskConfig = New-AzureRmDiskConfig -SourceResourceId $restoredDisk.Id -Location $restoredDisk.Location -CreateOption Copy
    $targetDisk = New-AzureRmDisk -Disk $targetDiskConfig -DiskName $newDiskName -ResourceGroupName $RgName -Verbose
    ====================

    OR

    ====================
    If you want to export the restored managed disk to a storage account and then use your ARM template to create the VM, you can use the following PowerShell script

    $targetStorageAccountName = " "
    $targetStorageContainerName = " "
    $targetblobName = " "
    $targetStorageAccountKey = " "
    $sasExpiryDuration = " "
    $restoredDiskName = " "
    $rgName = " "


    $sas = Grant-AzureRmDiskAccess -ResourceGroupName $rgName -DiskName $restoredDiskName -DurationInSecond $sasExpiryDuration -Access Read
    $storageContext = New-AzureStorageContext -StorageAccountName $targetStorageAccountName -StorageAccountKey $targetStorageAccountKey
    Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $targetStorageContainerName -DestContext $storageContext -DestBlob $targetblobName
    ====================


    • Proposed as answer by Rohan Islam Thursday, September 12, 2019 11:05 AM
    • Marked as answer by mij2014 Thursday, September 12, 2019 12:43 PM
    Thursday, September 12, 2019 11:05 AM

All replies

  • =======================
    You can simply copy the restored VHDs by following your naming convention and re-create the VM using PowerShell.

    $restoredDiskName = " "
    $newDiskName = " "
    $RgName = " "

    $restoredDisk = Get-AzureRmDisk -ResourceGroupName $RgName -DiskName $restoredDiskName
    $targetDiskConfig = New-AzureRmDiskConfig -SourceResourceId $restoredDisk.Id -Location $restoredDisk.Location -CreateOption Copy
    $targetDisk = New-AzureRmDisk -Disk $targetDiskConfig -DiskName $newDiskName -ResourceGroupName $RgName -Verbose
    ====================

    OR

    ====================
    If you want to export the restored managed disk to a storage account and then use your ARM template to create the VM, you can use the following PowerShell script

    $targetStorageAccountName = " "
    $targetStorageContainerName = " "
    $targetblobName = " "
    $targetStorageAccountKey = " "
    $sasExpiryDuration = " "
    $restoredDiskName = " "
    $rgName = " "


    $sas = Grant-AzureRmDiskAccess -ResourceGroupName $rgName -DiskName $restoredDiskName -DurationInSecond $sasExpiryDuration -Access Read
    $storageContext = New-AzureStorageContext -StorageAccountName $targetStorageAccountName -StorageAccountKey $targetStorageAccountKey
    Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $targetStorageContainerName -DestContext $storageContext -DestBlob $targetblobName
    ====================


    • Proposed as answer by Rohan Islam Thursday, September 12, 2019 11:05 AM
    • Marked as answer by mij2014 Thursday, September 12, 2019 12:43 PM
    Thursday, September 12, 2019 11:05 AM
  • The 2nd solution will work for me.

    Awesome - thanks for the help.

    Thursday, September 12, 2019 12:43 PM