Operations 11 min read

Master LVM on Linux: Create, Extend, Reduce, and Snapshot Volumes

This guide explains Linux LVM fundamentals, covering physical volume creation, volume group management, logical volume operations such as creation, resizing, removal, as well as snapshot creation and restoration, complete with practical command-line examples for each step.

Raymond Ops
Raymond Ops
Raymond Ops
Master LVM on Linux: Create, Extend, Reduce, and Snapshot Volumes

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

Physical Volume (PV): a physical partition created from a disk or partition.

Volume Group (VG): a collection of PVs, treated as a single storage unit.

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

Physical Extent (PE): the smallest allocation unit in a VG, default 4 MiB, configurable.

Create/Remove Physical Volumes (PV)

Use existing disks (e.g., /dev/sdb /dev/sdc) and add them to a 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   # create PVs
# pvremove /dev/sdc            # remove a PV
# pvs
PV   VG   Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <9.00g 0
/dev/sdb  lvm2   --- 10.00g 10.00g

Create a Volume Group (VG)

Create a VG from existing PVs.

# vgcreate -s [PE size] [VG name] [PV paths...]
# vgcreate -s 4M my_vg /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

Add a New PV to an Existing VG

Extend the VG by adding another PV.

# 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

Remove a Single PV from a VG

Remove a specific PV from the VG.

# vgreduce my_vg /dev/sdd
# pvs
... (output showing /dev/sdd removed)

Remove an Entire VG

Delete the VG completely.

# vgremove my_vg
Volume group "my_vg" successfully removed

Remove an Empty VG

Remove a VG that has no allocated space.

# vgreduce -a my_vg   # removes only empty VGs

Create a Logical Volume (LV)

Create an LV named my_lv of 10 GiB in my_vg.

# lvcreate -L 10G -n my_lv my_vg
# lvs
LV     VG   Attr   LSize
my_lv  my_vg -wi-a----- 10.00g

Format and Mount the LV

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

Extend LV Capacity

Increase LV size by 5 GiB and resize the filesystem.

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

Reduce LV Capacity

Shrink LV from 15 GiB to 10 GiB.

# 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
# mount /dev/my_vg/my_lv /LVM/

Create an LVM Snapshot

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

Restore from a Snapshot

# mkdir /back
# mount /dev/my_vg/mylv_back /back/
# cp -a /back/* ./
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxstorageLVMVolume 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

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.