What is LVM and Why Use It?

LVM (Logical Volume Manager) is an abstraction layer between physical disks and filesystems in Linux. Instead of creating partitions directly on a disk (which is rigid and hard to change), LVM allows dynamic management of disk space – growing, shrinking, and moving volumes without downtime.

Key advantages of LVM:

  • Resize volumes on the fly, without unmounting
  • Combine multiple physical disks into a single logical space
  • Create snapshots – point-in-time copies of volumes
  • Thin provisioning – allocate space on demand
  • Simple data migration between disks

LVM is the standard on production servers and the default configuration in many distributions (Fedora, RHEL, CentOS, Ubuntu Server).


Key Concepts

LVM is built on three layers:

PV (Physical Volume) – a physical volume. This is a disk or partition that has been initialized for use with LVM. It can be a whole disk (/dev/sdb) or a single partition (/dev/sdb1).

VG (Volume Group) – a volume group. A pool of disk space composed of one or more PVs. This is where we carve out logical volumes. Think of it as a virtual disk.

LV (Logical Volume) – a logical volume. The equivalent of a traditional partition, but flexible. This is where we create a filesystem and mount it in the system.

The flow looks like this:

Physical disks -> PV -> VG -> LV -> Filesystem
/dev/sdb              vg_data   lv_home    ext4
/dev/sdc                        lv_var     xfs

Installation

Most distributions come with LVM tools pre-installed. If not, you can install them:

# Debian/Ubuntu
sudo apt-get install lvm2

# Fedora/RHEL/CentOS
sudo dnf install lvm2

# Arch Linux
sudo pacman -S lvm2

Check that LVM services are running:

sudo systemctl status lvm2-lvmetad.service

Creating PV, VG, and LV – Practical Example

Let’s assume we have two disks: /dev/sdb (50 GB) and /dev/sdc (50 GB), and we want to combine them into a single LVM space.

Step 1: Create Physical Volumes

# Initialize disks as PVs
sudo pvcreate /dev/sdb /dev/sdc

# Check created PVs
sudo pvs

Example output:

  PV         VG      Fmt  Attr PSize  PFree
  /dev/sdb           lvm2 ---  50.00g 50.00g
  /dev/sdc           lvm2 ---  50.00g 50.00g

Step 2: Create a Volume Group

# Create a volume group from both disks
sudo vgcreate vg_data /dev/sdb /dev/sdc

# Check the group
sudo vgs

Example output:

  VG      #PV #LV #SN Attr   VSize  VFree
  vg_data   2   0   0 wz--n- 99.99g 99.99g

We now have a single 100 GB pool from two disks.

Step 3: Create Logical Volumes

# Create a 60 GB LV for /home
sudo lvcreate -L 60G -n lv_home vg_data

# Create a 30 GB LV for /var
sudo lvcreate -L 30G -n lv_var vg_data

# Or use a percentage of free space
# sudo lvcreate -l 100%FREE -n lv_backup vg_data

# Check created LVs
sudo lvs

Example output:

  LV      VG      Attr       LSize  Pool Origin Data%  Meta%
  lv_home vg_data -wi-a----- 60.00g
  lv_var  vg_data -wi-a----- 30.00g

Step 4: Create Filesystems and Mount

# Create ext4 filesystem
sudo mkfs.ext4 /dev/vg_data/lv_home
sudo mkfs.xfs /dev/vg_data/lv_var

# Mount the volumes
sudo mount /dev/vg_data/lv_home /home
sudo mount /dev/vg_data/lv_var /var

To make the mounts persistent, add entries to /etc/fstab:

/dev/vg_data/lv_home  /home  ext4  defaults  0 2
/dev/vg_data/lv_var   /var   xfs   defaults  0 2

Extending and Resizing Volumes

This is the main advantage of LVM over traditional partitions. Resizing a volume is straightforward and in many cases does not require unmounting.

Growing an LV

# Add 10 GB to lv_home
sudo lvextend -L +10G /dev/vg_data/lv_home

# Extend the filesystem (ext4)
sudo resize2fs /dev/vg_data/lv_home

# For XFS use xfs_growfs
# sudo xfs_growfs /var

# You can do both in one command with the -r flag
sudo lvextend -L +10G -r /dev/vg_data/lv_home

The -r (--resizefs) flag automatically extends the filesystem after growing the LV.

Adding a New Disk to an Existing VG

# New disk /dev/sdd
sudo pvcreate /dev/sdd
sudo vgextend vg_data /dev/sdd

# Now we have more free space in the VG
sudo vgs

Shrinking an LV

Shrinking requires more caution. The filesystem must be shrunk first, then the LV. XFS does not support shrinking.

# Unmount the volume
sudo umount /home

# Check the filesystem
sudo e2fsck -f /dev/vg_data/lv_home

# Shrink the filesystem to 40 GB
sudo resize2fs /dev/vg_data/lv_home 40G

# Shrink the LV to 40 GB
sudo lvreduce -L 40G /dev/vg_data/lv_home

# Remount
sudo mount /dev/vg_data/lv_home /home

Warning: Shrinking a volume carries a risk of data loss. Always create a backup before this operation.


Snapshots

LVM snapshots are point-in-time copies of a volume’s state. They use a copy-on-write mechanism – initially the snapshot takes no additional space. Space is consumed only when data on the original volume changes.

Creating a Snapshot

# Create a snapshot named snap_home with 5 GB for changes
sudo lvcreate -L 5G -s -n snap_home /dev/vg_data/lv_home

# Check the snapshot
sudo lvs

Example output:

  LV        VG      Attr       LSize  Pool Origin  Data%
  lv_home   vg_data owi-aos--- 60.00g
  snap_home vg_data swi-a-s---  5.00g      lv_home 0.00

Mounting a Snapshot

# Mount the snapshot as read-only
sudo mount -o ro /dev/vg_data/snap_home /mnt/snapshot

Restoring from a Snapshot

# Unmount the original volume
sudo umount /home

# Restore data from the snapshot
sudo lvconvert --merge /dev/vg_data/snap_home

# After merge, the snapshot is automatically removed
# Remount the volume
sudo mount /dev/vg_data/lv_home /home

Removing a Snapshot

sudo lvremove /dev/vg_data/snap_home

Warning: LVM snapshots are not a substitute for backups. When a snapshot fills its allocated space (5 GB in our example), it becomes invalid. Monitor usage with lvs.


Thin Provisioning

Thin provisioning allows creating logical volumes that are larger than the available physical space. Disk space is allocated only when data is actually written. This technique is commonly used in virtualization and cloud environments.

# Create an 80 GB thin pool
sudo lvcreate -L 80G --thinpool thin_pool vg_data

# Create a thin LV with 200 GB virtual size
sudo lvcreate -V 200G --thin -n lv_thin1 vg_data/thin_pool

# Another thin LV
sudo lvcreate -V 200G --thin -n lv_thin2 vg_data/thin_pool

# Check usage
sudo lvs -a

Both volumes “see” 200 GB, but they actually consume only as much space as data written to them. When the thin pool fills up, it must be extended or data will be lost – that is why monitoring is critical.

# Check thin pool usage
sudo lvs -o+data_percent,metadata_percent vg_data/thin_pool

LVM vs Traditional Partitions

  • Traditional partitions have a fixed size set at creation time – LVM allows resizing at any time
  • Traditional partitions cannot combine multiple disks into one space – LVM merges multiple PVs into a single VG
  • Traditional partitions do not support snapshots – LVM has built-in snapshots
  • Traditional partitions are simpler to configure – LVM requires learning additional tools
  • Traditional partitions have no thin provisioning – LVM allows overprovisioning
  • Moving data between disks requires manual copying with traditional partitions – LVM supports pvmove for live migration
  • Traditional partitions do not require an additional abstraction layer – LVM adds complexity that can make data recovery harder in case of failure
  • Traditional partitions are a better choice for simple desktops – LVM is the standard on servers

Cheat Sheet – Most Used Commands

Physical Volumes

sudo pvcreate /dev/sdX          # Create PV
sudo pvs                        # List PVs (short)
sudo pvdisplay                  # List PVs (detailed)
sudo pvremove /dev/sdX          # Remove PV
sudo pvmove /dev/sdb /dev/sdd   # Move data between PVs

Volume Groups

sudo vgcreate vg_name /dev/sdX  # Create VG
sudo vgs                        # List VGs (short)
sudo vgdisplay                  # List VGs (detailed)
sudo vgextend vg_name /dev/sdY  # Add PV to VG
sudo vgreduce vg_name /dev/sdX  # Remove PV from VG
sudo vgremove vg_name           # Remove VG

Logical Volumes

sudo lvcreate -L 50G -n lv_name vg_name   # Create LV
sudo lvs                                   # List LVs (short)
sudo lvdisplay                             # List LVs (detailed)
sudo lvextend -L +10G -r /dev/vg/lv       # Extend LV + filesystem
sudo lvreduce -L 30G /dev/vg/lv           # Shrink LV
sudo lvremove /dev/vg/lv                   # Remove LV
sudo lvrename vg_name old_name new_name    # Rename LV

Snapshots

sudo lvcreate -L 5G -s -n snap /dev/vg/lv  # Create snapshot
sudo lvconvert --merge /dev/vg/snap         # Restore from snapshot

Diagnostics

sudo lvm version      # LVM version
sudo dmsetup ls        # List device-mapper devices
sudo dmsetup status    # Device-mapper status
sudo vgck vg_name      # Check VG consistency

Troubleshooting Tips

LV Not Visible After Reboot

# Activate all VGs
sudo vgchange -ay

# Check if LVM sees the disks
sudo pvscan
sudo vgscan
sudo lvscan

Disk Disappeared from VG

# Check which PVs are unavailable
sudo pvs -a

# If the disk is physically damaged, remove it from the VG
sudo vgreduce --removemissing vg_data

Snapshot Filling Up Too Fast

# Check snapshot usage
sudo lvs -o+snap_percent

# Extend the snapshot
sudo lvextend -L +5G /dev/vg_data/snap_home

Cannot Extend LV – No Free Space in VG

# Check free space
sudo vgs

# Add a new disk
sudo pvcreate /dev/sde
sudo vgextend vg_data /dev/sde

# Now extend the LV
sudo lvextend -L +20G -r /dev/vg_data/lv_home

Reading LVM Configuration from a Rescue Disk

# Scan for available volumes
sudo vgscan
sudo lvscan

# Activate volumes
sudo vgchange -ay

# Mount
sudo mount /dev/vg_data/lv_home /mnt

Summary

LVM is one of the most important tools for managing disk space on Linux. The flexibility, snapshots, and ability to combine multiple disks into a single pool make it the standard on production servers. The initial learning curve is small, and the benefits are enormous. If you manage a system with more than one disk or need flexibility in allocating space, LVM is the natural choice.