Skip to main content
Welcome to our comprehensive guide on managing and configuring LVM (Logical Volume Manager) storage in Linux. LVM is a powerful tool that provides storage flexibility by allowing you to combine free space from different parts of a disk—or even from multiple disks—into a single continuous partition as seen by the operating system. With LVM, you can easily resize storage partitions, making it convenient to expand capacity as your needs grow. In this guide, you will explore various LVM operations, including creating physical volumes, volume groups, and logical volumes, as well as resizing and formatting them. Most CentOS installations come with LVM tools pre-installed. If your system does not have them, install the package with:
For demonstration purposes, assume that three new virtual disks, each with 5 gigabytes of capacity, have been added to your virtual machine.

Key LVM Concepts

Before diving into the commands, it is essential to understand the core LVM terminology:
  • PV (Physical Volume): A real storage device such as an entire disk or a partition.
  • VG (Volume Group): A collection (or pool) of physical volumes that creates a single virtual disk.
  • LV (Logical Volume): A partition created within a volume group.
  • PE (Physical Extent): The basic unit into which a physical volume is subdivided.

Viewing Available Physical Volumes

A Physical Volume (PV) represents a real storage device. To display all available PVs and check which ones are used by LVM, execute:
You might see output similar to:
In this output, /dev/sda2 is already configured as an LVM physical volume (likely set up during the CentOS installation), so it will be excluded from further operations in this lesson.

Creating Physical Volumes

To incorporate new storage, designate two of the new disks (for example, /dev/sdc and /dev/sdd) as physical volumes:
A successful output will look like:
Verify the current physical volumes with:
Expected output:
The PFree column shows the free storage available on each physical volume.

Creating a Volume Group

To utilize the available storage, create a Volume Group (VG) that aggregates the physical volumes into one virtual disk. For example, combining /dev/sdc and /dev/sdd creates a VG of 10 gigabytes. Create the volume group named “my_volume” with:
Output confirmation:

Extending a Volume Group

If you require additional storage, you can extend the volume group. First, create a physical volume on a new disk (e.g., /dev/sde):
Next, extend your volume group with:
Then verify the updated volume group details using:
A sample output might be:
If a physical volume is no longer needed, you can remove it from the volume group using vgreduce and then wipe its LVM signature with pvremove.

Creating Logical Volumes

Once the physical volumes and volume group are ready, create Logical Volumes (LVs) to act as partitions within the VG. Create a logical volume named “partition1” with a size of 2GB in “my_volume”:
Expected output:
Check the volume groups to view logical volumes and available free space:
Sample output:
You may also create a second logical volume (e.g., “partition2”) with a size of 6GB:
Verify with:
Which might output:
And for a final check:
Example:

Resizing Logical Volumes (LVs)

Growing a Logical Volume

Data in an LV is divided into physical extents (PEs). To expand an LV to utilize all available extents in its volume group, run:
A sample output might be:

Shrinking a Logical Volume

To reduce a logical volume to a specific size (for example, 2GB), use:
This command will warn you about potential data loss. If you are sure, confirm the reduction:
Always ensure you have a backup before reducing the size of a logical volume as this operation can result in data loss.

Creating a Filesystem on a Logical Volume

An LV must be formatted with a filesystem before it becomes useful. For instance, to format “partition1” with the XFS filesystem, run:
The output will confirm the creation of the new XFS filesystem along with details such as metadata and block sizes.

Resizing an LV with an Existing Filesystem

If your logical volume includes a filesystem, you need to resize both the LV and the filesystem concurrently. XFS supports online expansion (but cannot be shrunk while mounted). To expand “partition1” from 2GB to 3GB, run:
An example output sequence:
Note that while many filesystems can expand online, they generally cannot be shrunk without unmounting.

Viewing Logical Volume Details

To display detailed information about your logical volumes, use:
This command shows details such as the LV path, name, size, status, and more. An example output for “partition1” might be:
This LV path (/dev/my_volume/partition1) works in a similar way to standard device files like /dev/vda.
The image shows a terminal window displaying information about a logical volume in a CentOS system, including details like path, name, size, and status.

Additional LVM Commands and Tips

If you ever need help or a quick refresher on any LVM command, refer to the manual pages by running:
While navigating the manual, you can use tab-completion in the terminal. For example, type “vg” and press Tab twice to see available VG options such as:
  • vgcreate
  • vgdisplay
  • vgexport
  • vgchange
  • vgck
  • vgextend
  • vgimport
  • vgmerge
  • vgimportdevices
  • vgcfgrestore
  • vgmknodes
  • vgreduce
  • vgs
  • vgsplit
This concludes our guide on managing and configuring LVM storage in Linux. Armed with these commands and tips, you are now ready to explore further lab exercises and enhance your Linux storage management skills.
The image shows a terminal window displaying a list of Linux Logical Volume Manager (LVM) commands and related utilities. The text is part of a manual page, as indicated by the footer.

Watch Video