LVM & Disk Management
Physical volumes, volume groups, logical volumes, snapshots, thin provisioning, and live resize.
Overview
LVM (Logical Volume Manager) adds a layer of abstraction between physical storage and filesystems.
Three-Tier Hierarchy
- Physical Volumes (PVs) — raw disks initialised for LVM: pvcreate /dev/sdb
- Volume Groups (VGs) — pool of PVs: vgcreate myvg /dev/sdb /dev/sdc
- Logical Volumes (LVs) — virtual partitions: lvcreate -L 100G -n data myvg
LVM Snapshots
LVM snapshots are copy-on-write:
Use snapshots for consistent backups of running databases. The snapshot must be large enough to hold all writes during the backup window.
Thin Provisioning
Thin provisioning overcommits storage — allocating real blocks only when written. Useful for dev environments but dangerous in production without monitoring.
Key concepts
- Physical Volume (PV)
- A disk or partition initialised with pvcreate. Contains LVM metadata and Physical Extents (PE, typically 4 MB each).
- Volume Group (VG)
- A pool of one or more PVs. Logical Volumes are allocated from VG free space.
- Logical Volume (LV)
- A virtual partition within a VG. Has its own device path (/dev/VG/LV). Can span multiple PVs.
- LVM snapshot
- Copy-on-write point-in-time copy of an LV. Used for online backups — the snapshot presents the state at creation time.
- pvmove
- Migrates physical extents from one PV to another within the same VG. Allows hot removal of a disk without downtime.
When to use it
- Growing a volume for a database that is running out of disk space without downtime
- Creating a consistent database backup snapshot while the database is running
- Migrating data across disks with pvmove without taking services offline
Interview questions
- Your /data partition is 95% full. How do you extend it online without restarting the service?
Sign up free to read the full topic
More Linux topics
Start free on Cariara · Coding problems · System design studio