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:
- Extend the Logical Volume (LV) - Allocate additional space from the volume group
- 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:
Example output:
Step 2: Check Volume Group Free Space
Verify that your volume group has free space available:
Look for the "Free PE / Size" line in the output:
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:
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:
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)
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:
Step 5: Verify the Expansion
Confirm that the disk space has been successfully expanded:
You should now see the increased space:
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:
-
Check if the partition has unallocated space:
-
Extend the physical volume:
(Replace/dev/sda3with your actual PV partition) -
Verify the volume group now has free space:
Filesystem Still Shows Old Size
If df -h doesn't show the increased space after resize2fs:
-
Check if the logical volume was actually extended:
-
Try running resize2fs again:
-
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:
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
Related Documentation
- LVM Administration Guide
- ext4 Filesystem Documentation
- Managing disk partitions on Linux
- Cloud instance storage expansion guides
References
- Ubuntu LVM Documentation: help.ubuntu.com/lvm
- Linux LVM HOWTO: tldp.org/HOWTO/LVM-HOWTO
- resize2fs man page:
man resize2fs - lvresize man page:
man lvresize