Skip to main content
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.

Prerequisites

Before you begin, ensure that the LVM2 package is installed on your system. Use the command below to install LVM2:

Step 1: Create a Physical Volume

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:
Expected output:

Step 2: Create a Volume Group

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:
Expected output:
To display details about the physical volume, run:
Sample output:
For further information about the volume group, use:
Sample output:

Step 3: Create a Logical Volume

After establishing the volume group, create a logical volume (LV). In this example, we create a 1GB LV named vol1 within the caleston_vg volume group:
Expected output:
To verify that the LV was created successfully, list all logical volumes:
Sample output:

Step 4: Create and Mount a Filesystem

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:
After the filesystem is created, mount it to a directory (e.g., /mnt/vol1) to make it accessible:

Step 5: Resize the Logical Volume and Filesystem

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:
Sample output:
If there is enough free space, extend the logical volume by an additional 1GB:
Expected output:
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:
The output will indicate that the filesystem has been resized. Finally, verify the new filesystem size:
Sample output:

Access Paths for the Logical Volume

It’s important to note that the logical volume can be accessed through two different paths:
  • /dev/caleston_vg/vol1
  • /dev/mapper/caleston_vg-vol1
Both paths refer to the same logical volume, so you can use either interchangeably in your commands and configurations.

Conclusion

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:

Watch Video

Practice Lab