Before You Start
- Identify the device first: run
lsblk -fand note the disk, the partition number, and the file system type. Device names can change between boots, so check them again each time. - Take a snapshot or a backup: changing a partition table has no undo. See snapshot vs backup.
- Grow only: this guide makes partitions larger. Shrinking is a different and risky operation, and XFS cannot be shrunk in practice.
Check Whether cloud-init Already Did It
Many cloud images grow the root partition and file system by themselves: cloud-init's growpart and resizefs modules run at every boot by default. After a disk upgrade and a reboot, compare the disk and the file system:
lsblk /dev/vda
df -h /
If the root file system is already close to the disk size, there is nothing left to do. To see what cloud-init did, search its log:
sudo grep -iE 'growpart|resize' /var/log/cloud-init.log
How cloud-init works at boot is explained in what is cloud-init.
Step 1: Check That the Kernel Sees the New Size
lsblk
The disk line should show the new size. virtio disks normally report a resize on their own. For an sda disk, ask for a rescan with echo 1 | sudo tee /sys/class/block/sda/device/rescan. If the old size remains, reboot.
Step 2: Install growpart
| System | Command |
|---|---|
| Debian, Ubuntu | sudo apt install cloud-guest-utils |
| AlmaLinux, Rocky Linux | sudo dnf install cloud-utils-growpart |
Step 3: Grow the Partition
sudo growpart --dry-run /dev/vda 1
sudo growpart /dev/vda 1
Note the space: the disk and the partition number are two arguments. For NVMe, write /dev/nvme0n1 1. The dry run prints what would change. growpart extends a partition up to the end of the disk or the start of the next partition, so in practice only the last partition can grow. If it reports NOCHANGE, the partition already fills the space it can reach.
Step 4: Grow the File System
| File system | Command |
|---|---|
| ext4 | sudo resize2fs /dev/vda1 |
| XFS | sudo xfs_growfs / |
resize2fs takes the partition, xfs_growfs takes the mount point. Both grow a mounted file system without downtime; it is the same thing cloud-init does to the mounted root file system at boot. Check the type with df -T / if you are not sure.
With LVM in Between
If lsblk shows an lvm entry below the partition, there is one more layer. Grow the partition, then the physical volume, then the logical volume together with its file system:
sudo growpart /dev/vda 3
sudo pvresize /dev/vda3
sudo lvs
sudo lvextend -r -l +100%FREE /dev/VG_NAME/LV_NAME
Take the volume group and volume names from lvs. The -r option grows the ext4 or XFS file system in the same step. The layers are explained in LVM explained.
Check the Result
lsblk
df -h /
df should now show the larger size. For a second data disk the steps are the same with its own name, such as /dev/vdb 1 and /dev/vdb1. If the file system was created on the whole disk without a partition, skip growpart and run resize2fs or xfs_growfs directly.
When It Does Not Work
- Another partition sits after the one you want to grow: growpart cannot jump over it. Moving partitions is not a safe online task; restore to a fresh layout instead.
- MBR partition table: a partition on a
dostable cannot reach beyond 2 TiB, and growpart stops there with a warning. Larger disks need GPT. - resize2fs reports that the file system already has that size: the partition did not grow; repeat Step 3 and check its output.