Mastering LVM on Linux: Step‑by‑Step Guide to Create, Extend, and Snapshot Logical Volumes
This tutorial explains Linux Logical Volume Manager (LVM) fundamentals, walks through creating and removing physical volumes, building and deleting volume groups, provisioning logical volumes, formatting and mounting them, and performing size extensions, reductions, and snapshot operations with concrete command examples.
What is LVM?
LVM (Logical Volume Manager) is a Linux storage subsystem that aggregates physical disks or partitions into a single storage pool, allowing dynamic resizing of volumes and more efficient use of disk space.
LVM Components
Physical Volume (PV) : a disk or partition that becomes part of the pool.
Volume Group (VG) : a collection of one or more PVs, treated as a single logical disk.
Logical Volume (LV) : a slice of a VG that can be formatted and used for data storage.
Physical Extent (PE) : the smallest allocation unit inside a VG (default 4 MiB, configurable).
Creating and Removing Physical Volumes
Assuming two unused disks /dev/sdb and /dev/sdc: # pvcreate /dev/sdb /dev/sdc To delete a PV later:
# pvremove /dev/sdcCreating a Volume Group
Combine the two PVs into a VG named my_vg with a 4 MiB PE size: # vgcreate -s 4M my_vg /dev/sdb /dev/sdc Verify with:
# vgsExtending a Volume Group
Add a new PV /dev/sdd to the existing VG:
# vgextend my_vg /dev/sddRemoving a Physical Volume from a VG
Detach /dev/sdd from my_vg:
# vgreduce my_vg /dev/sddRemoving an Entire Volume Group
Delete the VG my_vg completely:
# vgremove my_vgRemoving an Empty VG
If a VG has no allocated LVs, it can be removed automatically:
# vgreduce -a my_vgCreating a Logical Volume
Create a 10 GiB LV named my_lv inside my_vg: # lvcreate -L 10G -n my_lv my_vg List LVs to confirm:
# lvsFormatting and Mounting the LV
# mkdir /LVM
# mkfs.ext4 /dev/my_vg/my_lv
# mount /dev/my_vg/my_lv /LVMExtending an LV
Increase the LV size by 5 GiB, then resize the filesystem:
# lvextend -L +5G /dev/my_vg/my_lv
# resize2fs -f /dev/my_vg/my_lvCheck the new size with df -h.
Reducing an LV
To shrink the LV back to 10 GiB, unmount, check, resize the filesystem, then reduce the LV:
# 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_lvConfirm the new size with df -h.
Taking a Snapshot
Create a 200 MiB snapshot of my_lv named mylv_back:
# lvcreate -s -n mylv_back -L 200M /dev/my_vg/my_lvList snapshots with lvs.
Restoring from a Snapshot
Mount the snapshot and copy its contents back to the original location:
# mkdir /back
# mount /dev/my_vg/mylv_back /back
# cp -a /back/* ./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.
