π§± Everything You Need to Know About LVM in Linux
If you’re working with Linux systems, sooner or later you’ll encounter LVM — Logical Volume Manager. It’s a powerful system for managing storage that goes far beyond traditional disk partitioning.
In this post, we’ll cover everything about LVM: what it is, why it’s useful, and how to use it — with real-world commands and examples.
π What is LVM?
LVM (Logical Volume Manager) is a system that lets you manage your storage devices more flexibly than traditional partitions. Instead of dividing your disk into fixed partitions, LVM allows you to create logical volumes on top of physical storage devices, and you can resize, extend, or move them easily — even while the system is running.
π§© LVM Structure
To understand how LVM works, let’s look at the 3 main layers:
-
Physical Volumes (PV)
Actual hard drives or partitions (/dev/sda1
,/dev/nvme0n1p3
, etc.) -
Volume Groups (VG)
A pool of storage made by combining multiple PVs. -
Logical Volumes (LV)
These are like partitions, created inside a VG. You mount and format LVs just like regular partitions.
π Why Use LVM?
✅ Benefits of LVM:
-
Resize volumes on the fly
-
Combine multiple disks into one volume
-
Create snapshots for backups or testing
-
Easily manage growing storage needs
-
Migrate volumes to other disks with minimal downtime
π ️ How to Use LVM – Step by Step
Let’s go through a real example.
πΉ Step 1: Install LVM (if not installed)
πΉ Step 2: Create Physical Volume (PV)
Check PVs:
πΉ Step 3: Create Volume Group (VG)
List VGs:
πΉ Step 4: Create Logical Volume (LV)
-
-L 10G
: size of the LV -
-n my_lv
: name -
my_vg
: volume group
πΉ Step 5: Format the Logical Volume
πΉ Step 6: Mount It
π Resize Volumes
Increase LV size (if VG has free space):
Reduce LV size (⚠️ Risky – backup first):
πΈ Snapshots with LVM
Create a snapshot:
Mount snapshot if needed and use for backups or testing.
π‘ Useful LVM Commands
Command | Description |
---|---|
pvcreate | Initialize physical volume |
vgcreate | Create volume group |
lvcreate | Create logical volume |
lvextend | Increase LV size |
lvreduce | Reduce LV size |
lvremove | Remove logical volume |
vgextend | Add PV to existing VG |
vgreduce | Remove PV from VG |
vgremove | Remove volume group |
pvremove | Remove physical volume |
lvdisplay , vgdisplay , pvdisplay | Show detailed info |
π§― Real-World Use Cases
-
Creating storage pools for virtual machines
-
Using snapshots before risky software upgrades
-
Expanding file systems without downtime
-
Managing external disks or RAID devices
⚠️ Things to Watch Out For
-
Shrinking LVs is dangerous — always back up first.
-
Don’t remove a PV that still has active data.
-
Snapshots take space — monitor usage or they will become invalid.
✅ Summary
LVM is a must-know tool for any Linux sysadmin, DevOps engineer, or power user. It gives you flexibility, control, and scalability over your disk storage. Whether you’re running a home server or managing an enterprise system, LVM is one of the most valuable storage tools in your arsenal.
Comments
Post a Comment