How to Expand Disk via Growpart and Resize2fs
This guide shows how to expand a disk from the command line using growpart and resize2fs.
Before proceeding, make sure you have a backup of your important data. Resizing disks can be risky if not done correctly. Also make sure you have identified the correct disk and partition, because expanding the wrong partition can result in data loss.
Expand the Disk
Check the current disk usage
Check the current disk usage and available space with the fdisk -l command:
Output:
In this output, /dev/vda3 is the root partition and the one we want to resize. The /dev/vda disk shows 100 GB, while the root partition /dev/vda3 is still only about 25 GB.
Expand the partition with growpart
Use growpart to expand the partition so it uses the remaining space on the disk:
Replace X with the actual partition number. Here the partition is /dev/vda3, so X is 3:
Output:
Resize the filesystem
Now resize the filesystem so it uses the newly allocated space. resize2fs works with ext2, ext3 and ext4 filesystems, so make sure your filesystem is supported before running it.
Since the root partition is /dev/vda3, replace X with 3:
Output:
The partition and the ext4 filesystem now use the available disk space.
Verify the expansion
Run fdisk -l again to confirm the partition is now using the additional space:
Output:
You have now expanded the disk using growpart and resize2fs.

