Welcome to Day 16 of the 30 Days of Linux Challenge!
Today’s focus is on a foundational storage concept for system administration: Logical Volume Management (LVM).
If you’ve ever needed to resize partitions without losing data, combine multiple disks into one logical space, or take instant storage snapshots — LVM is what makes that possible in Linux systems.
📚 Table of Contents
- Why LVM Matters
- Key LVM Components Explained
- Typical LVM Workflow
- Managing and Monitoring LVM
- Real-World Applications of LVM
- Try It Yourself
- Common LVM Commands Cheat Sheet
- Why This Matters in Real-World Systems
Why LVM Matters
Traditional partitioning has limitations:
- Static in size (resizing is complicated and risky)
- Cannot easily span multiple disks
- Difficult to migrate without downtime
LVM solves this.
With LVM:
- You group physical storage into flexible pools
- You carve logical volumes out of those pools
- You can grow, shrink, snapshot, and move volumes without disrupting the system
🔵 In enterprise servers, cloud environments, database hosting, and virtualization — LVM is the standard.
Key LVM Components Explained
Here’s the basic structure:
Component | Description |
---|---|
Physical Volume (PV) | A real storage device (disk/partition) |
Volume Group (VG) | A storage pool made from one or more PVs |
Logical Volume (LV) | The partitions you create inside the VG |
Think of it like this:
Disks → pooled into a Volume Group → sliced into Logical Volumes.
Typical LVM Workflow
🔹 Step 1: Create Physical Volumes
Mark devices as LVM-ready:
sudo pvcreate /dev/sdb1 /dev/sdc1
🔹 Step 2: Create a Volume Group
Group PVs together:
sudo vgcreate my_vg /dev/sdb1 /dev/sdc1
🔹 Step 3: Create Logical Volumes
Create flexible partitions:
sudo lvcreate -L 10G -n data_lv my_vg
-L defines the size (e.g., 10GB)
-n names the volume
my_vg is your Volume Group
🔹 Step 4: Format and Mount
Prepare and use the logical volume:
sudo mkfs.ext4 /dev/my_vg/data_lv
sudo mkdir /mnt/mydata
sudo mount /dev/my_vg/data_lv /mnt/mydata
Congratulations — now /mnt/mydata acts like a normal filesystem but is fully dynamic underneath.
Managing and Monitoring LVM
View Physical Volumes:
sudo pvs
View Volume Groups:
sudo vgs
View Logical Volumes:
sudo lvs
This helps track free space, volume size, and health at every level.
Real-World Applications of LVM
Scenario | Why LVM Helps |
---|---|
Expanding a running database | Extend Logical Volume without downtime |
Consolidating old small disks | Combine into a single Volume Group |
Cloud server grows in storage size | Simply extend the Logical Volume |
Scheduled backups on live servers | Use snapshots for safe backups |
Dev/QA environment needing dynamic disks | Create and destroy Logical Volumes on demand |
In production environments, downtime is expensive — LVM lets you adapt your storage live.
Try It Yourself (Practice Lab)
On a test server or VM:
Create a PV
sudo pvcreate /dev/sdb
Create a VG
sudo vgcreate lab_vg /dev/sdb
Create an LV
sudo lvcreate -L 5G -n lab_lv lab_vg
Format it
sudo mkfs.ext4 /dev/lab_vg/lab_lv
Mount it
sudo mkdir /mnt/lab
sudo mount /dev/lab_vg/lab_lv /mnt/lab
Verify
df -h /mnt/lab
sudo pvs
sudo vgs
sudo lvs
Then try expanding it:
sudo lvextend -L +2G /dev/lab_vg/lab_lv
sudo resize2fs /dev/lab_vg/lab_lv
Common LVM Commands Cheat Sheet
Command | Purpose |
---|---|
pvcreate |
Initialize disk for LVM |
vgcreate |
Create volume group |
lvcreate |
Create logical volume |
pvs , vgs , lvs
|
Show volumes and volume groups |
lvextend |
Expand logical volume |
lvremove |
Delete logical volume |
lvcreate --snapshot |
Create snapshot of logical volume |
Why This Matters in Real-World Systems
LVM is used everywhere:
- Datacenters
- Cloud providers (AWS EC2 uses LVM inside some AMIs)
- Database clusters
- Backup and DR (Disaster Recovery) strategies
- Virtualization platforms (KVM, Proxmox, oVirt)
Knowing how to plan, create, manage, and troubleshoot LVM setups is a skill that separates junior admins from serious infrastructure engineers.