Extend a Partition and Filesystem on a Linux VPS

3 min
VPS/VDS Hosting

After a disk upgrade on your VPS Linux Infrawire, the virtual disk is bigger but the partition and the filesystem still have their old size. You have to grow both by hand, and it can be done live, without unmounting the root filesystem.

This guide covers plain partitions (ext4 and XFS) and LVM setups on Ubuntu 24.04, Debian 12, AlmaLinux 9 and Rocky 9.

📋 Prerequisites

  • A VPS whose disk has already been enlarged (the new size must show up in lsblk)
  • Root SSH access (IP and root password are available in your client area)
  • A recent backup of your important data

1. Back up before touching partitions

Resizing a mounted ext4 or XFS filesystem is routine, but a mistake in the partition table can destroy data. Save what matters first:

Bash
# Archive the data you cannot lose tar -czf /root/backup-etc.tar.gz /etc rsync -avz /var/www/ USER@BACKUP_HOST:/backups/www/ # Save the partition table (useful to restore it) sfdisk -d /dev/vda > /root/vda-partition-table.txt

2. Identify the disk, partition and filesystem

Bash
lsblk -f df -hT /

Typical output: disk vda of 80G, partition vda1 of 40G mounted on /, filesystem ext4 or xfs. If the root is on /dev/mapper/..., you are on LVM: see section 5. Disk names can also be sda or nvme0n1 (partitions then end in p1).

3. Grow the partition with growpart

Install the tool. On Ubuntu and Debian the package is cloud-guest-utils, on AlmaLinux and Rocky it is cloud-utils-growpart:

Bash
# Ubuntu / Debian apt update && apt install -y cloud-guest-utils # AlmaLinux / Rocky dnf install -y cloud-utils-growpart

Then grow partition number 1 of disk /dev/vda (note the space between the disk and the number):

Bash
growpart /dev/vda 1

If the message says NOCHANGE, the partition already uses all the space. Some images also have a small partition after the root one (swap, for example): in that case growpart cannot extend the root partition and you must remove or move that partition first.

Check that the kernel sees the new size:

Bash
lsblk /dev/vda # If the old size is still shown: partprobe /dev/vda

4. Grow the filesystem

Use the command matching your filesystem type (shown by lsblk -f).

For ext4:

Bash
resize2fs /dev/vda1

For XFS (default on AlmaLinux and Rocky). The argument is the mount point, not the device, and XFS can only grow, never shrink:

Bash
xfs_growfs /

5. LVM case: pvresize and lvextend

When the root logical volume sits on LVM, there is one more layer to grow: partition, then physical volume, then logical volume, then filesystem.

Bash
lsblk pvs && vgs && lvs # 1. Grow the partition that holds the physical volume (here vda3) growpart /dev/vda 3 # 2. Tell LVM the physical volume is bigger pvresize /dev/vda3 # 3. Extend the logical volume and its filesystem in one go (-r) lvextend -r -l +100%FREE /dev/mapper/VG_NAME-LV_NAME

The -r option calls the right tool (resize2fs or xfs_growfs) for you. Adapt VG_NAME-LV_NAME to the output of lvs, for example /dev/ubuntu-vg/ubuntu-lv. To use only part of the free space, replace -l +100%FREE with -L +10G.

6. Verify the result

Bash
df -h / lsblk

The Size column of df -h must now match the new capacity, and lsblk must show the partition filling the disk. No reboot is needed. Applications keep running during the whole operation.

🛠️ Troubleshooting

growpart: command not found: the package is not installed. Install cloud-guest-utils (apt) or cloud-utils-growpart (dnf).

NOCHANGE: partition 1 could not be grown: either the disk was not really enlarged (compare lsblk with what you ordered), or another partition sits right after the one you want to grow. Check with fdisk -l /dev/vda.

resize2fs: Bad magic number in super-block: the filesystem is probably XFS, not ext4. Run lsblk -f and use xfs_growfs / instead.

xfs_growfs: / is not a mounted XFS filesystem: you passed a device name, or the filesystem is ext4. Pass the mount point and check the type first.

lvextend reports no free extents: you skipped growpart or pvresize. Run pvs and check the PFree column.


🎉 Your extra disk space is now usable: no reboot, no downtime, and df -h proves it!

Stay up to date with the latest offers, discounts and special promotions.

View promotions

We use cookies

We use analytics cookies to improve your experience on our site. No data is sold to third parties. Learn more in our privacy policy.