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.

<code># 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
</code>

Create a Volume Group (VG)

Create a VG from existing PVs.

<code># 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
</code>

Add a New PV to an Existing VG

Extend the VG by adding another PV.

<code># 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
</code>

Remove a Single PV from a VG

Remove a specific PV from the VG.

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

Remove an Entire VG

Delete the VG completely.

<code># vgremove my_vg
Volume group "my_vg" successfully removed
</code>

Remove an Empty VG

Remove a VG that has no allocated space.

<code># vgreduce -a my_vg   # removes only empty VGs
</code>

Create a Logical Volume (LV)

Create an LV named

my_lv

of 10 GiB in

my_vg

.

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

Format and Mount the LV

<code># mkdir /LVM
# mkfs.ext4 /dev/my_vg/my_lv
# mount /dev/my_vg/my_lv /LVM/
</code>

Extend LV Capacity

Increase LV size by 5 GiB and resize the filesystem.

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

Reduce LV Capacity

Shrink LV from 15 GiB to 10 GiB.

<code># 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/
</code>

Create an LVM Snapshot

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

Restore from a Snapshot

<code># mkdir /back
# mount /dev/my_vg/mylv_back /back/
# cp -a /back/* ./
</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.