Running out of space on an LVM volume is one of the easiest storage problems to fix. Usually it takes one command and no downtime. What you need to do depends on where the extra space comes from.

Look at the current state

df -hT /                 # which LV is full, and its filesystem type
sudo lvs                 # logical volumes and sizes
sudo vgs                 # volume groups: VFree = unallocated space
sudo pvs                 # physical volumes
lsblk

There are three scenarios:

  1. The volume group already has free space (VFree > 0).
  2. The disk underneath was enlarged, as after a VPS disk upgrade.
  3. You’re adding a new disk.

Scenario 1: the VG has free space

Very common on Ubuntu Server. The installer creates a root LV that uses only part of the disk (often half, or 100 GB) and leaves the rest free in the VG:

sudo vgs
#  VG        #PV #LV #SN Attr   VSize    VFree
#  ubuntu-vg   1   1   0 wz--n- <78.00g  <39.00g

Claim it all:

sudo lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
df -h /
  • -l +100%FREE adds all the free extents. Use -L +20G for a fixed amount.
  • -r resizes the filesystem in the same step, ext4 or XFS, online.

That’s it.

Scenario 2: the underlying disk got bigger

After a disk upgrade, the chain is partition → PV → LV → filesystem:

lsblk
# vda      160G disk
# └─vda3    79G part
#   └─ubuntu--vg-ubuntu--lv  lvm  /

sudo growpart /dev/vda 3          # 1. grow the partition (note the space)
sudo pvresize /dev/vda3           # 2. tell LVM the PV is bigger
sudo lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv    # 3. grow LV + filesystem

If the PV is a whole disk (no partition), skip growpart: sudo pvresize /dev/vdb. See growpart.

Scenario 3: add a new disk

lsblk                                   # find the new disk, e.g. /dev/vdb
sudo pvcreate /dev/vdb
sudo vgextend ubuntu-vg /dev/vdb
sudo lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

The LV now spans both disks. If either disk fails, the LV is lost. For important data, put the new disk to use as a separate LV or mount, or use RAID. See LVM guide.

Without -r: resize the filesystem manually

If you’ve already extended the LV without -r:

sudo resize2fs /dev/ubuntu-vg/ubuntu-lv     # ext4
sudo xfs_growfs /                           # XFS (mount point)

Choosing the size

sudo lvextend -L 120G  /dev/vg/lv     # set the total size to 120G
sudo lvextend -L +20G  /dev/vg/lv     # add 20G
sudo lvextend -l +50%FREE /dev/vg/lv  # add half the free space

Leaving some space free in the VG gives you room for snapshots and emergencies. You can always extend again later.

Shrinking (be careful)

  • XFS can’t shrink.
  • ext4 can shrink, but only unmounted, and the filesystem must be shrunk before the LV:
sudo umount /data
sudo e2fsck -f /dev/vg/data
sudo lvreduce -r -L 50G /dev/vg/data      # -r shrinks the fs first, then the LV
sudo mount /data

Getting the order wrong destroys data. Take a backup first. Shrinking the root LV needs the console in recovery mode, because root can’t be unmounted while running.

Common errors

Insufficient free space: X extents needed, but only Y available — the VG doesn’t have that much free space. Check vgs, use +100%FREE, or add space first (scenarios 2 and 3).

New size given (…) not larger than existing size — -L 50G without + sets the total size, and that’s smaller than now. Use +50G.

Couldn't find device with uuid … — a PV is missing, perhaps a detached disk. Don’t force changes. Investigate first (pvs -a, vgdisplay -v).

resize2fs: Device or resource busy while unmounting for a shrink — something is using the filesystem. Find it with fuser -vm /data.

Quick reference

Situation Commands
VG has free space lvextend -r -l +100%FREE /dev/vg/lv
Disk enlarged growpart /dev/vda 3 → pvresize /dev/vda3 → lvextend -r …
New disk pvcreate /dev/vdb → vgextend vg /dev/vdb → lvextend -r …
Fs only (ext4) resize2fs /dev/vg/lv
Fs only (XFS) xfs_growfs /mountpoint

Related: disk full troubleshooting and du.

  • Linux
  • Storage
  • LVM