KVM

Extend Root Filesystem Using LVM on Linux

Running out of disk space on a root filesystem is one of those problems that every sysadmin hits eventually. If your system uses LVM (Logical Volume Manager), you are in a good position – LVM was designed to make this kind of operation straightforward, even on a live system. This guide covers extending the root filesystem on RHEL 10 and Ubuntu 24.04 using LVM, including adding new disks, growing existing partitions on cloud VMs without a reboot, and extending swap space.

Prerequisites

  • A Linux system (RHEL 10 or Ubuntu 24.04) with LVM configured on the root filesystem
  • Root or sudo access
  • A new disk attached to the system, or unallocated space on an existing disk
  • A basic understanding of partitions, physical volumes, volume groups, and logical volumes

Step 1 – Check Current LVM Layout

Before making any changes, get a clear picture of your current storage layout. Run these commands to understand what you are working with.

Check physical volumes:

sudo pvs

Sample output:

  PV         VG        Fmt  Attr PSize   PFree
  /dev/sda3  rhel      lvm2 a--  <49.00g    0

Check volume groups:

sudo vgs

Sample output:

  VG   #PV #LV #SN Attr   VSize   VFree
  rhel   1   2   0 wz--n- <49.00g    0

Check logical volumes:

sudo lvs

Sample output:

  LV   VG   Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root rhel -wi-ao---- <45.00g
  swap rhel -wi-ao----   4.00g

Also check the current disk usage and filesystem type:

df -hT /

Sample output:

Filesystem           Type  Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root xfs    45G   38G  7.0G  85% /

Note the filesystem type. RHEL uses xfs by default, while Ubuntu uses ext4. The resize command differs between them.

Step 2 - Add a New Disk and Create a Physical Volume

Attach a new disk to your server. On a hypervisor or cloud platform, add a new virtual disk. On bare metal, install a physical disk and verify the system detects it.

List all block devices to confirm the new disk is visible:

lsblk

You should see the new disk, for example /dev/sdb, with no partitions on it. Initialize it as an LVM physical volume:

sudo pvcreate /dev/sdb

Expected output:

  Physical volume "/dev/sdb" successfully created.

Verify the new physical volume:

sudo pvs

You should now see /dev/sdb listed with no volume group assigned yet.

Step 3 - Extend the Volume Group

Add the new physical volume to your existing volume group. Replace the VG name with yours - on RHEL it is commonly rhel, on Ubuntu it is commonly ubuntu-vg.

For RHEL 10:

sudo vgextend rhel /dev/sdb

For Ubuntu 24.04:

sudo vgextend ubuntu-vg /dev/sdb

Verify the volume group now shows free space:

sudo vgs

The VFree column should now show the capacity of the new disk.

Step 4 - Extend the Logical Volume

Now extend the root logical volume. You can either use all available free space or specify a size.

To use all available free space in the volume group:

sudo lvextend -l +100%FREE /dev/mapper/rhel-root

On Ubuntu:

sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv

To add a specific amount, for example 20 GiB:

sudo lvextend -L +20G /dev/mapper/rhel-root

Verify the logical volume size increased:

sudo lvs

Step 5 - Resize the Filesystem

Extending the logical volume does not automatically resize the filesystem on top of it. You need to grow the filesystem to fill the new space. The command depends on the filesystem type.

For XFS filesystems (default on RHEL 10):

sudo xfs_growfs /

For ext4 filesystems (default on Ubuntu 24.04):

sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

Both commands run online - no unmounting or rebooting required. Verify the filesystem now shows the larger size:

df -hT /

You should see the increased size reflected in the output. If the numbers match your expected total, the operation was successful.

Extending Root on Cloud VMs Without Reboot (growpart)

On cloud platforms like AWS, Azure, or GCP, you often expand the root disk by resizing the existing virtual disk rather than adding a new one. In this scenario, the physical disk gets larger but the partition table still reflects the old size. You need to grow the partition before LVM can see the new space.

Install the cloud-guest-utils package if not already present:

# Ubuntu
sudo apt install cloud-guest-utils

# RHEL
sudo dnf install cloud-utils-growpart

First, tell the kernel to rescan the disk to see the new size. For a virtio disk:

echo 1 | sudo tee /sys/class/block/sda/device/rescan

For SCSI disks on cloud VMs:

echo 1 | sudo tee /sys/class/scsi_device/0\:0\:0\:0/device/rescan

Now grow the partition. If the LVM physical volume is on /dev/sda3:

sudo growpart /dev/sda 3

Note the space between the device and the partition number. After growing the partition, tell LVM to resize the physical volume to use the new space:

sudo pvresize /dev/sda3

Verify free space appeared in the volume group:

sudo vgs

Now proceed with lvextend and the filesystem resize commands as described in Steps 4 and 5 above. The entire process runs online with no reboot required.

Extending Swap on LVM

If you need more swap space and your swap is on LVM (which is the default layout for most distro installers), you can extend it with a few extra steps.

First, disable the swap logical volume:

sudo swapoff /dev/mapper/rhel-swap

Extend the swap logical volume by the desired amount:

sudo lvextend -L +4G /dev/mapper/rhel-swap

Format the extended volume as swap:

sudo mkswap /dev/mapper/rhel-swap

Enable swap again:

sudo swapon /dev/mapper/rhel-swap

Verify the new swap size:

free -h

The swap total should now reflect the increased size.

One-Liner Shortcut Using lvextend -r

If you want to combine the logical volume extension and filesystem resize into a single command, use the -r flag with lvextend. This tells LVM to also resize the filesystem after extending the volume:

sudo lvextend -r -l +100%FREE /dev/mapper/rhel-root

This automatically detects the filesystem type and calls the appropriate resize tool. It works for both xfs and ext4. This is the approach most sysadmins use in practice because it reduces the chance of forgetting the filesystem resize step.

Troubleshooting

Here are common issues you might run into:

  • pvresize shows no additional space after growpart - The kernel may not have detected the new disk size. Re-run the rescan command and check lsblk to confirm the disk shows the larger size before running pvresize.
  • lvextend reports insufficient free space - Run vgs to check VFree. If it shows zero, you either need to add a new disk or grow an existing partition first.
  • resize2fs says the filesystem is not ext2/ext3/ext4 - You probably have an xfs filesystem. Use xfs_growfs / instead. Always check filesystem type with df -hT first.
  • xfs_growfs says nothing to do - The filesystem already fills the logical volume. Check that lvextend actually ran successfully by comparing lvs output before and after.

Verification Checklist

After completing the extension, run through these checks to confirm everything is in order:

# Confirm physical volume sizes
sudo pvs

# Confirm volume group has no unexpected free space (unless intentional)
sudo vgs

# Confirm logical volume sizes
sudo lvs

# Confirm filesystem size matches logical volume
df -hT /

# Confirm swap if extended
free -h

Summary

LVM makes extending the root filesystem a straightforward operation that does not require downtime. The workflow is consistent regardless of distribution - create or resize the physical volume, extend the volume group if needed, extend the logical volume, and resize the filesystem. On cloud VMs, use growpart and pvresize to claim space from a resized virtual disk. For swap, the only extra step is disabling and re-formatting the swap volume before and after extension. Always verify each step with the appropriate check command before moving to the next one.

Related Articles

Databases Install Beekeeper Studio SQL Manager on Ubuntu 24.04|22.04 Prometheus Prometheus MySQL exporter init script for SysV init system Programming How To Install Python 3.11 on Ubuntu 22.04|20.04|18.04 Debian How To Install Cockpit on Debian 12/11/10/9

Press ESC to close