LVM (Logical Volume Manager) — Flexible Storage Management in Linux¶
Logical Volume Manager (LVM) is a storage management framework that provides flexibility beyond traditional disk partitioning. Instead of being limited by fixed partition sizes, LVM allows administrators to create, resize, extend, reduce, and manage storage dynamically. LVM is widely used in enterprise Linux servers, cloud environments, databases, virtualization platforms, and Kubernetes worker nodes because it enables scalable and efficient storage management.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand LVM architecture
- Create Physical Volumes (PV)
- Create Volume Groups (VG)
- Create Logical Volumes (LV)
- Extend storage online
- Reduce logical volumes safely
- Create LVM snapshots
- Troubleshoot LVM
- Apply LVM best practices in production
Prerequisites¶
Complete:
- Module 1 – Linux Fundamentals
- Module 2 – Linux Command Line Essentials
- Module 3 – Text Processing
- Module 4 – File Management
- Module 5 – Users and Groups
- Module 6 – Process Management
- Module 7 – Package Management
- Module 8 – Networking
- Module 9 Lessons 1–4
Why Learn LVM?¶
Imagine:
- Your database suddenly needs 500 GB of additional storage.
- Your application log partition becomes full.
- A cloud VM receives a new disk.
- You need to take a snapshot before upgrading a production application.
Traditional partitions are difficult to resize.
LVM solves these problems with flexible storage management.
What is LVM?¶
LVM stands for:
It provides an abstraction layer between physical disks and filesystems.
Instead of using partitions directly:
LVM introduces additional layers:
LVM Architecture¶
Physical Disk
│
▼
Physical Volume (PV)
│
▼
Volume Group (VG)
│
▼
Logical Volume (LV)
│
▼
Filesystem
│
▼
Mount Point
Physical Volume (PV)¶
A Physical Volume is a storage device prepared for use by LVM.
Examples:
Create a Physical Volume:
View Physical Volumes:
Detailed information:
Volume Group (VG)¶
A Volume Group combines one or more Physical Volumes into a storage pool.
Example:
Create a Volume Group:
View Volume Groups:
Detailed information:
Logical Volume (LV)¶
A Logical Volume is a virtual partition created from a Volume Group.
Example:
Create a Logical Volume:
Options:
| Option | Meaning |
|---|---|
-L | Size |
-n | Logical volume name |
View Logical Volumes¶
Detailed information:
Create a Filesystem¶
Mount the Logical Volume¶
Create mount point.
Mount:
Verify:
Extend a Logical Volume¶
Increase by 50 GB.
Extend the filesystem.
For ext4:
For XFS:
The storage is now larger without recreating the filesystem.
Reduce a Logical Volume¶
Reducing storage requires additional care.
Example for ext4:
sudo umount /app
sudo e2fsck -f /dev/data_vg/app_lv
sudo resize2fs /dev/data_vg/app_lv 80G
sudo lvreduce -L 80G /dev/data_vg/app_lv
sudo mount /app
Warning: Reducing a logical volume incorrectly can cause permanent data loss. Always back up data before shrinking filesystems or logical volumes.
Extend a Volume Group¶
Add another disk.
Create PV.
Extend VG.
The Volume Group now has additional storage.
Remove a Logical Volume¶
Remove a Volume Group¶
Remove a Physical Volume¶
LVM Snapshots¶
Create a snapshot before performing upgrades.
Snapshots allow administrators to restore data to an earlier state if necessary.
Common Commands¶
Create PV.
Create VG.
Create LV.
Display LVM.
Extend LV.
Real Production Examples¶
Create cloud storage.
Create storage pool.
Create application storage.
Create filesystem.
Mount.
Production Perspective¶
LVM is widely used for:
- Enterprise Linux servers
- Cloud virtual machines
- Database storage
- Kubernetes worker nodes
- Virtualization platforms
- Backup servers
- Disaster recovery
- Storage expansion
It enables administrators to expand storage without repartitioning disks.
Hands-on Lab¶
Task 1¶
Display available disks.
Task 2¶
Create a Physical Volume.
Task 3¶
Create a Volume Group.
Task 4¶
Create a Logical Volume.
Task 5¶
Create an ext4 filesystem.
Task 6¶
Mount the Logical Volume.
Task 7¶
Extend the Logical Volume.
Task 8¶
Display LVM information.
Command Deep Dive¶
| Command | Purpose | Production Example |
|---|---|---|
pvcreate | Create Physical Volume | Prepare new disk |
vgcreate | Create Volume Group | Storage pool |
lvcreate | Create Logical Volume | Virtual partition |
pvdisplay | Display PV details | Storage inventory |
vgdisplay | Display VG details | Capacity planning |
lvdisplay | Display LV details | Volume management |
lvextend | Increase LV size | Online storage expansion |
resize2fs | Resize ext4 filesystem | Match filesystem to LV |
xfs_growfs | Grow XFS filesystem | Online XFS expansion |
Traditional Partitions vs LVM¶
| Feature | Traditional Partition | LVM |
|---|---|---|
| Resize Easily | Limited | ✅ |
| Multiple Disks | Limited | ✅ |
| Snapshots | ❌ | ✅ |
| Flexible Storage | ❌ | ✅ |
| Online Expansion | Limited | ✅ |
| Enterprise Usage | Moderate | Very High |
Common LVM Errors¶
| Error | Possible Cause |
|---|---|
Physical volume not found | Incorrect device |
Volume group not found | VG missing |
Logical volume not found | Incorrect LV path |
Insufficient free space | Volume Group full |
Filesystem resize failed | Filesystem not resized properly |
Production Troubleshooting Scenario¶
Scenario
A production database server reports:
Investigation:
Check storage.
The database filesystem is full.
Check available space in the Volume Group.
There is 200 GB of free space.
Extend the Logical Volume.
Grow the filesystem.
The application immediately gains additional storage without downtime.
Best Practices¶
- Use LVM for production Linux servers.
- Leave free space in Volume Groups for future expansion.
- Create snapshots before major upgrades.
- Use meaningful names for VGs and LVs.
- Monitor available free space regularly.
- Always back up data before reducing logical volumes.
Common Mistakes¶
❌ Confusing Physical Volumes with Logical Volumes.
✅ Distinguish clearly between Physical Volumes with Logical Volumes.
❌ Forgetting to resize the filesystem after extending the Logical Volume.
✅ Remember to to resize the filesystem after extending the Logical Volume.
❌ Reducing Logical Volumes without shrinking the filesystem first.
✅ Avoid this mistake: reducing Logical Volumes without shrinking the filesystem first.
❌ Using all available Volume Group space immediately.
✅ Avoid using all available Volume Group space immediately when a safer approach exists.
❌ Forgetting to mount newly created Logical Volumes.
✅ Remember to to mount newly created Logical Volumes.
Interview Questions¶
Beginner¶
- What does LVM stand for?
- What is a Physical Volume?
- What is a Volume Group?
- What is a Logical Volume?
Intermediate¶
- Why is LVM preferred over traditional partitions?
- How do you extend a Logical Volume?
- What is the purpose of a Volume Group?
- What is an LVM snapshot?
Architect Level¶
- How would you design storage for a production database using LVM?
- How would you expand storage without downtime?
- What are the advantages of LVM in cloud environments?
Summary¶
In this lesson, you learned:
- LVM architecture
- Physical Volumes
- Volume Groups
- Logical Volumes
- Creating and extending storage
- LVM snapshots
- Enterprise storage management
- Production best practices
LVM provides flexible, scalable storage management that overcomes the limitations of traditional disk partitioning. It enables administrators to grow storage dynamically, create snapshots, and efficiently manage enterprise storage across multiple physical devices.
Key Takeaways¶
- LVM separates physical storage from logical storage.
- Physical Volumes (PV) form the foundation of LVM.
- Volume Groups (VG) combine multiple storage devices into a single pool.
- Logical Volumes (LV) behave like flexible virtual partitions.
- Storage can be expanded online with minimal disruption.
- LVM is the preferred storage management solution for enterprise Linux systems.
What's Next?¶
RAID Concepts — Improving Storage Performance and Reliability
You'll explore:
- RAID levels
- RAID 0, RAID 1, RAID 5, RAID 6, and RAID 10
- Software RAID using
mdadm - Performance and redundancy
- Disk failure recovery
- Production storage best practices
RAID enhances storage performance and fault tolerance, making it an essential technology for enterprise servers and high-availability systems.