Resize a Virtual Machine

This article explains how to resize a virtual machine (VM) in Azure. Resizing a VM involves changing its size, which affects its CPU, memory, and other resources. This is often done to accommodate changing workload demands or to optimize costs.

Important: Resizing a VM requires stopping (deallocating) the VM first. You cannot resize a running VM.

When to Resize a VM

  • Your application requires more or less CPU and memory.
  • You want to reduce costs by moving to a smaller VM size.
  • You need to use specific VM features available only in certain size families.

Prerequisites

  • An existing Azure Virtual Machine.
  • Permissions to manage the VM (e.g., Contributor role on the VM or its resource group).

Steps to Resize a VM

Using the Azure Portal

  1. Navigate to your virtual machine in the Azure portal.
  2. In the Overview blade, click the Stop button to deallocate the VM. Confirm the action when prompted. Azure Portal Stop VM Button
  3. Once the VM is deallocated (its status will show as 'Stopped (deallocated)'), click on Size in the Settings section of the VM blade.
  4. A list of available VM sizes will appear. You can filter and search for the desired size. Select the new size for your VM and click Resize. Azure Portal VM Size Selection
  5. After the resize operation is complete, you can start the VM again from the Overview blade.

Using Azure CLI

You can also resize a VM using the Azure Command-Line Interface (CLI). First, stop the VM:

az vm deallocate --resource-group MyResourceGroup --name MyVM

Then, resize the VM. You can list available sizes for a location with az vm list-sizes --location eastus --output table.

az vm resize --resource-group MyResourceGroup --name MyVM --size Standard_D4s_v5

Finally, start the VM:

az vm start --resource-group MyResourceGroup --name MyVM

Using Azure PowerShell

Using Azure PowerShell, first stop the VM:

Stop-AzVM -ResourceGroupName "MyResourceGroup" -Name "MyVM" -Force

Then, resize the VM. You can list available sizes with Get-AzVMSize -Location "eastus".

$VM = Get-AzVM -ResourceGroupName "MyResourceGroup" -Name "MyVM"
$VM.HardwareProfile.VmSize = "Standard_D4s_v5"
Update-AzVM -VM $VM -ResourceGroupName "MyResourceGroup"

Finally, start the VM:

Start-AzVM -ResourceGroupName "MyResourceGroup" -Name "MyVM"

Important Considerations

  • Data Disks: Resizing a VM does not affect its data disks.
  • Ephemeral OS Disks: If your VM uses an ephemeral OS disk, resizing may lead to data loss on the OS disk if it contains important data. It's recommended to use managed disks for production workloads.
  • Availability Sets: If your VM is part of an Availability Set, you must resize all VMs in that set to the same new size to maintain the availability guarantees.
  • Proximity Placement Groups: If your VM is in a Proximity Placement Group, you can only resize it to a size within the same "hardware generation" or family.
  • Cost: Larger VM sizes generally incur higher costs. Choose a size that balances performance needs with budget constraints.
  • Supported Sizes: Not all VM sizes are available in all Azure regions.

For more detailed information on VM sizes and their capabilities, please refer to the Azure VM Sizes documentation.