Unix - UNIX Logical Volume Management (LVM)
Introduction
Logical Volume Management (LVM) is a storage management technology used in UNIX and UNIX-like operating systems that provides a flexible way to manage disk storage. Traditional disk partitioning creates fixed-size partitions that are difficult to resize after creation. LVM solves this problem by introducing a layer of abstraction between physical storage devices and file systems, allowing administrators to dynamically allocate, resize, and manage storage without significant downtime.
LVM is widely used in enterprise environments because it simplifies storage administration and enables efficient utilization of disk resources. Instead of working directly with physical disks and partitions, administrators manage logical storage units that can be expanded, reduced, or moved as needed.
Why LVM is Needed
In traditional disk management, a hard disk is divided into partitions during setup. Once a partition is created, modifying its size can be complicated and risky. If a partition becomes full while another partition has unused space, redistributing storage often requires backups, repartitioning, and restoration of data.
LVM overcomes these limitations by creating a virtual storage pool from one or more physical disks. Storage can then be allocated from this pool as required. This flexibility makes it easier to adapt to changing storage needs. LVM provides advanced features such as online resizing, snapshots, storage migration, and disk aggregation.
LVM Architecture
LVM consists of three main components:
Physical Volumes (PV)
A Physical Volume is the actual storage device used by LVM. It can be:
-
Entire hard disks
-
Disk partitions
-
Solid-state drives (SSDs)
-
Storage area network (SAN) volumes
Before a disk can be used by LVM, it must be initialized as a Physical Volume.
Example:
pvcreate /dev/sdb
This command prepares the disk /dev/sdb for LVM usage.
Volume Groups (VG)
A Volume Group is a collection of one or more Physical Volumes combined into a single storage pool. The Volume Group acts as a container from which logical storage is allocated.
For example:
-
Disk 1 = 100 GB
-
Disk 2 = 200 GB
Combined into a Volume Group:
-
Total Storage Pool = 300 GB
Creating a Volume Group:
vgcreate vgdata /dev/sdb /dev/sdc
This command creates a Volume Group named vgdata.
Logical Volumes (LV)
Logical Volumes are virtual partitions created from the storage available in a Volume Group. Users and applications interact with Logical Volumes just like normal disk partitions.
Example:
lvcreate -L 50G -n lvbackup vgdata
This creates a 50 GB Logical Volume named lvbackup.
The Logical Volume can then be formatted and mounted like any standard partition.
LVM Structure Diagram
Physical Disk 1 (100 GB) ──┐
│
Physical Disk 2 (200 GB) ──┼──► Volume Group (300 GB)
│
Physical Disk 3 (150 GB) ──┘
Volume Group
├── Logical Volume A (100 GB)
├── Logical Volume B (150 GB)
└── Logical Volume C (50 GB)
This structure allows storage to be managed independently of the physical disk layout.
Physical Extents and Logical Extents
LVM divides storage into small blocks called extents.
Physical Extents (PE)
These are chunks of storage within Physical Volumes.
Logical Extents (LE)
These are chunks assigned to Logical Volumes.
Typically, each extent may be 4 MB in size, though the size can vary. LVM maps Logical Extents to Physical Extents automatically.
This mapping provides the flexibility that makes LVM powerful.
Creating an LVM Storage Setup
The typical process involves the following steps:
Step 1: Create Physical Volumes
pvcreate /dev/sdb
pvcreate /dev/sdc
Step 2: Create a Volume Group
vgcreate vgdata /dev/sdb /dev/sdc
Step 3: Create a Logical Volume
lvcreate -L 100G -n lvproject vgdata
Step 4: Create a File System
mkfs.ext4 /dev/vgdata/lvproject
Step 5: Mount the Volume
mount /dev/vgdata/lvproject /project
The Logical Volume is now ready for use.
Extending a Logical Volume
One of the major advantages of LVM is the ability to increase storage space without recreating partitions.
Suppose a Logical Volume becomes full. If free space exists in the Volume Group, it can be expanded.
Example:
lvextend -L +20G /dev/vgdata/lvproject
After extending the volume, the file system can also be expanded.
For an ext4 file system:
resize2fs /dev/vgdata/lvproject
The available storage increases without affecting existing data.
Reducing a Logical Volume
LVM also allows shrinking Logical Volumes when storage is no longer required.
Example:
lvreduce -L 50G /dev/vgdata/lvproject
Care must be taken when reducing volumes because reducing a file system incorrectly can lead to data loss.
Administrators usually back up important data before performing this operation.
Extending a Volume Group
If a Volume Group runs out of space, additional disks can be added.
Example:
pvcreate /dev/sdd
vgextend vgdata /dev/sdd
The new disk immediately becomes part of the storage pool, increasing the available capacity.
LVM Snapshots
A snapshot is a temporary copy of a Logical Volume at a specific point in time.
Snapshots are commonly used for:
-
Backup operations
-
System testing
-
Database maintenance
-
Recovery purposes
Example:
lvcreate -L 5G -s -n snapshot1 /dev/vgdata/lvproject
This creates a snapshot of the existing Logical Volume.
If changes occur after the snapshot is created, the snapshot preserves the original state.
Storage Migration
LVM allows data to be moved from one disk to another while the system remains operational.
Example:
pvmove /dev/sdb
This command transfers data from one physical disk to another disk within the Volume Group.
Benefits include:
-
Hardware upgrades
-
Disk replacement
-
Maintenance operations
-
Load balancing
Viewing LVM Information
Several commands are available to inspect the LVM configuration.
Display Physical Volumes
pvdisplay
Display Volume Groups
vgdisplay
Display Logical Volumes
lvdisplay
Summary Information
pvs
vgs
lvs
These commands provide a quick overview of the storage configuration.
Advantages of LVM
Flexible Storage Management
Storage can be resized without repartitioning disks.
Easier Expansion
Additional disks can be added seamlessly.
Snapshot Support
Point-in-time copies simplify backup and recovery operations.
Storage Pooling
Multiple physical disks can be combined into a single storage resource.
Online Administration
Many operations can be performed without shutting down the system.
Improved Resource Utilization
Unused space can be allocated wherever needed.
Limitations of LVM
Additional Complexity
LVM introduces another layer between storage and the file system.
Learning Curve
Administrators must understand LVM concepts and commands.
Potential Performance Overhead
The abstraction layer may introduce a very small performance cost, although it is generally negligible on modern systems.
Recovery Complexity
If LVM metadata becomes corrupted, recovery procedures can be more complex than traditional partition recovery.
Real-World Applications
LVM is commonly used in:
-
Enterprise UNIX servers
-
Database systems
-
Cloud infrastructure
-
Virtualization platforms
-
Data centers
-
Large-scale storage environments
Organizations use LVM because storage requirements frequently change, and LVM provides the flexibility needed to manage those changes efficiently.
Conclusion
Logical Volume Management is a powerful storage management system that separates logical storage from physical disks. By using Physical Volumes, Volume Groups, and Logical Volumes, administrators gain flexibility in allocating, expanding, reducing, and managing storage resources. Features such as snapshots, online resizing, storage migration, and disk pooling make LVM an essential technology in modern UNIX environments. It simplifies storage administration, improves resource utilization, and supports the dynamic storage requirements of enterprise systems.