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.
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.00gCreating 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.99gAdding 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.00gRemoving 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.00gRemoving an Entire VG
# vgremove my_vg
Volume group "my_vg" successfully removedRemoving 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.00gFormatting 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_lvReducing 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_lvCreating an LVM Snapshot
# lvcreate -s -n mylv_back -L 200M /dev/my_vg/my_lv
# lvsRestoring from a Snapshot
# rm -fr * # simulate data loss
# mkdir /back
# mount /dev/my_vg/mylv_back /back/
# cp -a /back/* ./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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
