Expand virtual hard disks on a Linux VM with the Azure CLI
Applies to: ✔️ Linux VMs ✔️ Flexible scale sets
This article describes how to expand managed disks for a Linux virtual machine (VM) with the Azure CLI. You can add data disks to provide for additional storage space, and you can also expand an existing data disk. The default virtual hard disk size for the operating system (OS) is typically 30 GB on a Linux VM in Azure.
Warning
Always make sure that your filesystem is in a healthy state, your disk partition table type will support the new size, and ensure your data is backed up before you perform disk resize operations. For more information, see the Azure Backup quickstart.
Expand an Azure Managed Disk
Resize without downtime (preview)
You can now resize your managed disks without deallocating your VM.
The preview for this has the following limitations:
- Currently only available in the following regions:
- Australia Central
- Brazil South
- Canada Central
- Central India
- East Asia
- France Central
- Germany West Central
- Japan East
- Japan West
- North Europe
- Norway West
- South Africa North
- UK South
- West India
- Only supported for data disks.
- Disks smaller than 4 TiB can't be expanded to 4 TiB or larger without downtime.
- If you increase the size of a disk to 4 TiB or larger, it can then be expanded without downtime.
- Install and use either:
- The latest Azure CLI
- The latest Azure PowerShell module
- The Azure portal if accessed through https://aka.ms/iaasexp/DiskLiveResize
- Or an Azure Resource Manager template with an API version that's 2021-04-01 or newer.
To register for the feature, use the following command:
az feature register --namespace Microsoft.Compute --name LiveResize
It may take a few minutes for registration to take complete. To confirm that you've registered, use the following command:
az feature show --namespace Microsoft.Compute --name LiveResize
Get started
Make sure that you have the latest Azure CLI installed and are signed in to an Azure account by using az login.
This article requires an existing VM in Azure with at least one data disk attached and prepared. If you do not already have a VM that you can use, see Create and prepare a VM with data disks.
In the following samples, replace example parameter names such as myResourceGroup and myVM with your own values.
Important
If you've enabled LiveResize and your disk meets the requirements in Resize without downtime (preview), you can skip step 1 and 3.
Operations on virtual hard disks can't be performed with the VM running. Deallocate your 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 myVMNote
The VM must be deallocated to expand the virtual hard disk. Stopping the VM with
az vm stopdoes not release the compute resources. To release compute resources, useaz vm deallocate.View a list of managed disks in a resource group with az disk list. The following example displays a list of managed disks in the resource group named myResourceGroup:
az disk list \ --resource-group myResourceGroup \ --query '[*].{Name:name,Gb:diskSizeGb,Tier:accountType}' \ --output tableExpand the required disk with az disk update. The following example expands the managed disk named myDataDisk to 200 GB:
az disk update \ --resource-group myResourceGroup \ --name myDataDisk \ --size-gb 200Note
When you expand a managed disk, the updated size is rounded up to the nearest managed disk size. For a table of the available managed disk sizes and tiers, see Azure Managed Disks Overview - Pricing and Billing.
Start your VM 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
Expand a disk partition and filesystem
To use an expanded disk, expand the underlying partition and filesystem.
SSH to your VM with the appropriate credentials. You can see the public IP address of your VM with az vm show:
az vm show --resource-group myResourceGroup --name myVM -d --query [publicIps] --output tsvExpand the underlying partition and filesystem.
a. If the disk is already mounted, unmount it:
sudo umount /dev/sdc1b. Use
partedto view disk information and resize the partition:sudo parted /dev/sdcView information about the existing partition layout with
print. The output is similar to the following example, which shows the underlying disk is 215 GB:GNU Parted 3.2 Using /dev/sdc1 Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) print Model: Unknown Msft Virtual Disk (scsi) Disk /dev/sdc1: 215GB Sector size (logical/physical): 512B/4096B Partition Table: loop Disk Flags: Number Start End Size File system Flags 1 0.00B 107GB 107GB ext4c. Expand the partition with
resizepart. Enter the partition number, 1, and a size for the new partition:(parted) resizepart Partition number? 1 End? [107GB]? 215GBd. To exit, enter
quit.With the partition resized, verify the partition consistency with
e2fsck:sudo e2fsck -f /dev/sdc1Resize the filesystem with
resize2fs:sudo resize2fs /dev/sdc1Mount the partition to the desired location, such as
/datadrive:sudo mount /dev/sdc1 /datadriveTo verify the data disk has been resized, use
df -h. The following example output shows the data drive /dev/sdc1 is now 200 GB:Filesystem Size Used Avail Use% Mounted on /dev/sdc1 197G 60M 187G 1% /datadrive
Next steps
- If you need additional storage, you can also add data disks to a Linux VM.
- For more information about disk encryption, see Azure Disk Encryption for Linux VMs.