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.
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}1Creates 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}1Creates 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 myvgCreates 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/mylvExpands 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/mylve2fsck -f /dev/myvg/mylvresize2fs /dev/myvg/mylv 1Glvreduce -L 1G /dev/myvg/mylvAfter reduction, remount and verify with df -h.
Step 7: Create a Snapshot (read‑only)
mount -o remount,ro /dev/myvg/mylv /mnt/mylvlvcreate -L 1G -n mylv-snap -p r -s /dev/myvg/mylvmount -o remount,rw /dev/myvg/mylv /mnt/mylvmount /dev/myvg/mylv-snap /mnt/snapThe snapshot is mounted read‑only.
Step 8: Remove LVM Objects
lvremove /dev/myvg/mylv-snappvremove /dev/sdb1vgremove myvgUse the corresponding man pages for details on removing PVs, VGs, and LVs.
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.
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.
