Pay-As-You-Go VPS – Only pay for what you use, with flexible billing and no long-term commitment

Manage LVM with CLI: A Comprehensive Guide

September 4, 2025

 

In today’s storage management landscape, Logical Volume Manager (LVM) provides a flexible and efficient way to manage disk space on Linux systems. Utilizing the command-line interface (CLI) offers system administrators the ability to perform a variety of tasks, from creating logical volumes to resizing existing ones, all with precision and control. This article explores the essential commands necessary to manage LVM effectively using the CLI.

Understanding LVM Basics

Before diving into the command-line operations, it’s crucial to understand the core components of LVM:

  1. Physical Volumes (PVs): These are the physical disks or partitions that the LVM uses for storage.
  2. Volume Groups (VGs): A collection of physical volumes that acts as a single storage unit.
  3. Logical Volumes (LVs): These are the actual “partitions” created from the volume groups, which can be formatted with a filesystem.

Setting Up LVM

To get started with LVM, you must first install the necessary packages if they aren’t already included in your distribution. On most Linux distributions, you can do this using package managers like apt or yum.

Creating a Physical Volume

To create a Physical Volume, use the following command:

sudo pvcreate /dev/sdx

Replace /dev/sdx with the appropriate physical device.

Creating a Volume Group

After creating physical volumes, you can group them into a Volume Group:

sudo vgcreate my_volume_group /dev/sdx

Creating Logical Volumes

Once your Volume Group is set up, you can create Logical Volumes. This enables you to allocate storage within the group dynamically:

sudo lvcreate -n my_logical_volume -L 10G my_volume_group

This command creates a Logical Volume named my_logical_volume of size 10 GB.

Formatting and Mounting Logical Volumes

After creating a Logical Volume, you need to format it and then mount it for use:

sudo mkfs.ext4 /dev/my_volume_group/my_logical_volume

To mount, first create a directory:

sudo mkdir /mnt/my_mount_point
sudo mount /dev/my_volume_group/my_logical_volume /mnt/my_mount_point

Resizing Logical Volumes

One of the most powerful features of LVM is the ability to resize logical volumes. To extend a Logical Volume, use:

sudo lvextend -L +5G /dev/my_volume_group/my_logical_volume

After extending the Logical Volume, remember to resize the filesystem to utilize the new space:

sudo resize2fs /dev/my_volume_group/my_logical_volume

To reduce a Logical Volume’s size, make sure to first shrink the filesystem:

sudo resize2fs /dev/my_volume_group/my_logical_volume 5G

Then you can reduce the Logical Volume itself:

sudo lvreduce -L 5G /dev/my_volume_group/my_logical_volume

Monitoring and Managing LVM Status

To monitor the status of your LVM setup, you can use the following commands:

  • View the Physical Volumes:
sudo pvdisplay
  • Check Volume Groups:
sudo vgdisplay
  • Inspect Logical Volumes:
sudo lvdisplay

Conclusion

Managing LVM using the command line empowers system administrators with the flexibility and control needed for efficient storage management. By understanding the core concepts and commands, you can effectively create, manage, and resize volumes, ensuring that your Linux systems are optimized for performance and storage efficiency. Whether you’re running a personal project or managing enterprise-level environments, mastering LVM through the CLI is a valuable skill that enhances your command over disk management.

VirtVPS