Operations 31 min read

Mastering LVM on Linux: From Basics to Advanced Operations

This comprehensive guide explains Linux Logical Volume Manager (LVM) concepts, terminology, installation, essential commands, and step‑by‑step procedures for creating, extending, reducing, migrating, and snapshotting physical, volume, and logical volumes, empowering system administrators to manage storage flexibly and safely.

Raymond Ops
Raymond Ops
Raymond Ops
Mastering LVM on Linux: From Basics to Advanced Operations

LVM Overview

LVM is the Logical Volume Manager for Linux. There are two versions: LVM1 (stable) and LVM2 (latest, fully backward compatible except for snapshots).

LVM Introduction

Logical volume management provides a higher‑level view of disk storage than traditional partitions, allowing flexible allocation to applications and users.

Volumes can be resized and moved under LVM control, though filesystem tools may need updates.

LVM also lets you group volumes into named volume groups (e.g., "development") instead of raw device names.

Basic LVM Terminology

Volume Group (VG)

A VG is the highest‑level abstraction, grouping logical and physical volumes into a single management unit.

Physical Volume (PV)

A PV is usually a whole disk or a device that appears as a disk (e.g., software RAID).

Logical Volume (LV)

An LV corresponds to a partition in non‑LVM systems; it appears as a standard block device and can host a filesystem.

Physical Extent (PE)

Each PV is divided into fixed‑size blocks called physical extents.

Logical Extent (LE)

Each LV is divided into logical extents of the same size as PEs.

Mapping Example

Example with VG1 of 4 MiB PE size, two disks /dev/hda1 and /dev/hdb1 become PV1 and PV2, illustrating how logical extents map to physical extents.

Mapping Modes

Linear mapping assigns a range of PEs to an LV region. Striped mapping interleaves extents across multiple PVs to improve performance.

Snapshots

Snapshots create a read‑only copy of an LV at a point in time using copy‑on‑write; they grow as the original LV changes.

Installing LVM

<code>[root@centos7 ~]$ rpm -q lvm2   # check if lvm2 is installed
lvm2-2.02.171-8.el7.x86_64
[root@centos7 ~]$ yum -y install lvm2   # install if missing
</code>

Common Commands

<code>[root@centos7 ~]$ pv          # tab‑completion shows pv commands
pvchange pvck pvcreate pvdisplay pvmove pvremove pvresize pvs pvscan
[root@centos7 ~]$ vg          # tab‑completion shows vg commands
vgcfgbackup vgck vgdisplay vgimport vgmknodes vgrename vgsplit
vgcfgrestore vgconvert vgexport vgimportclone vgreduce vgs vgchange vgcreate vgextend vgmerge vgremove vgscan
[root@centos7 ~]$ lv          # tab‑completion shows lv commands
lvchange lvdisplay lvmconf lvmdump lvmsadc lvremove lvs
lvconvert lvextend lvmconfig lvmetad lvmsar lvrename lvscan
lvcreate lvm lvmdiskscan lvmpolld lvreduce lvresize
</code>

Brief notes on command prefixes:

pv‑

for physical volume,

vg‑

for volume group,

lv‑

for logical volume; create, remove, display, etc.

Using LVM

Creating a Physical Volume

Initialize a disk or partition before using it as a PV.

<code>[root@centos7 ~]$ pvcreate /dev/sdb1
</code>

Note: Do not initialize an entire disk if other OSes need to recognize it; use partitions and set type to 8e (Linux LVM).

Partitioning and Setting Type

<code>[root@centos7 ~]$ fdisk -l
...
/dev/sdb1  2048 2099199  1048576  8e  Linux LVM
...
</code>

After partitioning, run

partprobe

and

lsblk

to verify.

Viewing PV Information

<code>[root@centos7 ~]$ pvs
PV          VG          Fmt Attr PSize   PFree
/dev/sdb1   vg_test_01 lvm2 a-- 1020.00m 1020.00m
...</code>

Creating a Volume Group

<code>[root@centos7 ~]$ vgcreate vg_test_01 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
Volume group "vg_test_01" successfully created
</code>

Viewing VG Information

<code>[root@centos7 ~]$ vgs
VG          #PV #LV #SN Attr   VSize VFree
vg_test_01   4   0   0 wz--n- 3.98g 3.98g
</code>

Activating/Deactivating a VG

<code>[root@centos7 ~]$ vgchange -a y vg_test_01
0 logical volume(s) in volume group "vg_test_01" now active
[root@centos7 ~]$ vgchange -a n vg_test_01
0 logical volume(s) in volume group "vg_test_01" now inactive
</code>

Extending a VG

<code>[root@centos7 ~]$ vgextend vg_test_01 /dev/sdb2
Volume group "vg_test_01" successfully extended
</code>

Reducing a VG

<code>[root@centos7 ~]$ vgreduce vg_test_01 /dev/sdb2
Removed "/dev/sdb2" from volume group "vg_test_01"
</code>

Creating a Logical Volume

<code>[root@centos7 ~]$ lvcreate -L 2G -n lv_test_01 vg_test_01
Logical volume "lv_test_01" created
</code>

Removing a Logical Volume

<code>[root@centos7 ~]$ lvremove /dev/vg_test_01/lv_test_01
Do you really want to remove active logical volume vg_test_01/lv_test_01? [y/n]: y
Logical volume "lv_test_01" successfully removed
</code>

Note: Unmount the LV before removal.

Formatting and Mounting

<code>[root@centos7 ~]$ mkfs.ext4 /dev/vg_test_01/lv_test_01
[root@centos7 ~]$ mkdir /mnt/test_01
[root@centos7 ~]$ mount /dev/vg_test_01/lv_test_01 /mnt/test_01
</code>

Extending an LVM

Increase an LV by 1 GiB, then resize the filesystem.

<code>[root@centos7 ~]$ lvextend -L +1G /dev/vg_test_01/lv_test_01
Size of logical volume vg_test_01/lv_test_01 changed from 2.00 GiB to 3.00 GiB
[root@centos7 ~]$ resize2fs /dev/mapper/vg_test_01-lv_test_01
</code>

Reducing an LVM

Before shrinking an LV, shrink the filesystem, then reduce the LV size.

<code>[root@centos7 ~]$ umount /dev/vg_test_01/lv_test_01
[root@centos7 ~]$ resize2fs /dev/vg_test_01/lv_test_01 1G
[root@centos7 ~]$ e2fsck -f /dev/vg_test_01/lv_test_01
[root@centos7 ~]$ lvreduce -L 1G /dev/vg_test_01/lv_test_01
</code>

ext and xfs filesystems cannot be reduced.

Migrating a VG to Another Machine

Check and analyze.

Pre‑process.

Unmount filesystems.

Deactivate the VG.

Export the VG (

vgexport

).

Move the disks to the new host.

Import the VG (

vgimport

).

Activate the VG.

Mount the LV.

Example commands for export, import, and verification are shown.

Using Snapshots

Create a read‑only snapshot of an LV for backup.

<code>[root@centos6 ~]$ lvcreate -L 500M -s -p r -n vg_test_01_snapshot /dev/vg_test_01/lv_test_01
Logical volume "vg_test_01_snapshot" created.
</code>

Mount the snapshot read‑only, back up data, then remove the snapshot.

<code>[root@centos6 ~]$ mount /dev/vg_test_01/vg_test_01_snapshot /mnt/test_bak
mount: block device /dev/mapper/vg_test_01-vg_test_01_snapshot is write-protected, mounting read-only
[root@centos6 ~]$ umount /mnt/test_bak
[root@centos6 ~]$ lvremove /dev/vg_test_01/vg_test_01_snapshot
Do you really want to remove active logical volume vg_test_01_snapshot? [y/n]: y
Logical volume "vg_test_01_snapshot" successfully removed
</code>
LinuxstorageSystem AdministrationLVMVolume Management
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.