Ubuntu Server Expand LVM2
- Published on
- 3 min read
- Authors
- Name
- Robin te Hofstee
- @Robin_teHofstee
Below are step‑by‑step instructions you can follow to expand an LVM2 partition on Ubuntu Server. The process depends on whether you already have free space available in your volume group (VG) or if you first need to expand the underlying physical partition on your disk. Here’s a guide that covers both scenarios:
1. Check Your Current Disk and LVM Status
Check disk usage and partition layout:
df -h sudo fdisk -l
Examine your VG and LV details:
sudo vgdisplay sudo lvdisplay
These commands let you see how much free space exists in your VG and the current sizes of your logical volumes (LVs).
2. If You Have Free Space in Your Volume Group
Sometimes, especially with the default Ubuntu installer, extra space is allocated to the VG but not used by the LV. If vgdisplay
shows free space (look for the “Free PE / Size” line), you can extend your LV directly:
Extend the Logical Volume (LV):
For example, to extend to use 100% of the free space:sudo lvextend -l +100%FREE /dev/mapper/ubuntu-vg-ubuntu-lv
(Replace
/dev/mapper/ubuntu-vg-ubuntu-lv
with your actual LV path.)Resize the Filesystem:
If you’re using an ext4 filesystem, run:sudo resize2fs /dev/mapper/ubuntu-vg-ubuntu-lv
For other file systems (like XFS), use the appropriate command (e.g.,
xfs_growfs
).Verify the Changes:
df -h
3. If Your VG Doesn’t Have Free Space
If vgdisplay
shows 0 free space, you first need to expand the underlying physical partition.
A. Expand the Underlying Disk
At the hypervisor level:
If you’re running a virtual machine, increase the size of the virtual disk in your VM settings (for example, through VMware, KVM, Hyper-V, etc.).Rescan the Disk in Ubuntu:
Force Ubuntu to see the new size (assuming your disk is/dev/sda
):echo 1 | sudo tee /sys/class/block/sda/device/rescan
B. Resize the Partition
Optionally, you can use tools like cfdisk
, fdisk
, or growpart
to adjust the partition that backs your PV (often something like /dev/sda3
):
Launch your partition tool (using cfdisk as an example):
sudo cfdisk /dev/sda
Select your LVM Partition:
Choose the partition (for example,/dev/sda3
) and select the “Resize” option. Increase it to occupy the new free space.Write Changes and Exit.
C. Extend the Physical Volume (PV)
Let LVM know about the increased partition size:
sudo pvresize /dev/sda3
Check that pvdisplay
now shows increased size and that your VG has more free space.
D. Now Extend the Logical Volume and Filesystem
Repeat the steps from Section 2:
- Extend the LV:
sudo lvextend -l +100%FREE /dev/mapper/ubuntu-vg-ubuntu-lv
- Resize the Filesystem:
sudo resize2fs /dev/mapper/ubuntu-vg-ubuntu-lv
- Verify with df:
df -h
Summary
- Scenario 1: If your VG already has free space, you only need to extend your LV and then resize your filesystem.
- Scenario 2: If not, first expand the underlying disk (via your hypervisor), then adjust the partition (using tools like cfdisk/fdisk/growpart), run
pvresize
, and finally extend your LV and filesystem.
These steps should expand your LVM2 content area so that your system can take advantage of the additional disk space.
For further details and examples, you might review one or more of these guides:
- How to Extend the Default Ubuntu LVM Partition
- Ask Ubuntu: How can I resize an active LVM partition?
- How to Increase Size of Disk Partition in Ubuntu
Feel free to ask if you need any further clarification on any of these steps!