Skip to main content

What is LVM?

In one sentence

LVM is a tool in Linux that allows you to resize, combine, and manage storage space without needing to turn off the server or losing data.

Definition

When you partition a hard disk or SSD, the size of each partition is usually fixed. If one of the partitions runs out of space, changing it is difficult and data may be lost.

LVM acts as an intelligent layer between the disk and the operating system. With LVM, you can:

  • Make a partition larger without turning off the server
  • Combine multiple disks together to create a larger space
  • Manage storage space more flexibly

LVM (Logical Volume Manager) is an abstraction layer between Block Devices (disks or partitions) and the File System that works at the Linux Kernel level.

LVM provides dynamic storage space management capabilities, including:

  • Online Resize (Growing/Shrinking Volumes without Downtime)
  • Aggregation (Combining multiple Physical Volumes into one Volume Group)
  • Snapshot (Taking a point-in-time image of a Volume)
  • Thin Provisioning (Allocating more than actual capacity)
  • Striping and Mirroring at the software level

Why did LVM come into existence?

Before LVM, storage management in Linux had serious limitations:

ProblemDescription
Fixed Partition SizeAfter creating a partition, resizing it was very difficult
Partition Count LimitationIn MBR, a maximum of 4 Primary partitions could be created
Inability to Combine DisksMultiple disks could not be simply combined together
High Risk of ChangesAny change in disk structure required Downtime and carried the risk of data loss

LVM solved these problems and made storage management dynamic and flexible.

LVM Architecture

LVM consists of three main layers:

HDD / SSD / Logical DrivePhysical Disk / PartitionHDD / SSD / Logical DrivepvcreatePhysical Volume (PV)pvcreatevgcreateVolume Group (VG)vgcreatelvcreateLogical Volume (LV)lvcreateext4 / XFSFile Systemext4 / XFS

Explanation of Each Layer

LayerFull NameSimple DescriptionTechnical Description
PVPhysical VolumeA disk or partition introduced to LVMA Block Device prepared for use in LVM with pvcreate
VGVolume GroupA large pool of space made from one or more PVsA collection of PVs that aggregates their space and divides them into units called PE (Physical Extent)
LVLogical VolumeA space similar to a partition used by the OSPart of a VG created with lvcreate on which a File System can be built

A Simple Example

Assume a server has two Logical Drives:

  • Logical Drive 1: Capacity 500GB
  • Logical Drive 2: Capacity 500GB

Without LVM, each Logical Drive is usable only separately. But with LVM:

Step 1: You introduce both Logical Drives as PVs.

Step 2: You place both PVs in one VG. Now you have a 1TB pool.

Step 3: From this pool, you create as many LVs as needed.

For example:

Logical VolumeSizeMount PointUsage
lv-root100GB/Operating System
lv-var200GB/varLogs and variable data
lv-data600GB/dataVirtual Machines and data
Free100GBFor future needs
Note

With LVM, you do not need to allocate all space from the beginning. You can keep part of the space free and expand any LV in the future.

LVM vs Traditional Partitioning

FeatureTraditional PartitioningLVM
Online Resize❌ Usually requires Downtime✅ Growing online without Downtime
Combining Multiple Disks❌ Not possible✅ Multiple PVs in one VG
Snapshot❌ Not supported✅ Has Snapshot capability
Thin Provisioning❌ Not supported✅ Allocation over actual capacity
Complexity✅ Simpler⚠️ Requires learning and caution
Troubleshooting✅ More direct⚠️ Extra layer complicates troubleshooting

Common LVM Operations

Building LVM Structure from Scratch

# Step 1: Create Physical Volume
pvcreate /dev/sdb

# Step 2: Create Volume Group
vgcreate vg-data /dev/sdb

# Step 3: Create Logical Volume
lvcreate -L 200G -n lv-data vg-data

# Step 4: Create File System
mkfs.xfs /dev/vg-data/lv-data

# Step 5: Mount
mount /dev/vg-data/lv-data /data

Expanding an LV (Without Downtime)

# Increase LV size by an additional 100 GB
lvextend -L +100G /dev/vg-data/lv-data

# Grow File System (for XFS)
xfs_growfs /data

# Grow File System (for ext4)
resize2fs /dev/vg-data/lv-data

Adding New Disk to VG

# Introduce new disk as PV
pvcreate /dev/sdc

# Add new PV to existing VG
vgextend vg-data /dev/sdc
Key Benefit

By adding a new disk to VG, the storage pool's capacity increases without any Downtime, and existing LVs can be expanded.

Checking LVM Status

# Display Physical Volumes
pvs
pvdisplay

# Display Volume Groups
vgs
vgdisplay

# Display Logical Volumes
lvs
lvdisplay

LVM Snapshot

One of LVM's important features is the ability to take a Snapshot.

A Snapshot is a point-in-time image of an LV's status at a specific moment.

Use Cases for Snapshots

  • Backup without Downtime: Take a Snapshot before Backup, then backup from the Snapshot.
  • Testing Changes: Take a Snapshot before updating or making changes. If a problem occurs, revert to the previous state.
  • Development Environment: Use Snapshots to create test environments.

Snapshot Creation Example

# Create Snapshot of lv-data with size 50 GB
lvcreate -s -L 50G -n lv-data-snap /dev/vg-data/lv-data
Attention

Snapshots consume extra space. If the space allocated to the Snapshot fills up, the Snapshot automatically becomes invalid. Choose an appropriate size considering the volume of changes.

Thin Provisioning

In normal LVM, when you create an LV with a capacity of say 500GB, this space is reserved from the VG immediately even if no data is written on it yet.

Thin Provisioning solves this problem:

FeatureNormal LVM (Thick)LVM Thin
Space ReservationEntire space reserved immediatelyOnly actually used space is occupied
Over-Provisioning❌ Not possible✅ Can allocate more than real capacity
Performance✅ Slightly better⚠️ Slight overhead exists
Monitoring NeedNormal⚠️ Strict space monitoring is essential
Important Warning

In Thin Provisioning, if the actual Pool space runs out and there is no proper monitoring, data loss or service stoppage may occur.

Position of LVM in Storage Structure

To better understand LVM's place in the whole structure, pay attention to this diagram:

HDD / SSDPhysical DiskHDD / SSDHardware RAIDRAID ControllerHardware RAIDVirtual DiskLogical DriveVirtual DiskLVM Layer 1PV (Physical Volume)LVM Layer 1LVM Layer 2VG (Volume Group)LVM Layer 2LVM Layer 3LV (Logical Volume)LVM Layer 3ext4 / XFSFile Systemext4 / XFS
Clarification

Logical Volume in LVM is different from Logical Drive in RAID Controller.

  • Logical Drive is created by the RAID Controller from physical disks
  • Logical Volume is created by LVM at the Operating System level

These two concepts are located in different layers and should not be confused.

Role of LVM in Plaivid

In the Plaivid architecture, using LVM is recommended in most scenarios.

Common suggested structure:

VGLVMount PointUsage
vg-oslv-root/Operating system and system files
vg-oslv-swapswapSwap Memory
vg-varlv-var/varLogs and variable data
vg-datalv-data/dataVirtual Machines and Workloads

Benefits of this Design

  • Flexibility: In the future if /var or /data runs out of space, it can be grown without Downtime
  • Workload Separation: OS data is separated from work data
  • Easier Management: Each VG can be on a separate Logical Drive
  • Snapshot: Possibility of taking Snapshots of sensitive LVs before important operations
Practical Advice

When installing Plaivid, it is recommended to keep 10 to 20 percent of each VG's space free. This free space is very valuable for Snapshot operations, growing LVs, and crisis management.

Important Notes for IT Experts

Choosing the Right File System

File SystemOnline GrowShrinkSuitable For
XFS✅ Yes❌ NoHeavy Workloads, Datastore
ext4✅ Yes✅ Yes (with caution)General use, Operating System
Note

If you think you might need to shrink an LV in the future, use ext4. XFS can only grow.

PE Size (Physical Extent)

  • Default PE size in most distributions is 4MB
  • For large VGs (several terabytes), increasing PE Size can make management easier
  • PE Size cannot be changed after creating the VG

LVM Performance

  • LVM adds a software layer, but its Overhead is negligible in most scenarios
  • In very heavy I/O scenarios, ensure Alignment is done correctly
  • Using LVM Cache can allow combining SSD and HDD for performance improvement

Conclusion

LVM is a powerful tool for flexible storage space management in Linux.

If we want to put it very simply:

  • Without LVM: Space size is fixed, and changing it is difficult and risky
  • With LVM: Space can be grown without Downtime, multiple disks combined, and Snapshots taken
ConceptWhat is it?Created By What?
Physical DiskReal disk inside the serverHardware
Logical DriveLogical disk built by RAIDRAID Controller
PVDisk introduced to LVMpvcreate
VGSpace pool from one or multiple PVsvgcreate
LVUsable space similar to a partitionlvcreate
File SystemFile structure on LVmkfs

Consequently, in professional infrastructures, using LVM is not just a choice but a necessity for dynamic and reliable storage management.