Cloud block storage & online resizing guide
In cloud environments (Amazon Web Services, Google Cloud Platform, Microsoft Azure, and private OpenStack/KVM clusters), storage capacity must scale dynamically. Expanding a virtual disk is a three-layer procedure: notifying the Linux kernel of the hardware size change, extending the partition boundary, and expanding the filesystem.
The three layers of storage expansion
| Layer | Component | Execution Command / Mechanism |
|---|---|---|
| Layer 1: Block Device | Kernel Driver (NVMe / SCSI / VirtIO) | Cloud API resize + echo 1 > /sys/class/block/sdX/device/rescan (Auto-detected on modern NVMe). |
| Layer 2: Partition / LVM | GPT / MBR / LVM Physical Volume | growpart /dev/nvme0n1 1 and pvresize /dev/nvme0n1p2. |
| Layer 3: Filesystem | ext4, XFS, or Btrfs | resize2fs /dev/nvme0n1p1 or xfs_growfs /mountpoint. |
Standard online expansion procedure (Step-by-step)
1. Expand disk in cloud console / CLI
Increase the volume size (e.g. from 50 GB to 200 GB) in your cloud provider:
# AWS CLI example
aws ec2 modify-volume --volume-id vol-0123456789abcdef0 --size 200
# Google Cloud CLI example
gcloud compute disks resize disk-prod-01 --size=200GB --zone=us-central1-a
# Azure CLI example
az disk update --name myDataDisk --resource-group myRG --size-gb 2002. Force kernel device rescan (SCSI / VirtIO drives)
NVMe drives (/dev/nvme*) detect capacity changes automatically. For SCSI/SATA virtual disks (/dev/sda):
# Trigger kernel rescan of target block device
echo 1 | sudo tee /sys/class/block/sda/device/rescan
# Verify new capacity is recognized by kernel
lsblk3. Extend partition boundaries with growpart
Install cloud-guest-utils if not present, then expand the target partition:
# Install growpart utility
sudo apt install cloud-guest-utils # or dnf install cloud-utils-growpart
# Grow partition 1 on device /dev/nvme0n1 (Note the space between device and partition number)
sudo growpart /dev/nvme0n1 1
# Verify partition 1 now reflects full disk capacity
lsblk /dev/nvme0n14. Expand filesystem online
# For Ext4 filesystems:
sudo resize2fs /dev/nvme0n1p1
# For XFS filesystems (pass the active mount point):
sudo xfs_growfs /
# For Btrfs filesystems:
sudo btrfs filesystem resize max /Expanding LVM volumes in the cloud
If your cloud instance utilizes LVM:
# 1. Expand the underlying partition
sudo growpart /dev/sda 2
# 2. Resize the LVM Physical Volume
sudo pvresize /dev/sda2
# 3. Extend the Logical Volume and filesystem simultaneously (-r flag handles fs resize)
sudo lvextend -r -l +100%FREE /dev/vg_main/lv_rootAutomated resizing via cloud-init
Modern Linux cloud images automatically expand the root partition on boot via cloud-init:
# /etc/cloud/cloud.cfg configuration snippet
growpart:
mode: auto
devices: ['/']
ignore_growroot_disabled: false
resize_rootfs: trueFrequently asked questions
Do you need to unmount the filesystem or reboot the VM to resize a cloud disk?
What does growpart do under the hood?
growpart (part of the cloud-guest-utils package) reads the partition table (MBR or GPT), relocates the backup GPT header to the end of the enlarged physical disk, and rewrites the ending sector of the target partition to consume all contiguous unallocated space.
Why does xfs_growfs take a mount point while resize2fs takes a device path?
xfs_growfs requires the target to be a mount point (e.g. xfs_growfs /srv/data) because XFS interacts with the live active filesystem driver. Conversely, resize2fs takes the underlying block device path (e.g. resize2fs /dev/nvme0n1p1).
How do you resize an LVM volume on cloud storage?
First grow the partition with growpart, then expand the LVM Physical Volume with pvresize /dev/sda2, extend the Logical Volume with lvextend -r -l +100%FREE /dev/vg_main/lv_root (the -r flag automatically resizes ext4/XFS filesystems in one step).