Migrating Azure VMs | From Storage Accounts to Managed Disks

Microsoft now recommends using managed disks for all your Azure IaaS VMs. However we need to convert the existing VMs that use unmanaged disks to managed disks first in order to benefit from the performance improvements that managed disks offer.

Keep in Mind

  • The conversion process requires the VM to be restarted.
  • The process irreversible meaning taht you cannot go back to unmanaged disks once converted.
  • The conversion process deallocated the VMs and therefore you may lose any dynamic private IPs assigned to it. Therefore assign static private IPs  to the VMs before you start the conversion.
  • The source VHD and storage account used by the unmanaged disks are left over once migrated. You need to manually delete these.
  • There is a minimum version of the Azure VM agent required by the conversion process and you need to check that first.

Converting single VMs without an availability set

  • Following cmdlets deallocates the VM first.
$rgName = "myUnmanagedRG"
$vmName = "myUnmanagedVM"
Stop-AzureRmVM -ResourceGroupName $rgName -Name $vmName -Force
  • Following cmdlet  converts the unmanaged VM, including OS disk and any data disks, and starts the VM.
ConvertTo-AzureRmVMManagedDisk -ResourceGroupName $rgName -VMName $vmName

Converting VMs in an availability set

  • The process for this one is slightly different as you need to first convert the availability set to a managed availability set. Following cmdlets do the trick.
$rgName = 'myUnmanagedResourceGroup'
$avSetName = 'myUnmanagedAvailabilitySet'

$avSet = Get-AzureRmAvailabilitySet -ResourceGroupName $rgName -Name $avSetName
Update-AzureRmAvailabilitySet -AvailabilitySet $avSet -Sku Aligned
  • However you may encounter an error saying “The specified fault domain count 3 must fall in the range 1 to 2.”. This is beacuse the region where your availability set is may only 2 managed fault domains but the number of unmanaged fault domains is 3.  You need to update the fault domain to 2 and update SKU to Aligned as below:
$avSet.PlatformFaultDomainCount = 2
Update-AzureRmAvailabilitySet -AvailabilitySet $avSet -Sku Aligned
  • Following cmdlets deallocate and convert each VM in the availability set and restarts them automatically.
$avSet = Get-AzureRmAvailabilitySet -ResourceGroupName $rgName -Name $avSetName

foreach($vmInfo in $avSet.VirtualMachinesReferences)
 $vm = Get-AzureRmVM -ResourceGroupName $rgName | Where-Object {$_.Id -eq $vmInfo.id}
 Stop-AzureRmVM -ResourceGroupName $rgName -Name $vm.Name -Force
 ConvertTo-AzureRmVMManagedDisk -ResourceGroupName $rgName -VMName $vm.Name