Skip to main content

๐Ÿ›  Expanding Root Filesystem on Ubuntu with LVM (Virtual Machine)

๐Ÿ“‹ Use Case

When a virtual machine runs out of space on the root (/) partition, and the underlying disk has already been expanded via the hypervisor or cloud platform.

This guide applies to systems using:

  • Ubuntu Server (e.g., 22.04 LTS)

  • LVM-managed disks

  • A single-root disk layout (e.g., /dev/mapper/ubuntu--vg-ubuntu--lv)


๐Ÿงพ Prerequisites

  • A snapshot or backup of the VM (highly recommended)

  • Root/sudo access

  • Disk already expanded in the hypervisor (e.g., from 72GB to 250GB)


๐Ÿชœ Step-by-Step Instructions

1. Check Current Disk Usage

bash
df -h /

2. List Disks and Partitions

bash
lsblk

Look for:

  • The disk (e.g., xvda)

  • The root LVM volume (e.g., /dev/mapper/ubuntu--vg-ubuntu--lv)

  • Confirm that a partition (e.g., xvda3) is larger than the mounted root volume

3. Extend the Logical Volume

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

4. Resize the Filesystem

Assuming you're using ext4:

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

๐Ÿ’ก To confirm the filesystem type:

bash
df -T /

5. Verify Expansion

bash
df -h /

You should now see the full size available (e.g., ~146GB instead of 72GB).


๐Ÿงผ Optional: Clean Up Old Snapshots & Logs

Free up even more space:

bash
sudo journalctl --vacuum-time=10d sudo apt autoremove sudo apt clean

โœ… Outcome

The root filesystem is now successfully extended. The server will run normally with more disk space, avoiding future outages caused by full disks.