Operations 10 min read

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

This tutorial explains Linux LVM fundamentals, walks through creating and removing physical volumes, building volume groups, managing logical volumes—including formatting, mounting, extending, shrinking—and demonstrates how to take and restore snapshots using concrete command‑line examples.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux LVM: Step‑by‑Step Guide to Create, Resize, and Snapshot Logical Volumes

LVM (Logical Volume Manager) is a Linux storage subsystem that aggregates physical disks into a flexible pool, allowing dynamic resizing of partitions and better utilization of disk space.

Key LVM Components

Physical Volume (PV) : a disk or partition that becomes a physical storage unit.

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

Logical Volume (LV) : a partition carved out of a VG; it can be formatted and used to store data.

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

Creating and Removing Physical Volumes

# List available disks
ll /dev/sd[b-z]
# Create PVs on two disks
pvcreate /dev/sdb /dev/sdc
# Remove a PV (example)
pvremove /dev/sdc
# Verify PVs
pvs

Creating a Volume Group

# Show current PVs
pvs
# Create a VG named my_vg using the two PVs, with 4 MiB PE size
vgcreate -s 4M my_vg /dev/sdb /dev/sdc
# List VGs
vgs

Adding a New PV to an Existing VG

# Extend the VG with an additional disk
vgextend my_vg /dev/sdd
# Verify the addition
pvs

Removing a Single PV from a VG

# Remove /dev/sdd from my_vg
vgreduce my_vg /dev/sdd
# Verify the removal
pvs

Removing an Entire VG

# List VGs
vgs
# Delete the VG named my_vg
vgremove my_vg
# Confirm removal
vgs

Removing an Empty VG

# Remove a VG that has no allocated space
vgreduce -a my_vg
# Verify the result
vgs

Creating a Logical Volume

# Create a 10 GiB LV named my_lv in my_vg
lvcreate -L 10G -n my_lv my_vg
# List LVs to confirm
lvs

Formatting and Mounting the LV

# Create a mount point
mkdir /LVM
# Format the LV with ext4
mkfs.ext4 /dev/my_vg/my_lv
# Mount it
mount /dev/my_vg/my_lv /LVM/

Extending the LV (Resize Up)

# Check current size
df -h
# Add 5 GiB to the LV
lvextend -L +5G /dev/my_vg/my_lv
# Resize the filesystem
resize2fs -f /dev/my_vg/my_lv
# Verify new size
df -h

Shrinking the LV (Resize Down)

# Unmount the LV
umount /dev/my_vg/my_lv
# Check filesystem integrity
e2fsck -f /dev/my_vg/my_lv
# Reduce filesystem to 10 GiB
resize2fs -f /dev/my_vg/my_lv 10G
# Reduce the LV itself
lvreduce -L 10G /dev/my_vg/my_lv
# Remount and verify
mount /dev/my_vg/my_lv /LVM/
df -h

Creating a Snapshot

# Take a 200 MiB snapshot of my_lv
lvcreate -s -n mylv_back -L 200M /dev/my_vg/my_lv
# List LVs to see the snapshot
lvs

Restoring from a Snapshot

# Simulate data loss, then mount the snapshot
mkdir /back
mount /dev/my_vg/mylv_back /back/
# Copy data back to the original LV
cp -a /back/* /LVM/
# (Optional) Unmount and clean up
umount /back
Original source: https://www.cnblogs.com/LyShark/p/10167313.html
LVM diagram
LVM diagram
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.

LinuxstorageSystem AdministrationLVMVolume Management
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

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.