Linux Administration: Logical Volume Manager (LVM)
Logical Volume Manager (LVM) allows you to group multiple physical volumes into a single volume group, enabling you to allocate and resize logical volumes flexibly. In this guide, we will look at how to manage LVM in Linux step-by-step.
Creating an LVM Partition
Before running LVM commands, create an LVM partition using fdisk. As shown below, set the partition type code to 8e (Linux LVM).
Creating and Deleting Physical Volumes (PV)
A Physical Volume (PV) is a partition initialized for use in LVM.
Let’s create a physical volume using the previously generated partition with pvcreate /dev/sdb1. You can verify the created physical volume using pvdisplay. Conversely, if you want to remove a physical volume, run pvremove /dev/sdb1.
Creating a Volume Group (VG)
Next, let’s create a Volume Group (VG), which pools multiple physical volumes into a single storage group.
Executing vgcreate vg_new /dev/sdb1 creates a new volume group named vg_new and adds physical volume /dev/sdb1 to it. You can verify the volume group configuration using vgdisplay.
Creating and Deleting Logical Volumes (LV)
Now, let’s create and delete a Logical Volume (LV) — the actual usable storage space — from the volume group.
Get Hyunjae’s stories in your inbox
Join Medium for free to get updates from this writer.
Running lvcreate -L 1G -n lv_new vg_new allocates a 1GB logical volume named lv_new from vg_new. You can check the new logical volume using lvdisplay. To delete the logical volume, run lvremove /dev/vg_new/lv_new.
Creating a File System and Persistent Mounting
Create an ext4 file system on the logical volume by executing mkfs.ext4 /dev/vg_new/lv_new. Next, create a mount point directory using mkdir /data and mount the logical volume with mount /dev/vg_new/lv_new /data. Running df -h will confirm that the file system is successfully mounted.
To ensure persistent mounting upon boot, add the entry to /etc/fstab and restart the system. Verify with df -h after rebooting to confirm that it remains mounted as expected.
Extending Logical Volumes
Finally, let’s cover how to extend a logical volume. Since file system resizing procedures differ between ext4 and xfs, we will look at both methods.
Extending an ext4 File System
First, extend the logical volume by 1GB using lvextend -L +1G /dev/vg_new/lv_new. Then, expand the ext4 file system size using resize2fs /dev/vg_new/lv_new. Running df -h will show that the file system size has increased to 2GB.
Extending an xfs File System
Now, let’s look at extending an xfs file system. First, create a new logical volume named lv_xfs using lvcreate -L 1G -n lv_xfs vg_new. Format it with mkfs.xfs /dev/vg_new/lv_xfs and mount it to /data2 using mount /dev/vg_new/lv_xfs /data2.
Next, allocate all remaining free space in the volume group to lv_xfs using lvextend -l +100%FREE /dev/vg_new/lv_xfs. Then, expand the file system using xfs_growfs /data2. Checking with df -h will confirm that the remaining 2GB of storage has been successfully added to the lv_xfs volume.





