What is LVM?
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:
| Problem | Description |
|---|---|
| Fixed Partition Size | After creating a partition, resizing it was very difficult |
| Partition Count Limitation | In MBR, a maximum of 4 Primary partitions could be created |
| Inability to Combine Disks | Multiple disks could not be simply combined together |
| High Risk of Changes | Any 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:
Explanation of Each Layer
| Layer | Full Name | Simple Description | Technical Description |
|---|---|---|---|
| PV | Physical Volume | A disk or partition introduced to LVM | A Block Device prepared for use in LVM with pvcreate |
| VG | Volume Group | A large pool of space made from one or more PVs | A collection of PVs that aggregates their space and divides them into units called PE (Physical Extent) |
| LV | Logical Volume | A space similar to a partition used by the OS | Part 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 Volume | Size | Mount Point | Usage |
|---|---|---|---|
lv-root | 100GB | / | Operating System |
lv-var | 200GB | /var | Logs and variable data |
lv-data | 600GB | /data | Virtual Machines and data |
| Free | 100GB | — | For future needs |
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
| Feature | Traditional Partitioning | LVM |
|---|---|---|
| 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
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
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:
| Feature | Normal LVM (Thick) | LVM Thin |
|---|---|---|
| Space Reservation | Entire space reserved immediately | Only actually used space is occupied |
| Over-Provisioning | ❌ Not possible | ✅ Can allocate more than real capacity |
| Performance | ✅ Slightly better | ⚠️ Slight overhead exists |
| Monitoring Need | Normal | ⚠️ Strict space monitoring is essential |
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:
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:
| VG | LV | Mount Point | Usage |
|---|---|---|---|
vg-os | lv-root | / | Operating system and system files |
vg-os | lv-swap | swap | Swap Memory |
vg-var | lv-var | /var | Logs and variable data |
vg-data | lv-data | /data | Virtual Machines and Workloads |
Benefits of this Design
- Flexibility: In the future if
/varor/dataruns 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
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 System | Online Grow | Shrink | Suitable For |
|---|---|---|---|
| XFS | ✅ Yes | ❌ No | Heavy Workloads, Datastore |
| ext4 | ✅ Yes | ✅ Yes (with caution) | General use, Operating System |
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
| Concept | What is it? | Created By What? |
|---|---|---|
| Physical Disk | Real disk inside the server | Hardware |
| Logical Drive | Logical disk built by RAID | RAID Controller |
| PV | Disk introduced to LVM | pvcreate |
| VG | Space pool from one or multiple PVs | vgcreate |
| LV | Usable space similar to a partition | lvcreate |
| File System | File structure on LV | mkfs |
Consequently, in professional infrastructures, using LVM is not just a choice but a necessity for dynamic and reliable storage management.