
Getty Images/iStockphoto
Manage storage using Linux Logical Volume Manager
To see how flexible your storage space can be, consider Logical Volume Manager on Linux. Flexibility is critical on servers housing huge numbers of files or other resources.
For decades, system administrators have been forced to consider storage capacity on a per-physical disk and per-partition basis. That changed when Linux began supporting Logical Volume Manager.
Previously, if you needed a 120 GB storage area, you needed a physical drive with a partition of at least 120 GB. Linux Logical Volume Manager offers administrators far more storage management flexibility.
Explore Logical Volume Manager's concepts and components, including physical and logical volumes, as well as sample commands to help you manage your storage space.
Users need root or sudo privileges on the system.
What is Logical Volume Manager?
Linux Logical Volume Manager enables storage space to span multiple partitions and drives for more flexible use. Storage drives no longer dictate the size of the logical storage area, and admins can add or remove capacity easily.
Logical Volume Manager maps devices behind the scenes, while showing users a unified storage area. Administrators can create a 90 GB storage volume from three disks with 30 GB each or whatever other division of space is available, such as one disk with 10 GB, another with 20 GB and a third with 60 GB.
Requirements
Linux Logical Volume Manager requirements include a current Linux distribution and at least one drive. However, to take advantage of Logical Volume Manager's flexibility, you need at least two drives.
If you're migrating an existing server from a standard partitioning scheme to Logical Volume Manager, back up the user data, implement the manager and then restore the content. If you're just experimenting with test VMs or computers, install Linux, and have at least two storage disks available.
Components
The Linux Logical Volume Manager structure consists of three primary components:
- Physical volumes (PVs). Storage capacity is allocated to the Logical Volume Manager device mapper. They may be physical disks, disk partitions or logical unit numbers.
- Volume groups (VGs). They consist of one or more PVs representing a total potential storage space that may span multiple storage drives. You allocate this potential space to logical volumes.
- Logical volumes (LVs). These virtual partitions are carved from a VG. Add a file system, such as ext4 or XFS, and then mount the storage space for users to access.
Users can think of the components as layers. The foundation is one or more PVs, which are allocated space on storage drives. Next are VGs, consisting of at least one PV. Storage space is carved from the VGs into LVs that users see as usable storage space.
Use the lsblk command to display the available storage drives.

Create physical volumes
You build your Linux Logical Volume Manager storage space from the physical layer up. Begin with empty space on a physical disk or partition. Back up existing data to restore when the process is complete.
You must designate the capacity as storage space the device mapper should manage. The PV commands begin with the pv string, and they are fairly logical:
- pvcreate. Initialize storage space as a PV.
- pvdisplay. List the physical attributes of a PV.
- pvs. Display PV information.
- pvscan. Scan for storage configured as PVs.
- pvremove. Remove a PV from Logical Volume Manager management.
For example, if you need to designate two physical disks as PVs for Logical Volume Manager management, type the following commands.
sudo pvcreate /dev/sdb
sudo pvcreate /dev/sdc
Check your work with the pvs and pvdisplay commands.

Back up existing data whenever you mess with partitions or disk structures. In this case, the pvcreate command wipes any data on /dev/sdb1.

Create volume groups
Now that Linux Logical Volume Manager has PVs to work with, the next step is to aggregate that space into a VG. VG commands begin with vg.
Here are a few common VG management commands:
- vgcreate. Create a VG from one or more PVs.
- vgdisplay. List VG attributes.
- vgs. Display VG information.
- vgremove. Remove a VG from Logical Volume Manger management, freeing the PVs for use elsewhere.
The vgcreate command syntax includes a name for the new VG and the PVs it contains. Use the following command to create a new VG named projects_vg from the existing /dev/sdb1 PV.
sudo vgcreate projects_vg /dev/sdb1
Display the results using the vgs and vgdisplay commands.
A single system supports multiple VGs, which is an important consideration for large file servers.

Create logical volumes
Carve one or more LVs from the aggregated space of a VG. You treat these LVs as if they were traditional partitions by adding a file system and attaching them to a mount point for user access. Like PVs and VGs, the LV management commands begin with lv.
Here are a few common command examples:
- lvcreate. Create an LV from a VG.
- lvdisplay. Display LV attributes.
- lvs. Display LV information.
- lvremove. Deallocate an LV, returning the capacity to the VG from which it was carved.
You may configure multiple LVs on a single system. Each may use space from the same or different VGs.
Type the following commands to create and display an LV from an existing VG.
sudo lvcreate --name projects --size 3G projects_vg
sudo lvdisplay
The --name option names the new LV, so make it descriptive. The --size flag sets the total capacity. There are many ways to set the size, so check the documentation.

Format and mount the storage space
For the remaining steps, manage the LVs as if they were standard partitions. To use them for storage, you must add a file system, create a mount point and mount them.
First, display the LV settings using the lvdisplay command.
sudo lvdisplay

Identify the LV Path value. You use this with the mkfs command in the next step.
Install the ext4 file system on the /dev/projects_vg/projects LV using this command.
sudo mkfs.ext4 /dev/projects_vg/projects

Create a mount point.
sudo mkdir /projects
Manually mount the LV to the /projects directory.
mount /dev/projects_vg/projects /projects
Confirm the new storage space is available by using the du -h and df -h commands.
sudo du -h /projects
sudo df -h /projects

Expanding and shrinking storage space
One of Linux Logical Volume Manager's biggest benefits is the ability to shrink or extend the storage capacity without losing data or restarting the system.
Suppose you underestimated how much storage space is needed, and now, you must add more without generating downtime. The steps are the following:
- Physically install a drive, and identify it with lsblk -- assume it is /dev/sdc in this example.
- Designate it as a PV with the pvcreate command.
- Unmount the existing LV from the mount point with the umount command.
- Add the new PV to the existing VG with the vgextend command.
- Extend the existing LV with the lvextend command.
- Expand the ext4 file system with the resize2fs command.
- Remount the LV to the mount point with the mount command.
- Confirm the process worked with the df -h and lvdisplay commands.
The Logical Volume Manager commands to expand storage using 100% of the new PV's size look like this.
sudo pvcreate /dev/sdc1
sudo vgextend /dev/projects_vg /dev/sdc
sudo lvextend -l +100%FREE /dev/projects_vg/projects
sudo resize2fs /dev/projects_vg/projects
Best of all, none of these steps require a system reboot, other than possibly physically installing the new storage disk. The XFS file system has similar capabilities using the xfsgrow command.
If you allocated more storage space to an LV than it needs, you can decide how much space to remove, shrink the file system and reduce the LV. First, use the resize2fs command to reduce the file system, and then shrink the LV using the lvreduce command.
Damon Garn owns Cogspinner Coaction and provides freelance IT writing and editing services. He has written multiple CompTIA study guides, including the Linux+, Cloud Essentials+ and Server+ guides, and contributes extensively to Informa TechTarget, The New Stack and CompTIA Blogs.