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.
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
pvsCreating 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
vgsAdding a New PV to an Existing VG
# Extend the VG with an additional disk
vgextend my_vg /dev/sdd
# Verify the addition
pvsRemoving a Single PV from a VG
# Remove /dev/sdd from my_vg
vgreduce my_vg /dev/sdd
# Verify the removal
pvsRemoving an Entire VG
# List VGs
vgs
# Delete the VG named my_vg
vgremove my_vg
# Confirm removal
vgsRemoving an Empty VG
# Remove a VG that has no allocated space
vgreduce -a my_vg
# Verify the result
vgsCreating 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
lvsFormatting 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 -hShrinking 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 -hCreating 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
lvsRestoring 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 /backOriginal source: https://www.cnblogs.com/LyShark/p/10167313.html
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.)
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.
