LVM on Ubuntu: Create & Resize Volumes
Master LVM on Ubuntu: create physical volumes, volume groups, and logical volumes, then grow a filesystem online without downtime.
Fixed partitions are a planning trap: size them too small and you run out of space; too large and you waste it. LVM (Logical Volume Manager) removes that guesswork. It adds a flexible layer between your physical disks and your filesystems, so you can grow a volume, add a disk to a pool, or move data between disksโoften without downtime. This is the same elasticity that cloud block storage gives you, implemented locally on Ubuntu.
This guide builds an LVM stack from scratch on Ubuntu 24.04: turning raw disks into physical volumes, grouping them into a volume group, carving out a logical volume, putting a filesystem on it, and then growing that filesystem online while it stays mounted. We finish with verification and the pitfalls that trip people up.
The three LVM layers
LVM has three stacked concepts. A Physical Volume (PV) is a raw disk or partition handed to LVM. One or more PVs join a Volume Group (VG), a single pool of storage. From that pool you allocate Logical Volumes (LVs), which behave like partitions you can format and mount. The power is that LVs are not tied to a single disk and can be resized after creation.
Prerequisites
- Ubuntu 24.04 LTS with
sudoaccess. - At least one spare, unused disk (this guide uses
/dev/sdband later/dev/sdc). All data on these disks will be destroyed. - The LVM tools, which are usually preinstalled. If not:
sudo apt update && sudo apt install lvm2.
Step 1: Identify your disks
List block devices to confirm which disks are free:
lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 50G 0 disk
โโsda1 8:1 0 50G 0 part /
sdb 8:16 0 20G 0 disk
sdc 8:32 0 20G 0 diskHere sda is the OS disk; sdb and sdc are empty 20 GB disks we will use. Double-check you are not about to wipe something important.
Step 2: Create a physical volume
Initialize the first disk as an LVM physical volume:
sudo pvcreate /dev/sdb Physical volume '/dev/sdb' successfully created.Verify:
sudo pvsStep 3: Create a volume group
Create a VG named data-vg containing the PV:
sudo vgcreate data-vg /dev/sdbsudo vgsStep 4: Create a logical volume
Carve a 10 GB logical volume named web-lv out of the group:
sudo lvcreate -L 10G -n web-lv data-vgTo instead use a percentage of free spaceโsay all of itโuse -l:
sudo lvcreate -l 100%FREE -n web-lv data-vgThe new device appears at /dev/data-vg/web-lv (and a matching path under /dev/mapper/). Confirm:
sudo lvsStep 5: Create a filesystem and mount it
sudo mkfs.ext4 /dev/data-vg/web-lvCreate a mount point and mount it:
sudo mkdir -p /srv/web
sudo mount /dev/data-vg/web-lv /srv/webTo make the mount persistent across reboots, add it to /etc/fstab using the LV's UUID. Get the UUID:
sudo blkid /dev/data-vg/web-lvThen add a line to /etc/fstab (replace the UUID with yours):
UUID=xxxx-xxxx /srv/web ext4 defaults 0 2Test the fstab entry without rebooting:
sudo systemctl daemon-reload
sudo mount -a
df -h /srv/webStep 6: Grow the volume online (the payoff)
This is why LVM earns its place. Say /srv/web is filling up. First, add capacity to the volume group by initializing the second disk and extending the VG:
sudo pvcreate /dev/sdc
sudo vgextend data-vg /dev/sdcThe VG now has more free space. Extend the logical volume and grow the filesystem in one command with -r (resizefs), all while it stays mounted:
sudo lvextend -r -L +15G /dev/data-vg/web-lvThe +15G adds 15 GB to the current size; -r automatically runs resize2fs for ext4 afterward. To grow into all remaining free space instead:
sudo lvextend -r -l +100%FREE /dev/data-vg/web-lvIf you ever extend the LV without -r, grow the filesystem manually:
sudo resize2fs /dev/data-vg/web-lvStep 7: Verify the new size
df -h /srv/web
sudo lvs
sudo vgsThe df output should show the larger filesystem, available immediately with no unmount and no reboot:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/data--vg-web--lv 25G 104M 24G 1% /srv/webNote how the device-mapper name doubles the dashes in data-vg to data--vgโthat is normal LVM escaping, not a typo.
Common pitfalls and troubleshooting
- Wiping the wrong disk.
pvcreatedestroys data. Always confirm withlsblkthat the target disk is empty and unmounted first. - Forgetting to grow the filesystem.
lvextendalone only grows the block device; the filesystem stays the same size until you runresize2fs(ext4) orxfs_growfs(XFS). Use-rto do both at once. - XFS cannot shrink. ext4 can be shrunk (offline); XFS can only grow. Choose accordingly if you might need to reduce a volume.
- fstab typos cause boot failures. A bad
/etc/fstabline can drop the system to emergency mode at boot. Always test withsudo mount -abefore rebooting, and use UUIDs rather than device names. - VG out of space. If
lvextendfails with insufficient free extents, add a disk withpvcreate+vgextendfirst, as in Step 6.
Conclusion
LVM gives a single Ubuntu host the kind of elastic storage that used to require careful upfront partitioning: pool your disks, allocate what you need today, and grow online tomorrow. The pvcreate โ vgcreate โ lvcreate โ lvextend -r workflow is worth committing to memory.
The same idea scales out across a cluster. Distributed storage like a Ceph cluster on Ubuntu pools disks across many nodes, and in OpenStack you consume that capacity as elastic Cinder block volumes you attach to instances on demand. That is exactly how clouditiv delivers resilient, growable storage in its managed on-premise cloudโthe flexibility of LVM, at data-center scale, without you babysitting disks.