Convert Azure Managed Disk VM to Unmanged disk VM

As Microsoft offer managed and Unmanaged (storage account) disk and you create your VM either in Managed or in Unmanaged disk.

In Unmanaged  disk you have to manage the storage accounts, disk(VHDs) and the high availability of your VMs disk but managed disk you can avoid complex storage account, disks management and high availability (if VMs are part of AV sets).

You can convert unmanaged disk VM to managed disk VM using below command.

ConvertTo-AzureRmVMManagedDisk -ResourceGroupName <RGName>-VMName <VMName>

Refer this MS Link to convert unmanaged disk VM to managed disk VM.

But Converting VM from Managed disk to unmanaged, it’s not straight forward like unmanaged to managed.

So, Let discuss how we can convert that VM in Unmanaged disk VM if any VM running in Managed disk.

  1. Stop & Deallocate the VM from Azure Portal.
  2. Create a storage account also created container in that storage account.

Now you can run below PowerShell to export disk and import in newly created storage account.

# To Get the list of your managed disks
Get-AzureRmDisk | ft ResourceGroupName, Name, DiskSizeGB

# To Grant access to the disk for Export(SAS URL)
$sas = Grant-AzureRmDiskAccess -ResourceGroupName <RGName> -DiskName <DiskName> -DurationInSecond 3600 -Access Read

# Get storage account context
$destContext = New-AzureStorageContext –StorageAccountName <SAName>-StorageAccountKey <AccessKey>

# Start copy
$copyBlob = start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer <ContainerName>-DestContext $destContext -DestBlob <importeddiskname>.vhd

# To Check copy status
$copyBlob | Get-AzureStorageBlobCopyState

Once Copy status show success that means copy complete and you can go to Managed disk overview page on Azure Portal and click on Cancel Export to closed/Deactivate SAS token. Now you can use this copied VHD to create new VM (If OS Disk) or attach as data disk.

Conclusion-  As you can see coming from unmanaged to managed disk quite easy but if you are tying to revert from managed to unmanaged disk VM it’s not easy. This article is just an work around which we used to migrate VM from Managed disk to unmanaged disk.

 

Leave a comment