Learn how to resize an LVM partition on Ubuntu with this guide. Logical Volume Manager (LVM) lets you manage disk space flexibly on Ubuntu systems. This tutorial will walk you through extending a logical volume to use more space.
Scenario
When you resize an LVM partition on Ubuntu, you might have a disk (/dev/sda
) with a total size of 30GB, divided into:
/dev/sda1
: 1MB (BIOS boot partition)/dev/sda2
: 1.8GB (mounted as/boot
)/dev/sda3
: 28.2GB (LVM physical volume)
The logical volume (ubuntu-vg-ubuntu-lv
), mounted as /
, is 20GB, but you want to extend it to 28.2GB.
Prerequisites
- A Ubuntu system with LVM configured.
- Administrative access (sudo privileges).
- Back up your data before starting.
Steps to Resize the Disk and Extend LVM
If you’ve increased your disk size (e.g., from 20GB to 30GB), you need to ensure the system recognizes the new size and extend the LVM physical volume before resizing the logical volume.
1. Rescan the Disk to Detect the New Size
The system might not automatically recognize the new 10GB. Run:
echo 1 | sudo tee /sys/block/sda/device/rescan
This updates the kernel to see the new disk size (30GB).
2. Verify the New Disk Size
Check the updated size with:
lsblk /dev/sda
You should see /dev/sda
as 30GB. If not, ensure the additional space was properly added at the hardware level (e.g., in a VM, confirm the disk extension in your hypervisor).
3. Extend the Physical Partition
Since /dev/sda
is already part of an LVM group, it likely has a partition (e.g., /dev/sda3
) used for LVM. You need to resize this partition to use the new space. Use fdisk
to modify the partition table:
sudo fdisk /dev/sda
- Press
d
to delete the existing LVM partition (e.g., partition 3). Don’t worry—this won’t delete your data, just the partition table entry. - Press
n
to create a new partition, using the same start sector as before (note it down from the output) and extending to the end of the disk to include the new 10GB. - Set the type to
8e
(Linux LVM) witht
if needed. - Press
w
to write the changes and exit.
4. Update the Kernel with the New Partition Table
Run:
sudo partprobe /dev/sda
5. Resize the Physical Volume (PV)
Now, extend the LVM physical volume to use the resized partition (assuming it’s /dev/sda3
):
sudo pvresize /dev/sda3
Check with:
sudo pvs
The physical volume should now show 28.2GB.
Steps to Resize an LVM Partition on Ubuntu
Now that the disk and physical volume are resized, you can extend the logical volume.
1. Verify the Current Disk Layout
Check the disk layout with lsblk
:
lsblk
Output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 1M 0 part
├─sda2 8:2 0 1.8G 0 part /boot
└─sda3 8:3 0 28.2G 0 part
└─ubuntu-vg-ubuntu-lv 252:0 0 20G 0 lvm /
Verify the filesystem size:
df -h /
2. Check the Volume Group (VG) Space
See available space in the volume group:
sudo vgs
3. Check the Logical Volume (LV)
Confirm the logical volume size:
sudo lvs
4. Extend the Logical Volume
When you resize an LVM partition on Ubuntu, extend the logical volume to use all free space:
sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
5. Resize the Filesystem
For ext4
, run:
sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
For xfs
, use:
sudo xfs_growfs /
6. Verify the New Size
Check the updated size:
df -h /
The output should show ~28.2GB for /
.
Why Does Ubuntu Leave Unallocated Space When You Resize an LVM Partition?
The Ubuntu installer often leaves unallocated space in the volume group for flexibility, allowing you to extend volumes or create new ones later.
Tips
- Always back up your data before resizing. For more on LVM management.
- Use the “Custom storage layout” option during installation to allocate all space upfront.
- Regularly monitor your LVM setup for errors. Use
sudo pvdisplay
andsudo vgdisplay
to check the health of your physical volumes and volume groups, ensuring your system runs smoothly. - Shrinking an LVM volume is riskier, so proceed with caution.
Conclusion
To resize an LVM partition on Ubuntu is simple with these steps. LVM’s flexibility makes it ideal for managing storage on Ubuntu servers.