Operations 11 min read

Master Linux LVM: Create, Extend, Shrink, and Snapshot Volumes

This guide walks through creating Linux LVM physical volumes, volume groups, and logical volumes on four 1 GB disks, demonstrates formatting, mounting, extending, shrinking, and snapshotting volumes, and provides the necessary commands for managing and removing LVM components.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Linux LVM: Create, Extend, Shrink, and Snapshot Volumes

Step 1: Partition Disks

Use fdisk /dev/sdb (repeat for /dev/sdc, /dev/sdd, /dev/sde) to create a single primary partition, set the type to 8e (Linux LVM), and write the table.

Step 2: Create Physical Volumes

pvcreate /dev/sd{b,c,d,e}1

Creates PVs on all four disks. pvs Shows each PV with size around 1004 MiB. pvdisplay /dev/sdb1 Displays detailed information for the first PV.

Step 3: Create Volume Group

vgcreate myvg /dev/sd{b,c,d}1

Creates volume group "myvg" with three PVs (default PE size 4 MiB). vgextend myvg /dev/sde1 Adds the fourth PV, increasing VG size. vgs Shows VG size and free space.

Step 4: Create Logical Volume

lvcreate -L 2G -n mylv myvg

Creates a 2 GiB logical volume named "mylv". lvdisplay /dev/myvg/mylv Shows LV attributes. mkfs.ext4 /dev/myvg/mylv Formats the LV with ext4. mkdir /mnt/mylv && mount /dev/myvg/mylv /mnt/mylv Mounts the LV; add an entry to /etc/fstab for permanent mounting.

Step 5: Extend the LV

lvextend -L 3G /dev/myvg/mylv

Expands the LV to 3 GiB. resize2fs /dev/myvg/mylv Resizes the filesystem to use the new space. df -h Shows the updated size.

Step 6: Reduce the LV (offline)

Unmount the LV, check the filesystem, shrink the filesystem, then shrink the LV.

umount /mnt/mylv
e2fsck -f /dev/myvg/mylv
resize2fs /dev/myvg/mylv 1G
lvreduce -L 1G /dev/myvg/mylv

After reduction, remount and verify with df -h.

Step 7: Create a Snapshot (read‑only)

mount -o remount,ro /dev/myvg/mylv /mnt/mylv
lvcreate -L 1G -n mylv-snap -p r -s /dev/myvg/mylv
mount -o remount,rw /dev/myvg/mylv /mnt/mylv
mount /dev/myvg/mylv-snap /mnt/snap

The snapshot is mounted read‑only.

Step 8: Remove LVM Objects

lvremove /dev/myvg/mylv-snap
pvremove /dev/sdb1
vgremove myvg

Use the corresponding man pages for details on removing PVs, VGs, and LVs.

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.

LinuxstoragesnapshotLVMFilesystemVolume Management
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.