Convert a Linux virtual machine from unmanaged disks to managed disks

If you have existing Linux virtual machines (VMs) that use unmanaged disks, you can convert the VMs to use managed disks through the Azure Managed Disks service. This process converts both the OS disk and any attached data disks.

This article shows you how to convert VMs by using the Azure CLI. If you need to install or upgrade it, see Install Azure CLI 2.0.

Before you begin

  • If the unmanaged disk is in a storage account previously encrypted through Azure Storage Service Encryption, you can't convert it to a managed disk. For steps to copy and use these virtual hard disks (VHDs) in managed disks, see the Managed disks and Azure Storage Service Encryption section later in this article.

  • The conversion requires a restart of the VM, so schedule the migration of your VMs during a pre-existing maintenance window.

  • The conversion is not reversible.

  • Be sure to test the conversion. Migrate a test virtual machine before you perform the migration in production.

  • During the conversion, you deallocate the VM. The VM receives a new IP address when it is started after the conversion. If needed, you can assign a static IP address to the VM.

  • The original VHDs and the storage account used by the VM before conversion are not deleted. They continue to incur charges. To avoid being billed for these artifacts, delete the original VHD blobs after you verify that the conversion is complete.

Convert single-instance VMs

This section covers how to convert single-instance Azure VMs from unmanaged disks to managed disks. (If your VMs are in an availability set, see the next section.) You can use this process to convert the VMs from premium (SSD) unmanaged disks to premium managed disks, or from standard (HDD) unmanaged disks to standard managed disks.

  1. Deallocate the VM by using 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 by using 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 by using 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 VMs in an availability set

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 after the availability set itself has been converted to a managed availability set. Then, start all the VMs and continue operating as normal.

  1. List all VMs in an availability set by using 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 by using 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 by using 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 by using 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 by using 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
    

Managed disks and Azure Storage Service Encryption

You can't use the preceding steps to convert an unmanaged disk into a managed disk if the unmanaged disk is in a storage account that has ever been encrypted through Azure Storage Service Encryption. The following steps detail how to copy and use unmanaged disks that have been in an encrypted storage account:

  1. Copy the VHD by using az storage blob copy start to a storage account that has never been enabled for Azure Storage Service Encryption.

  2. Use the copied VM in one of the following ways:

    • Create a VM that uses managed disks and specify that VHD file during creation by using az vm create.

    • Attach the copied VHD by using az vm disk attach to a running VM that uses managed disks.

Next steps

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