This article provides an overview of Logical Volume Manager (LVM) and guides users through its setup and management.
In this lesson, we explore the Logical Volume Manager (LVM), a powerful tool that enables you to group multiple physical volumes (disks or partitions) into a single volume group (VG). From the volume group, you can then allocate one or more logical volumes (LVs). While our example uses three partitions, LVM is flexible enough to work with a single disk, multiple disks, or even an unlimited number of partitions grouped under a single VG.
One of LVM’s most significant advantages is its ability to resize logical volumes dynamically, provided there is sufficient free space in the volume group. This feature is especially useful for systems with changing storage requirements.
The initial step in configuring LVM is to identify available disks or partitions and create physical volumes (PVs) from them. A physical volume represents the disk or partition in LVM.For example, to create a physical volume on the device path /dev/sdb, execute:
Once the physical volume is established, create a volume group (VG) that will host your logical volumes. In this example, the VG is named caleston_vg and includes /dev/sdb:
Copy
Ask AI
vgcreate caleston_vg /dev/sdb
Expected output:
Copy
Ask AI
Volume group "caleston_vg" successfully created
To display details about the physical volume, run:
Copy
Ask AI
pvdisplay
Sample output:
Copy
Ask AI
--- Physical volume ---PV Name /dev/sdbVG Name caleston_vgPV Size 20.00 GiB / not usable 3.00 MiBAllocatable yesPE Size 4.00 MiBTotal PE 5119Free PE 5119Allocated PE 0PV UUID iDCXIN-En2h-5IlJ-Yjqv-GcsR-gDfV-zaf66E
For further information about the volume group, use:
Copy
Ask AI
vgdisplay
Sample output:
Copy
Ask AI
--- Volume group ---VG Name caleston_vgSystem ID LVM2-XXXXXXFormat lvm2Metadata Areas 1Metadata Sequence No 1VG Access read/writeVG Status resizableMAX LV 0Cur LV 0Open LV 0Max PV 0Cur PV 1Act PV 1VG Size 20.00 GiBPE Size 4.00 MiBTotal PE 5119Alloc PE / Size 0 / 0Free PE / Size 5119 / 20.00 GiBVG UUID VzmIAn-9cEl5bA-lVtm-wHKX-KQaObR
With your logical volume in place, the next step is to create a filesystem on it. In this example, we create an ext4 filesystem on /dev/caleston_vg/vol1:
Copy
Ask AI
mkfs.ext4 /dev/caleston_vg/vol1
After the filesystem is created, mount it to a directory (e.g., /mnt/vol1) to make it accessible:
Sometimes you may need to expand the logical volume while it remains mounted. Begin by verifying that there is sufficient free space in the volume group:
If there is enough free space, extend the logical volume by an additional 1GB:
Copy
Ask AI
lvresize -L +1G /dev/caleston_vg/vol1
Expected output:
Copy
Ask AI
Logical volume vol1 successfully resized.
At this stage, even after resizing the logical volume, the filesystem will still report its original size (1GB) when using the df command because only the LV has been extended. It is essential to also resize the filesystem with the resize2fs command.
Resize the filesystem using:
Copy
Ask AI
resize2fs /dev/caleston_vg/vol1
The output will indicate that the filesystem has been resized. Finally, verify the new filesystem size:
This lesson has walked you through the fundamental steps of setting up and managing LVM—from creating physical volumes and volume groups to creating, mounting, and resizing logical volumes and filesystems. Regular practice of these operations will help solidify your understanding of LVM’s flexibility and scalability.For further reading and advanced concepts, consider exploring additional resources: