Operations 10 min read

Mastering LVM: Step‑by‑Step Guide to Create, Resize, and Snapshot Logical Volumes

This tutorial explains Linux LVM fundamentals, covering physical volumes, volume groups, logical volumes, and physical extents, and provides detailed commands for creating, extending, shrinking, removing, and snapshotting LVM components with practical examples.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Mastering LVM: Step‑by‑Step Guide to Create, Resize, and Snapshot Logical Volumes

LVM (Logical Volume Manager) is a Linux mechanism that aggregates physical disks into a single storage pool, allowing dynamic resizing of volumes for better utilization.

Physical Volume (PV) : a disk or partition converted into a physical volume.

Volume Group (VG) : a collection of one or more PVs, treated as a single large disk.

Logical Volume (LV) : a partition within a VG that can be formatted and store data.

Physical Extent (PE) : the smallest allocatable unit in a VG, default 4 MB but configurable.

Creating/Removing Physical Volumes (PV)

# ll /dev/sd[b-z]
brw-rw---- 1 root disk 8,16 Sep 21 22:04 /dev/sdb
brw-rw---- 1 root disk 8,32 Sep 21 22:04 /dev/sdc
# pvcreate /dev/sdb /dev/sdc
# pvremove /dev/sdc
# pvs
PV         VG     Fmt  Attr PSize   PFree
/dev/sda2  centos lvm2 a--  <9.00g   0
/dev/sdb          lvm2 ---  10.00g 10.00g

Creating a Volume Group (VG)

# vgcreate -s [PE size] [VG name] /dev/sdb /dev/sdc
# vgs
VG       #PV #LV #SN Attr   VSize   VFree
centos   1   2   0  wz--n- <9.00g   0
my_vg    2   0   0  wz--n- 19.99g 19.99g

Adding a New PV to a VG

# vgextend my_vg /dev/sdd
# pvs
PV         VG     Fmt  Attr PSize   PFree
/dev/sda2  centos lvm2 a--  <9.00g   0
/dev/sdb   my_vg  lvm2 a--  <10.00g <10.00g
/dev/sdc   my_vg  lvm2 a--  <10.00g <10.00g
/dev/sdd   my_vg  lvm2 a--  <10.00g <10.00g

Removing a Single PV from a VG

# vgreduce my_vg /dev/sdd
# pvs
PV         VG     Fmt  Attr PSize   PFree
/dev/sda2  centos lvm2 a--  <9.00g   0
/dev/sdb   my_vg  lvm2 a--  <10.00g <10.00g
/dev/sdc   my_vg  lvm2 a--  <10.00g <10.00g
/dev/sdd          lvm2 ---  10.00g 10.00g

Removing an Entire VG

# vgremove my_vg
Volume group "my_vg" successfully removed

Removing an Empty VG # vgreduce -a my_vg Creating a Logical Volume (LV)

# lvcreate -L 10G -n my_lv my_vg
# lvs
LV      VG     Attr       LSize
root    centos -wi-ao---- <8.00g
swap    centos -wi-ao---- 1.00g
my_lv   my_vg  -wi-a----- 10.00g

Formatting and Mounting the LV

# mkdir /LVM
# mkfs.ext4 /dev/my_vg/my_lv
# mount /dev/my_vg/my_lv /LVM/

Extending LV Capacity

# lvextend -L +5G /dev/my_vg/my_lv
# resize2fs -f /dev/my_vg/my_lv

Reducing LV Capacity

# umount /dev/my_vg/my_lv
# e2fsck -f /dev/my_vg/my_lv
# resize2fs -f /dev/my_vg/my_lv 10G
# lvreduce -L 10G /dev/my_vg/my_lv

Creating an LVM Snapshot

# lvcreate -s -n mylv_back -L 200M /dev/my_vg/my_lv
# lvs

Restoring from a Snapshot

# rm -fr *               # simulate data loss
# mkdir /back
# mount /dev/my_vg/mylv_back /back/
# cp -a /back/* ./
LinuxSystem AdministrationLVMLogical Volume Manager
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

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.