Mastering LVM on Linux: Step‑by‑Step Guide to Create, Extend, and Manage Logical Volumes
This article provides a comprehensive, hands‑on tutorial for Linux Logical Volume Manager (LVM), covering installation environment setup, creating physical volumes, volume groups, logical volumes, extending them, resizing file systems, and adding new disks, complete with command‑line examples and explanations.
1. Introduction to LVM
LVM (Logical Volume Manager) adds a flexible abstraction layer between physical disks and file systems, allowing dynamic resizing of partitions without data loss. It groups multiple disks into volume groups (VG) and creates logical volumes (LV) that can be resized on demand.
2. Test Environment
Platform: VMware Workstation 17 Pro Guest OS: Rocky Linux 8.9
3. Practical Examples
3.1 Create Physical Volume (PV)
parted /dev/sdb print # view disk info
pvcreate /dev/sdb # create PVVerify PV status:
pvscan
pvs
pvdisplay /dev/sdb3.2 Create Volume Group (VG)
vgcreate vgtest /dev/sdb # create VG named vgtestCheck VG status:
vgscan
vgs
vgdisplay vgtest3.3 Create Logical Volume (LV)
lvcreate -l 100%FREE vgtest -n lvtest # allocate all VG space to LVView LV information:
lvscan
lvs
lvdisplay vgtest/lvtest3.4 Extend Logical Volume
Increase LV size by 200 MiB: lvextend -L +200M vgtest2/lvtest2 Or extend by a number of extents: lvextend -l +25 vgtest2/lvtest2 Allocate all free space:
lvextend -l +100%FREE vgtest2/lvtest23.5 Mount and Persistently Mount LV
mkfs.xfs /dev/vgtest2/lvtest2 # create XFS filesystem
mkdir /data
mount /dev/vgtest2/lvtest2 /data
blkid /dev/vgtest2/lvtest2 # get UUID
# Add to /etc/fstab for permanent mount
UUID="544fae3b-7d08-4090-a6a7-aa5bcc4d9be0" /data xfs defaults 0 03.6 Expand VG with New Disks
Rescan SCSI hosts to detect new disks, then create a new PV and extend the VG:
echo "- - -" > /sys/class/scsi_host/host0/scan
# repeat for host1, host2
pvcreate /dev/sdf
vgextend vgtest2 /dev/sdfAfter extending the VG, enlarge the LV and the filesystem:
lvextend -l +100%FREE vgtest2/lvtest2
xfs_growfs /dev/vgtest2/lvtest23.7 Resize LV and Filesystem in One Step
pvcreate /dev/sdg
vgextend vgtest2 /dev/sdg
lvextend -L +5G -r vgtest2/lvtest2 # extend LV by 5 GiB and resize XFS automaticallyThe article demonstrates the full lifecycle of LVM management: creating PVs, VGs, LVs, extending them, mounting, and handling storage growth without rebooting.
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.
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.
