• Post author:Bhaskar Soni
  • Post published:
  • Post category:Linux
  • Post comments:1 Comment
  • Reading time:3 mins read

Logical Volume Manager (LVM) adds a flexible layer between physical disks and file systems on Linux. Instead of fixed partitions, you create logical volumes that you can resize, move and snapshot, often without downtime. This guide explains how LVM works and how to create an LVM partition step by step.

LVM partition

The building blocks

ComponentMeaningExample
Physical volume (PV)A disk or partition prepared for LVM/dev/sdb
Volume group (VG)A pool built from one or more PVsvg_data
Logical volume (LV)A “virtual partition” carved from the VG/dev/vg_data/lv_app
Physical extent (PE)The small, fixed-size unit LVM allocates (4 MiB by default)—

Think of the VG as a storage pool and LVs as flexible slices of it.

Benefits of LVM

  • Resize volumes online, often without unmounting.
  • Combine several disks into one large volume.
  • Take snapshots for backups or testing.
  • Move data between disks while the system runs (pvmove).
  • Add capacity by adding disks to the volume group.

Step-by-step: create an LVM partition

In this example, a new empty disk /dev/sdb becomes a 20 GB volume for application data. Warning: double-check the disk name with lsblk, because these commands erase data.

1. Identify the disk

lsblk

2. Create a physical volume

sudo pvcreate /dev/sdb
sudo pvs

You can use the whole disk, as here, or a partition with the Linux LVM type.

3. Create a volume group

sudo vgcreate vg_data /dev/sdb
sudo vgs

4. Create a logical volume

sudo lvcreate -L 20G -n lv_app vg_data
sudo lvs

Use -l 100%FREE instead of -L 20G to use all free space.

5. Create a file system

sudo mkfs.xfs /dev/vg_data/lv_app
# or: sudo mkfs.ext4 /dev/vg_data/lv_app

6. Mount it

sudo mkdir -p /data
sudo mount /dev/vg_data/lv_app /data
df -h /data

7. Mount it at boot

Add a line to /etc/fstab:

/dev/vg_data/lv_app  /data  xfs  defaults  0 0

Then test with sudo mount -a before rebooting, because a wrong entry can stop the system from booting.

Extending a logical volume

When space runs low, extend the LV and file system in one command:

sudo lvextend -r -L +10G /dev/vg_data/lv_app

The -r option resizes the file system too. If the volume group has no free space, first add a new disk with pvcreate and vgextend vg_data /dev/sdc.

Note that XFS can grow but cannot shrink. Ext4 can shrink, but only while unmounted, so plan carefully.

Snapshots

A snapshot captures a volume’s state at one moment:

sudo lvcreate -s -L 5G -n lv_app_snap /dev/vg_data/lv_app

Snapshots are useful before upgrades or for consistent backups. However, they are not backups by themselves, and they slow writes while they exist, so remove them when done.

Useful commands

TaskCommand
Show PVs, VGs, LVspvs, vgs, lvs
Detailed infopvdisplay, vgdisplay, lvdisplay
Remove an LVlvremove /dev/vg_data/lv_app

Related guides

Sources

Running Linux servers in production? Our Linux server hardening & security audit checks configuration, patching, SSH and logging. You can also use our free Linux server hardening checklist, or contact us.

Post author avatar

Bhaskar Soni

Bhaskar Soni is a Security Engineer and the founder of Youngster Company, based in Ahmedabad, Gujarat. He works hands-on with Linux server hardening, vulnerability assessment and penetration testing (VAPT), ISO 27001 compliance and OSINT investigations. He writes practical, tested guides for IT professionals and Indian businesses, and every article on this site is written or reviewed by him.

This Post Has One Comment

Leave a Reply