Grow and shrink Ubuntu storage with LVM

Ubuntu can make a partition look as though it has plenty of room while the filesystems built on top of it are nearly full. Learning how to use LVM to resize partitions on Ubuntu helps you separate these storage layers and change them safely. The important part is knowing which layer needs more space before running any commands.

Logical Volume Manager, usually shortened to LVM, is common on Ubuntu installations that use the LVM partitioning option. It lets you grow, shrink or relocate logical volumes without rebuilding the entire disk layout. This guide explains the complete process, from checking the layout to extending a filesystem, adding another disk and handling the limitations of shrinking.

How LVM storage is arranged

LVM introduces several layers between the physical disk and your files. A physical volume, or PV, can be a whole disk or a partition. Physical volumes are combined into a volume group, which pools their available space. Logical volumes are then carved from that group and formatted with filesystems such as ext4 or XFS.

A useful way to visualise this is:

Disk → partition → physical volume → volume group → logical volume → filesystem

On a typical Ubuntu installation, the root filesystem might be /dev/mapper/ubuntu--vg-ubuntu--lv. That unusual name combines the volume group and logical volume names with safe character substitutions. Other installations use different names, so confirm the layout rather than assuming the default.

Use these commands to inspect it:

lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS
sudo pvs
sudo vgs
sudo lvs

The vgs output includes VFree, the unused capacity in the volume group. Australian technology users often call a gigabyte a “gig”, but LVM sizes should be entered precisely. A drive advertised as 1 TB by an Australian retailer usually appears as roughly 931 GiB because vendors use decimal units while Linux reports binary units.

Prepare safely

Start with an independent backup. An LVM snapshot is useful for protecting against a mistaken resize, but it lives on the same storage system and is not a substitute for a backup. Copy important data to an external drive before making structural changes. Two- and four-terabyte USB drives are widely available in the Australian market for this purpose.

Record the current LVM metadata:

sudo vgcfgbackup ubuntu-vg

Replace ubuntu-vg if your volume group has another name. The backup is written under /etc/lvm/backup. If space permits, a short-lived snapshot adds another layer of protection:

sudo lvcreate --snapshot --size 2G \
  --name root-snap /dev/ubuntu-vg/ubuntu-lv

Make sure the tools required for the operation are installed:

sudo apt install lvm2 cloud-guest-utils parted

Check which filesystem and logical volume are mounted at the target path:

findmnt -no SOURCE,FSTYPE,TARGET /home

A separate data filesystem can usually be unmounted normally. The root filesystem is more awkward because it must remain available while the system runs. For changes to root, boot an Ubuntu live USB and work from there.

Many computers sold through Australian retailers such as JB Hi-Fi and Harvey Norman arrive with Windows, an EFI System Partition and a manufacturer recovery partition. If you dual-boot Ubuntu on one of these machines, leave those partitions untouched. Resize only the Ubuntu LVM components.

Extend an existing volume

The simplest growth operation uses space already available inside the volume group. Check the free space first:

sudo vgs ubuntu-vg

If at least 20 GiB is free, add 20 GiB to the logical volume with:

sudo lvextend -L +20G /dev/ubuntu-vg/ubuntu-lv

To assign every currently free extent to the volume:

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

The logical volume can remain mounted during this step because you are changing the size of the block device beneath the filesystem. The filesystem itself must still be expanded separately.

Confirm the result with sudo lvs. The new size should now be visible, although a program using the filesystem may continue to report the old total until its next refresh or reboot. If the command reports insufficient free space, the space is probably still outside the volume group. The physical partition or physical volume must be expanded before this command can work.

Grow the partition behind LVM

When a disk partition contains unused space, begin by identifying the partition that holds the LVM physical volume. lsblk -f shows this relationship clearly. Suppose the partition is /dev/nvme0n1p3, with 3 identifying its number on the disk.

Grow that partition to the end of the disk:

sudo growpart /dev/nvme0n1 3
sudo partprobe /dev/nvme0n1

If the kernel cannot reread a mounted partition, partprobe may report that it is busy. In that case, finish the partition change and reboot before continuing. Do not force a partition table update over an active filesystem.

Next, tell LVM that the physical volume has more space:

sudo pvresize /dev/nvme0n1p3

Now extend the logical volume and filesystem. For an ext4 filesystem:

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

For XFS, grow the mounted filesystem with:

sudo xfs_growfs /dev/ubuntu-vg/ubuntu-lv

XFS can grow while mounted, but it cannot be reduced. If growpart reports that no change was made, the partition may already reach the end of the disk. Check lsblk and sudo pvs to confirm whether the unused space was inside the physical volume rather than outside the partition.

Add capacity with another disk

LVM can incorporate additional storage into an existing volume group. This is useful when a system has a small system disk but needs more room for home directories, containers or media. The new disk should normally contain a partition, although LVM can use an entire disk.

First confirm the device name with lsblk. Then create the physical volume, add it to the group and extend the logical volume:

sudo pvcreate /dev/sdb1
sudo vgextend ubuntu-vg /dev/sdb1
sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

These examples assume a partition named /dev/sdb1; substitute the actual device. pvcreate writes LVM metadata and destroys any existing filesystem on that device, so check the disk carefully before proceeding.

Finally, grow the filesystem using either resize2fs for ext4 or xfs_growfs for XFS. Keep removable disks for data volumes rather than the root filesystem, because an unplugged device can make the logical volume unavailable.

Australian mains power is 230 volts, and a surge-protected UPS can provide a controlled shutdown during a resize. On a hot Sydney or Canberra day, keep the drive shaded and use stable power. Heat and an intermittent cable are avoidable risks even when the LVM commands are correct.

Shrink when the filesystem allows it

Growing storage is usually straightforward; shrinking has stricter rules. XFS cannot be shrunk at all. ext4 can be reduced, but the filesystem must be unmounted and checked first. From a live Ubuntu session, unmount the target filesystem and run:

sudo e2fsck -f /dev/ubuntu-vg/ubuntu-lv
sudo resize2fs /dev/ubuntu-vg/ubuntu-lv 40G
sudo lvresize -L 40G /dev/ubuntu-vg/ubuntu-lv

Those commands first reduce the ext4 filesystem to 40 GiB, then reduce the logical volume to the same size. The order matters because LVM must never contain a filesystem larger than the logical volume beneath it.

The backing partition can be reduced afterwards if you need physical free space for another partition. Use parted to inspect its start and end positions before changing anything:

sudo parted /dev/nvme0n1 unit GiB print

The resizepart command needs a new endpoint, not the desired size of the logical volume. For example, a partition starting near 1 GiB and containing a 40 GiB volume could end near 41 GiB:

sudo parted -s /dev/nvme0n1 unit GiB resizepart 3 41GiB

Never use that endpoint blindly; calculate it from the displayed partition layout. Then update the physical volume metadata with sudo pvresize /dev/nvme0n1p3. Taking an LVM snapshot or a separate backup before this operation is particularly important.

Fix common resize problems

An error about insufficient free extents means the volume group has no unallocated capacity. Inspect it with sudo vgs, then either grow the physical volume or add another disk. If pvresize reports that no change was made, the partition table may already reflect the larger size.

If a filesystem refuses to resize, confirm its type with findmnt. Use resize2fs for ext4 and xfs_growfs for XFS, while avoiding resize2fs on XFS. A busy device usually means the filesystem is still mounted or a process holds it open. Check with fuser -vm /mount/path and unmount it when possible.

If a logical volume is missing after a reboot, scan and activate its volume group:

sudo vgscan
sudo vgchange -ay ubuntu-vg

Do not restore old LVM metadata merely to solve an unknown error, because it can conceal the actual cause. Use sudo lvs, sudo vgs and sudo pvs to compare the expected and current layout.

Ubuntu Australia’s community resources and local Linux user groups around Sydney, Melbourne, Brisbane and Canberra can help when the device names or storage layout differ from a tutorial. The most useful diagnostic information is usually the complete output of lsblk -f, pvs, vgs and lvs, along with the exact command that failed.

The central rule is to resize in order: partition, physical volume, logical volume and filesystem. Growth is usually forgiving, while shrinking can cause immediate data loss, especially with XFS. What the reader should remember is that a current backup, accurate layout information and verification after every layer are the real safeguards behind a successful LVM resize.