Skip to content

Expanding LVM Disk Space on Ubuntu/Linux

This guide explains how to expand LVM (Logical Volume Manager) disk space on Ubuntu and other Linux distributions when you've increased the underlying storage capacity.

Use Case

This procedure is commonly needed when:

  • You've expanded a virtual machine's disk in a hypervisor
  • You've added physical storage to your system
  • You've resized a cloud instance's root volume
  • Your LVM logical volume has free space available in the volume group

Prerequisites

Important Prerequisites

  • Administrative (sudo) access
  • Backup of important data (recommended)
  • Basic understanding of LVM concepts
  • Extended physical volume (PV) or volume group (VG) with free space

Understanding the Process

The expansion process involves two main steps:

  1. Extend the Logical Volume (LV) - Allocate additional space from the volume group
  2. Resize the Filesystem - Expand the filesystem to use the newly allocated space

LVM Hierarchy

LVM uses a three-layer structure:

  • Physical Volume (PV) - Physical disk or partition
  • Volume Group (VG) - Pool of storage from one or more PVs
  • Logical Volume (LV) - Virtual partition that uses space from the VG

Step-by-Step Guide

Step 1: Check Current Disk Usage

First, verify your current disk usage and available space:

df -h

Example output:

Filesystem                         Size  Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv   20G   18G  1.0G  95% /

Step 2: Check Volume Group Free Space

Verify that your volume group has free space available:

sudo vgdisplay

Look for the "Free PE / Size" line in the output:

--- Volume group ---
VG Name               ubuntu-vg
...
Free  PE / Size       2559 / 10.00 GiB

Available Space Confirmed

If you see free space in the volume group, you can proceed with the expansion.

No Free Space?

If there's no free space, you need to first extend the physical volume. See the Troubleshooting section below.

Step 3: Extend the Logical Volume

Expand the logical volume to use all available free space in the volume group:

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

Command breakdown:

  • lvresize - Resize a logical volume
  • -l +100%FREE - Use 100% of the free space in the volume group
  • /dev/mapper/ubuntu--vg-ubuntu--lv - Path to the logical volume

Alternative: Specific Size

To extend by a specific amount instead:

sudo lvresize -L +10G /dev/mapper/ubuntu--vg-ubuntu--lv

Expected output:

Size of logical volume ubuntu-vg/ubuntu-lv changed from 20.00 GiB to 30.00 GiB.
Logical volume ubuntu-vg/ubuntu-lv successfully resized.

Step 4: Resize the Filesystem

After extending the logical volume, resize the filesystem to use the new space.

For ext4 Filesystem (Most Common)

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

Expected output:

resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 4
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 7864320 (4k) blocks long.

For XFS Filesystem

If you're using XFS instead of ext4:

sudo xfs_growfs /

Filesystem Detection

To check your filesystem type:

df -T

Step 5: Verify the Expansion

Confirm that the disk space has been successfully expanded:

df -h

You should now see the increased space:

Filesystem                         Size  Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv   30G   18G   11G  62% /

Expansion Complete

Your filesystem now has access to the additional disk space!

Complete Command Summary

For quick reference, here's the complete sequence:

# Check current disk usage
df -h

# Check available space in volume group
sudo vgdisplay

# Extend logical volume
sudo lvresize -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv

# Resize ext4 filesystem
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

# Verify expansion
df -h

Troubleshooting

No Free Space in Volume Group

If vgdisplay shows no free space, you need to extend the physical volume first:

  1. Check if the partition has unallocated space:

    sudo pvdisplay
    sudo fdisk -l
    

  2. Extend the physical volume:

    sudo pvresize /dev/sda3
    
    (Replace /dev/sda3 with your actual PV partition)

  3. Verify the volume group now has free space:

    sudo vgdisplay
    

Filesystem Still Shows Old Size

If df -h doesn't show the increased space after resize2fs:

  1. Check if the logical volume was actually extended:

    sudo lvdisplay
    

  2. Try running resize2fs again:

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

  3. Reboot if necessary (though this is rarely required for ext4)

Finding Your LVM Path

If you're unsure of your logical volume path:

# List all logical volumes
sudo lvs

# List device mapper paths
ls -l /dev/mapper/

# Or use lvdisplay for detailed info
sudo lvdisplay

Common naming patterns:

  • /dev/mapper/ubuntu--vg-ubuntu--lv
  • /dev/mapper/vg_name-lv_name
  • /dev/vg_name/lv_name

Permission Denied Errors

All commands require root privileges. If you get permission denied:

# Ensure you're using sudo
sudo lvresize -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv

Additional Information

Online vs Offline Resizing

Online Resizing

Both ext4 and XFS support online resizing, meaning you can expand the filesystem while it's mounted and in use. No downtime is required for expansion operations.

Shrinking LVM Volumes

Shrinking Requires Caution

While expanding is safe, shrinking LVM volumes is risky and can result in data loss. Always:

  • Create a complete backup first
  • Unmount the filesystem before shrinking
  • Shrink the filesystem before shrinking the logical volume
  • Test the process in a non-production environment

Performance Considerations

  • LVM adds minimal overhead to disk operations
  • The resize operations are typically fast (seconds to minutes)
  • No data is moved during expansion
  • Filesystem expansion happens in real-time without downtime

References