Linucate
~ Linucate_

204.3 Logical Volume Manager

All Levels

Introduction

LVM separates physical storage from the logical devices used by filesystems. Its flexibility is valuable, but every resize crosses two layers: the logical volume and the filesystem above it.

What you should be able to do after this lesson:

  • Explain physical volumes, volume groups, and logical volumes.
  • Build and inspect an LVM stack.
  • Extend and reduce storage in the correct order.
  • Create and monitor snapshots.
  • Rename, activate, deactivate, and remove LVM objects safely.

Big Idea: Capacity Moves Through Several Layers

LVM allocates extents; it does not automatically understand the data structure inside every filesystem. A resize request must follow the direction of risk:

  • Grow: enlarge the lower block layer first, then the filesystem.
  • Shrink: shrink a supported filesystem first, then reduce the lower block layer.

Confusing the order during reduction can cut allocated filesystem blocks off the end of the logical volume.

The LVM Stack

disk or partition -> physical volume (PV) -> volume group (VG) -> logical volume (LV) -> filesystem

Inspect each layer:

pvs
vgs
lvs -a -o +devices

Device-mapper paths appear below /dev/mapper/; convenient links also appear as /dev/<vg>/<lv>.

Create Storage

sudo pvcreate /dev/sdb1 /dev/sdc1
sudo vgcreate vg_data /dev/sdb1 /dev/sdc1
sudo lvcreate -L 20G -n lv_projects vg_data
sudo mkfs.ext4 /dev/vg_data/lv_projects

Use vgextend to add another PV to an existing VG.

Extend a Volume

Extending is normally low risk when free extents exist:

sudo lvextend -L +5G /dev/vg_data/lv_projects
sudo resize2fs /dev/vg_data/lv_projects

For XFS, grow the mounted filesystem using its mount point:

sudo xfs_growfs /srv/projects

Some lvextend versions support -r to call an appropriate filesystem resize helper.

Reduce a Volume

Reduction is dangerous. The filesystem must be reduced before the LV, and only filesystems that support shrinking can be used.

Typical ext workflow:

  1. Back up the data.
  2. Unmount the filesystem.
  3. Check it with e2fsck.
  4. Shrink it with resize2fs.
  5. Reduce the LV with lvreduce.
  6. Check and mount it again.

XFS cannot be shrunk in place; create a smaller filesystem and migrate data instead.

Snapshots

sudo lvcreate -L 5G -s -n projects_snap /dev/vg_data/lv_projects
lvs -a

A classic LVM snapshot tracks changed blocks. If its allocated space fills, it becomes invalid. A snapshot is useful for obtaining a consistent backup point, but keeping it on the same storage does not make it a backup.

Rename and Activation

lvrename vg_data lv_projects lv_archive
vgchange -ay vg_data
vgchange -an vg_data

Update /etc/fstab, service configuration, and scripts after renaming a path.

Remove Objects

Remove from the top down:

sudo umount /srv/projects
sudo lvremove /dev/vg_data/lv_projects
sudo vgremove vg_data
sudo pvremove /dev/sdb1

Confirm that no needed extents remain on a PV before using vgreduce or pvremove. pvmove can relocate allocated extents first.

Guided Practice: Read an LVM Layout

On a system with LVM, start with read-only reports:

pvs -o pv_name,vg_name,pv_size,pv_free
vgs -o vg_name,vg_size,vg_free,pv_count,lv_count
lvs -a -o lv_name,vg_name,lv_size,lv_attr,origin,data_percent,devices
lsblk -f

For one logical volume, draw the complete path from each physical device to the mount point. Calculate how much free space exists in the volume group and how much free space exists inside the filesystem. These are different values.

If disposable virtual disks are available, create a small PV, VG, and LV, then extend it. Verify the LV size before growing the filesystem and verify the mounted capacity afterward. Remove the lab stack from the top down.

Troubleshooting Scenario

An administrator extends an LV by 10 GiB, but df -h still shows the old size. lvs shows the new size correctly.

The block layer grew but the filesystem did not. Identify the filesystem type, then use its supported grow command: resize2fs for ext or xfs_growfs against the XFS mount point. Repeating lvextend would allocate more storage without fixing the missing filesystem step.

Exam Focus

  • Know the PV -> VG -> LV hierarchy and /dev/mapper paths.
  • Distinguish free extents in a VG from free blocks in a filesystem.
  • Know create, extend, reduce, rename, activate, deactivate, move, and remove operations.
  • Classic snapshots consume space as the origin changes and become invalid if their allocation fills.

Recap

  • LVM consists of PVs, VGs, and LVs.
  • Extend the LV before growing the filesystem; shrink the filesystem before reducing the LV.
  • Snapshot capacity must be monitored.
  • Backups and verified device identities remain necessary despite LVM flexibility.
🎯

Test Your Knowledge

Complete the quiz to assess your understanding of this course's concepts.