Resize a Linux virtual machine using CLI 2.0

After you provision a virtual machine (VM), you can scale the VM up or down by changing the VM size. In some cases, you must deallocate the VM first. You need to deallocate the VM if the desired size is not available on the hardware cluster that is hosting the VM. This article details how to resize a Linux VM with the Azure CLI 2.0.

Resize a VM

To resize a VM, you need the latest Azure CLI 2.0 installed and logged in to an Azure account using az login.

  1. View the list of available VM sizes on the hardware cluster where the VM is hosted with az vm list-vm-resize-options. The following example lists VM sizes for the VM named myVM in the resource group myResourceGroup region:

    az vm list-vm-resize-options --resource-group myResourceGroup --name myVM --output table
    
  2. If the desired VM size is listed, resize the VM with az vm resize. The following example resizes the VM named myVM to the Standard_DS3_v2 size:

    az vm resize --resource-group myResourceGroup --name myVM --size Standard_DS3_v2
    

    The VM restarts during this process. After the restart, your existing OS and data disks are remapped. Anything on the temporary disk is lost.

  3. If the desired VM size is not listed, you need to first deallocate the VM with az vm deallocate. This process allows the VM to then be resized to any size available that the region supports and then started. The following steps deallocate, resize, and then start the VM named myVM in the resource group named myResourceGroup:

    az vm deallocate --resource-group myResourceGroup --name myVM
    az vm resize --resource-group myResourceGroup --name myVM --size Standard_DS3_v2
    az vm start --resource-group myResourceGroup --name myVM
    

    Warning

    Deallocating the VM also releases any dynamic IP addresses assigned to the VM. The OS and data disks are not affected.

Next steps

For additional scalability, run multiple VM instances and scale out. For more information, see Automatically scale Linux machines in a Virtual Machine Scale Set.