How to expand virtual hard disks on a Linux VM with the Azure CLI
The default virtual hard disk size for the operating system (OS) is typically 30 GB on a Linux virtual machine (VM) in Azure. You can add data disks to provide for additional storage space, but you may also wish to expand an existing data disk. This article details how to expand managed disks for a Linux VM with the Azure CLI 2.0. You can also expand the unmanaged OS disk with the Azure CLI 1.0.
Warning
Always make sure that you back up your data before you perform disk resize operations. For more information, see Back up Linux VMs in Azure.
Expand Azure Managed Disk
Make sure that you have the latest Azure CLI 2.0 installed and logged in to an Azure account 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 with your own values. Example parameter names include myResourceGroup and myVM.
Operations on virtual hard disks cannot 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.
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 be 200Gb in size:
az disk update \ --resource-group myResourceGroup \ --name myDataDisk \ --size-gb 200Note
When you expand a managed disk, the updated size is mapped 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 disk partition and filesystem
To use the expanded disk, you need to expand the underlying partition and filesystem.
SSH to your VM with the appropriate credentials. You can obtain the public IP address of your VM with az vm show:
az vm show --resource-group myResourceGroup --name myVM -d --query [publicIps] --o tsvTo use the expanded disk, you need to expand the underlying partition and filesystem.
a. If already mounted, unmount the disk:
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 215Gb in size: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
quitWith the partition resized, verify the partition consistency with
e2fsck:sudo e2fsck -f /dev/sdc1Now resize the filesystem with
resize2fs:sudo resize2fs /dev/sdc1Mount the partition to the desired location, such as
/datadrive:sudo mount /dev/sdc1 /datadriveTo verify the OS 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 also add data disks to a Linux VM. For more information about disk encryption, see Encrypt disks on a Linux VM using the Azure CLI.


