Convert a VM disk from managed to unmanaged - addycluri/Azure GitHub Wiki

There can be many situations where you are required to convert a disk attached to a VM from Managed-->unmanaged. Some of the common reasons being:

  • Migrate the VM (and all associated resources) to another Azure subscription. Explained here
  • Application compatibility / custom usage

This wiki particularly focuses on such a conversion process using a powershell script called Convert-ManagedDiskToUnManaged. Upon successful completion, the managed disks attached to the VM will be converted to un-managed disks (Blob VHD) and the VM restored. Please note that this process requires VM downtime somplan for it accordingly

Conversion Workflow

This script completes the disk conversion process and also recreates the VM with the latest converted disks as summarized below.

  • Get the current VMObject
  • Delete the current VM (does not destroy the current configuration and/or disks) to release the locks/Leases on the disks.
  • Create a temporary storage account to store the VHD's in the same resource group where the OS disk currently resides.
  • COPY all OS & Data disks to the temp storage account
  • update the VMObject with the new VHD URI's
  • re-create the VM using VMobject

Execution Steps

Follow the steps below to access Convert-ManagedDiskToUnManaged and execute the disk conversion process.

  • Download and import the Powershell Module locally using the instructions provided - here

  • Check the script details using Get-Help Convert-ManagedDiskToUnManaged -Full before proceeding.

  • Open powershell and Login to your azure account using Connect-AzureRmAccount -TenantId "GUID" -SubscriptionId "GUID" (where the VMs with managed disks currently live)

  • As a best practice, i always recommend to save the existing VM object to help with restoring it to the original configuration just in case there was any error encountered with the script. Update the $variables first and paste them into powershell.

    • $rgname = "your resource group name"
    • $vmname = "your VM name"
    • Get the current VMobject using <$vmObject = Get-AzureRmVm -ResourceGroupName $rgname -Name $vmname>
  • We have the entire VM configuration saved to $vmobject so, we can now proceed with the disk conversion process

  • Before you proceed, please ensure that all application owners & stakeholders are updated since the VM in question will have doowntime till the script execution is completed

  • To start the disk conversion, in powershell execute Convert-ManagedDiskToUnManaged -VMName $vmname -ResourceGroupName $rgname -verbose

  • For any reason if there is an error, you can restore the VM using New-AzureRmVm -VM $vmobject -ResourceGroupName $vmobject.ResourceGroupName -Location $vmobject.Location

⚠️ **GitHub.com Fallback** ⚠️