Master LVM: Create, Resize, and Delete Logical Volumes on Linux
This tutorial walks through preparing physical disks, creating physical volumes, a volume group, and multiple logical volumes, formatting and mounting them, dynamically expanding storage, and safely removing LVM components on a Linux system.
1. Prepare physical devices
List the target disks:
lsblk /dev/sdb /dev/sdc2. Create physical volumes
Initialize the disks as physical volumes: pvcreate /dev/sdb /dev/sdc Verify with:
pvs
pvdisplay /dev/sdb
pvdisplay /dev/sdc3. Create a volume group
Create a volume group named myvg01 and add the physical volumes: vgcreate myvg01 /dev/sdb /dev/sdc Check the group:
vgs myvg01
vgdisplay myvg014. Create logical volumes
Parameter explanation: -n: logical volume name -L: size in absolute units (e.g., 5G) -l: size in extents or percentage (e.g., 100 extents or 50%FREE)
Examples:
lvcreate -n mylv01 -L 5G myvg01 lvcreate -n mylv02 -l 100 myvg01 lvcreate -n mylv03 -l 50%FREE myvg01View logical volumes:
lvs /dev/myvg01/mylv01
lvs /dev/myvg01/mylv02
lvs /dev/myvg01/mylv035. Format logical volumes
Format mylv01 with XFS:
mkfs.xfs /dev/myvg01/mylv016. Mount and use
mkdir /funlyp-lv01
mount /dev/myvg01/mylv01 /funlyp-lv01
df -Th | grep funlyp
touch /funlyp-lv01/lvm_practice.log7. Dynamic expansion
Task: The partition is too small, how to expand?
Steps:
Identify the mounted logical volume (e.g., /dev/mapper/myvg01-mylv01).
Check free space in the volume group with vgs myvg01.
If free space exists, extend the logical volume and grow the filesystem.
Example – add 5 GiB:
lvextend -L +5G /dev/myvg01/mylv01
xfs_growfs /dev/myvg01/mylv01Further expansion to 20 GiB after adding a new disk sde:
pvcreate /dev/sde
vgextend myvg01 /dev/sde
lvextend -L +10G /dev/myvg01/mylv01
xfs_growfs /dev/myvg01/mylv018. Delete LVM components
When you need to delete a logical volume, how to operate?
Procedure:
Unmount the filesystem.
Remove logical volumes.
Remove the volume group.
Remove physical volumes.
umount /funlyp-lv01
lvremove /dev/myvg01/mylv01
vgremove myvg01
pvremove /dev/sdb /dev/sdc /dev/sdeSigned-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.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
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.
