Server LVM: Flexible Storage and Online Resize
You will build a flexible LVM storage stack on a server and grow a live filesystem without unmounting it. By the end you will expand capacity with zero downtime, the way production systems add space.
Learning Objectives
- Assemble physical volumes into a volume group.
- Carve a logical volume and put a filesystem on it.
- Extend the volume and filesystem online.
- Time: ~3 hours · Difficulty: Advanced · Prereqs: a server with two spare disks.
Architecture Overview
graph LR
D[(sdb + sdc)] -->|pvcreate| PV[Physical Volumes]
PV -->|vgcreate| VG[Volume Group 'data']
VG -->|lvcreate| LV[Logical Volume]
LV -->|mkfs + mount| FS[/srv ext4]
Environment Setup
You will need: a Linux server with LVM2 and two empty disks (/dev/sdb, /dev/sdc).
Before you begin: verify the disks are empty with lsblk.
Step-by-Step Execution
01
Initialize physical volumes and a group
This labels the disks for LVM and pools them into one resizable group.
sudo pvcreate /dev/sdb /dev/sdc && sudo vgcreate data /dev/sdb /dev/sdc[ROOT REQUIRED] Creates PVs and the 'data' volume group.
02
Create and format a logical volume
The LV behaves like a partition but can grow across both disks.
sudo lvcreate -L 10G -n srv data && sudo mkfs.ext4 /dev/data/srv03
Mount it
sudo mkdir -p /srv/store && sudo mount /dev/data/srv /srv/store04
Grow the volume online
Extend the LV, then grow the filesystem, all while it stays mounted and in use.
# lvextend -L +5G /dev/data/srv && resize2fs /dev/data/srv
Size of logical volume data/srv changed to 15.00 GiB
The filesystem is now 3932160 (4k) blocks long.
Progress So Far
graph LR
A[01 PV + VG] -->|done| B[02 LV + format]
B -->|done| C[03 Mount]
C -->|done| D[04 Online grow]
style A fill:#1a4a1a,stroke:#00ff00,color:#fff
style B fill:#1a4a1a,stroke:#00ff00,color:#fff
style C fill:#1a4a1a,stroke:#00ff00,color:#fff
style D fill:#1a4a1a,stroke:#00ff00,color:#fff
Testing & Validation
df -h /srv/store && sudo vgs && sudo lvsYou should see the larger size while the mount stayed active. If so, you grew storage with zero downtime.
Troubleshooting
- Filesystem size unchanged: run resize2fs (ext4) or xfs_growfs (xfs) after lvextend.
- VG out of space: add a disk with pvcreate + vgextend before lvextend.
- Cannot create PV: the disk has an existing signature; wipe with
wipefsafter confirming it is empty.
Extension Ideas
- Add LVM snapshots for consistent backups in Backup & Recovery.
- Compare with the fundamentals view in Linux Fundamentals: LVM.
- Experiment with thin provisioning for over-commit scenarios.
Key Results
- Grew a mounted filesystem from 10GB to 15GB with zero downtime.
- Pooled two disks into one flexible volume group.
- Decoupled filesystem size from physical disk limits.
- Verified capacity changes with df, vgs, and lvs.