Home / Azure

AzureRunbookBeginner

Customer says the Azure VM's C: or / drive is full: expanding the OS disk

Grow an Azure managed OS disk, then extend the partition and filesystem on Windows and Linux, with the checks to run before and after.

Deepak Bhardwaj2 min read

Applies toAzure managed disks, Windows Server 2016+, Ubuntu/RHEL with ext4 or XFS

Before you expand

  1. Find what's using the space first. Expanding a disk to hide a runaway log just delays the next ticket.
    • Windows: Get-ChildItem C:\ -Recurse -ErrorAction SilentlyContinue | Sort-Object Length -Descending | Select-Object -First 20 FullName, Length, or use TreeSize/WinDirStat.
    • Linux: sudo du -xh / --max-depth=2 | sort -h | tail -20
  2. Snapshot the disk. It's quick and gives you a way back.
RG=rg-prod; VM=vm-app-01
DISK=$(az vm show -g $RG -n $VM --query "storageProfile.osDisk.managedDisk.id" -o tsv)
az snapshot create -g $RG -n "${VM}-os-pre-expand-$(date +%F)" --source $DISK

Grow the managed disk

Most disk types can be expanded without deallocating (live resize), as long as the disk isn't larger than 4 TiB before or after. If live resize isn't supported for your configuration, deallocate first.

az disk update --ids $DISK --size-gb 256
az disk show --ids $DISK --query "{size:diskSizeGb, state:diskState}" -o table

Warning

Disks can only grow, never shrink. Choose the size deliberately, and remember that a bigger Premium SSD also moves into a higher performance tier.

Extend the partition: Windows

# Rescan, then grow C: to all available space
"rescan" | diskpart
$max = (Get-PartitionSupportedSize -DriveLetter C).SizeMax
Resize-Partition -DriveLetter C -Size $max
Get-Volume -DriveLetter C

If Resize-Partition fails, a recovery partition sits directly after C:. You can move or delete it (after a backup) or extend through Disk Management. This is common on older images.

Extend the partition: Linux

lsblk                                   # confirm the disk shows the new size
sudo growpart /dev/sda 1                # grow partition 1 (check the number with lsblk)
# ext4
sudo resize2fs /dev/sda1
# XFS (RHEL default) - pass the mount point
sudo xfs_growfs /
df -h /

With LVM (common on RHEL images), grow the physical volume, then the logical volume and the filesystem together:

sudo growpart /dev/sda 4
sudo pvresize /dev/sda4
sudo lvextend -r -l +100%FREE /dev/mapper/rootvg-rootlv   # -r also resizes the filesystem

Verify and close the ticket

  • df -h or Get-Volume shows the new free space.
  • The application is writing again. Check its logs for "disk full" errors stopping after the change.
  • Delete the snapshot once the change is confirmed stable, because it costs money.

Prevent it next time

  • Alert at 85% used on every volume (VM insights LogicalDisk / FreeSpacePercentage).
  • Move logs and data to data disks so the OS disk only holds the OS.
  • Set up log rotation (logrotate on Linux, IIS log cleanup on Windows) as part of the image.