For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /general/disk_management/How_to_Expand_Disk_via_Growpart_and_Resize2fs.md.

How to Expand Disk via Growpart and Resize2fs

This guide shows how to expand a disk from the command line using growpart and resize2fs.

Warning

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:

fdisk -l

Output:

root@vps:~# fdisk -l
...
Disk /dev/vda: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: CA147C86-F18D-46FC-A68E-BC0F0EFB040E

Device       Start      End  Sectors  Size Type
/dev/vda1     2048     4095     2048    1M BIOS boot
/dev/vda2     4096  1052671  1048576  512M Linux swap
/dev/vda3  1052672 52428766 51376095 24.5G Linux filesystem

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:

growpart /dev/vda X

Replace X with the actual partition number. Here the partition is /dev/vda3, so X is 3:

growpart /dev/vda 3

Output:

root@vps:~# growpart /dev/vda 3
CHANGED: partition=3 start=1052672 old: size=51376095 end=52428767 new: size=208662495 end=209715167

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.

resize2fs /dev/vdaX

Since the root partition is /dev/vda3, replace X with 3:

resize2fs /dev/vda3

Output:

root@vps:~# resize2fs /dev/vda3
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/vda3 is mounted on /; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 13
The filesystem on /dev/vda3 is now 26082811 (4k) blocks long.

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:

fdisk -l

Output:

root@vps:~# fdisk -l
...
Disk /dev/vda: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: CA147C86-F18D-46FC-A68E-BC0F0EFB040E

Device       Start       End   Sectors  Size Type
/dev/vda1     2048      4095      2048    1M BIOS boot
/dev/vda2     4096   1052671   1048576  512M Linux swap
/dev/vda3  1052672 209715166 208662495 99.5G Linux filesystem

You have now expanded the disk using growpart and resize2fs.