How to convert a Linux VM from unmanaged disks to Azure Managed Disks

If you have existing Linux VMs in Azure that use unmanaged disks in storage accounts and you want those VMs to be able to take advantage of managed disks, you can convert the VMs. This process converts both the OS disk and any attached data disks. The conversion process requires a restart of the VM, so schedule the migration of your VMs during a pre-existing maintenance window. The migration process is not reversible. Be sure to test the migration process by migrating a test virtual machine before performing the migration in production.

Important

During the conversion, you deallocate the VM. The VM receives a new IP address when it is started after the conversion. If you have a dependency on a fixed IP, use a reserved IP.

You cannot convert an unmanaged disk into a managed disk if the unmanaged disk is in a storage account that is, or at any time has been, encrypted using Azure Storage Service Encryption (SSE). The following steps detail how to convert unmanaged disks that are, or have been, in an encrypted storage account:

  • Copy the virtual hard disk (VHD) with az storage blob copy start to a storage account that has never been enabled for Azure Storage Service Encryption.
  • Create a VM that uses managed disks and specify that VHD file during creation with az vm create, or
  • Attach the copied VHD with az vm disk attach to a running VM with managed disks.

Convert VM to Azure Managed Disks

This section covers how to convert your existing Azure VMs from unmanaged disks to managed disks. You can use this process to convert from Premium (SDD) unmanaged disks to Premium managed disks, or from standard (HDD) unmanaged disks to standard managed disks.

Important

After performing the following procedure, there is a single block blob that remains in the default vhds container. The name of the file is “VMName.xxxxxxx.status”. Do not delete this remaining status object. Future work should address this issue.

  1. Deallocate the VM with az vm deallocate. The following example deallocates the VM named myVM in the resource group named myResourceGroup:

     az vm deallocate --resource-group myResourceGroup --name myVM
    
  2. Convert the VM to managed disks with az vm convert. The following process converts the VM named myVM including the OS disk and any data disks:

     az vm convert --resource-group myResourceGroup --name myVM
    
  3. Start the VM after the conversion to managed disks with az vm start. The following example starts the VM named myVM in the resource group named myResourceGroup.

     az vm start --resource-group myResourceGroup --name myVM
    

Convert VM in an availability set to managed disks

If the VMs that you want to convert to managed disks are in an availability set, you first need to convert the availability set to a managed availability set.

All VMs in the availability set must be deallocated before you convert the availability set. Plan to convert all VMs to managed disks once the availability itself has been converted to a managed availability set. You can then start all the VMs and continue operating as normal.

  1. List all VMs in an availability set with az vm availability-set list. The following example lists all VMs in the availability set named myAvailabilitySet in the resource group named myResourceGroup:

     az vm availability-set show --resource-group myResourceGroup \
         --name myAvailabilitySet --query [virtualMachines[*].id] --output table
    
  2. Deallocate all the VMs with az vm deallocate. The following example deallocates the VM named myVM in the resource group named myResourceGroup:

     az vm deallocate --resource-group myResourceGroup --name myVM
    
  3. Convert the availability set with az vm availability-set convert. The following example converts the availability set named myAvailabilitySet in the resource group named myResourceGroup:

     az vm availability-set convert --resource-group myResourceGroup \
         --name myAvailabilitySet
    
  4. Convert all the VMs to managed disks with az vm convert. The following process converts the VM named myVM including the OS disk and any data disks:

     az vm convert --resource-group myResourceGroup --name myVM
    
  5. Start all the VMs after the conversion to managed disks with az vm start. The following example starts the VM named myVM in the resource group named myResourceGroup.

     az vm start --resource-group myResourceGroup --name myVM
    

Next steps

For more information about storage options, see Azure Managed Disks overview