Skip to main content
RunBook Academy

LinuxXVI · LVMLVM operations

LVM creation, extension, and snapshots

Intermediate⏱ ~12 minbashpvcreatevgcreatelvcreatelvextendresize2fsxfs_growfsmount

What you'll learn

  • Create PV, VG, and LV from a fresh disk
  • Extend an LV and resize the filesystem online
  • Take and remove an LVM snapshot
  • Troubleshoot LVM problems

Prerequisites

Verified against Ubuntu 24.04 LTS · Debian 12 (Bookworm) · RHEL 9.x · Rocky Linux 9.x · AlmaLinux 9.x · Linux kernel 6.1 LTS / 6.6 LTS · systemd 255+ · OpenSSH 8.7p1 (RHEL 9) / 9.6p1 (Ubuntu 24.04) · nftables 1.0.x · chrony 4.x · Pacemaker 2.1.x · Corosync 3.1.x · 2026-08-09

Not yet marked complete on this device.

LVM operations are routine on production hosts. Knowing the right commands and order of operations prevents data loss and unnecessary downtime.

Creating an LVM stack

  1. Initialize a disk as a Physical Volume (PV): pvcreate /dev/sdXN
  2. Combine one or more PVs into a Volume Group (VG): vgcreate vg_data /dev/sdXN
  3. Allocate a Logical Volume (LV): lvcreate -L 100G -n data vg_data
  4. Create a filesystem on the LV: mkfs.ext4 /dev/vg_data/data
  5. Mount the LV: mkdir /data; mount /dev/vg_data/data /data
  6. Add to fstab: UUID=... /data ext4 defaults,nofail 0 2
  7. Verify: df -h /data; lvs
Data-loss riskcreate LV stack
$ pvcreate /dev/sdc1; vgcreate vg_data /dev/sdc1; lvcreate -L 100G -n data vg_data; mkfs.ext4 /dev/vg_data/data
Physical volume '/dev/sdc1' successfully created.
Volume group 'vg_data' successfully created
Logical volume 'data' successfully created
mke2fs 1.47.0 (5-Feb-2023)
Filesystem UUID: 1a2b-3c4d-...

Extending an LV

Configuration changeextend LV
$ lvextend -L +50G /dev/vg_data/data; resize2fs /dev/vg_data/data
Size of logical volume vg_data/data changed from 100.00g to 150.00g
resize2fs 1.47.0 (5-Feb-2023)
Resizing the filesystem on /dev/vg_data/data to 39321600 (4k) blocks.

LVM snapshots

Configuration changeLVM snapshot
$ lvcreate -L 5G -s -n data-snap /dev/vg_data/data
Logical volume 'data-snap' successfully created
Configuration changeuse and remove snapshot
$ mount -o ro,nouuid /dev/vg_data/data-snap /mnt/snap; ls /mnt/snap; umount /mnt/snap; lvremove /dev/vg_data/data-snap
Snapshots dir
file1
file2
Do you really want to remove active logical volume data-snap? [y/n]: y
Logical volume 'data-snap' successfully removed

Monitoring LVM

Read-only / Safemonitoring
$ pvs -o+pv_size,pv_free,pv_used; vgs -o+vg_size,vg_free,vg_used; lvs -o+lv_size,lv_used
  PV         VG   Fmt  Attr PSize   PFree   Used
/dev/sda2  vg0  lvm2 a--   99.00g   4.00g   95.00g
/dev/sdb1  vg0  lvm2 a--  500.00g 205.00g  295.00g
--- VG   #PV #LV #SN Attr   VSize   VFree
vg0    2   3   0 wz--n- 599.00g 209.00g
--- LV   VG  Attr       LSize   Used
root vg0 -wi-ao----   5.00g
var  vg0 -wi-ao----  90.00g
data vg0 -wi-ao---- 295.00g

Knowledge check

Knowledge check · 3 questions

  1. Q1. What is the correct order to extend a logical volume and its filesystem?

  2. Q2. LVM snapshots are instant and use little space until the original LV changes.

  3. Q3. Which of the following are correct LVM operations? Select all that apply.

Passing score: 75%. Answers are checked in this browser.