Operations 10 min read

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.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Mastering LVM on Linux: Step‑by‑Step Guide to Create, Extend, and Snapshot Logical Volumes

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/sdc

Creating 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:

# vgs

Extending a Volume Group

Add a new PV /dev/sdd to the existing VG:

# vgextend my_vg /dev/sdd

Removing a Physical Volume from a VG

Detach /dev/sdd from my_vg:

# vgreduce my_vg /dev/sdd

Removing an Entire Volume Group

Delete the VG my_vg completely:

# vgremove my_vg

Removing an Empty VG

If a VG has no allocated LVs, it can be removed automatically:

# vgreduce -a my_vg

Creating 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:

# lvs

Formatting and Mounting the LV

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

Extending 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_lv

Check 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_lv

Confirm 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_lv

List 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/* ./
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 AdministrationLVM
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.