LVM creation, extension, and snapshots
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
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
- Initialize a disk as a Physical Volume (PV): pvcreate /dev/sdXN
- Combine one or more PVs into a Volume Group (VG): vgcreate vg_data /dev/sdXN
- Allocate a Logical Volume (LV): lvcreate -L 100G -n data vg_data
- Create a filesystem on the LV: mkfs.ext4 /dev/vg_data/data
- Mount the LV: mkdir /data; mount /dev/vg_data/data /data
- Add to fstab: UUID=... /data ext4 defaults,nofail 0 2
- Verify: df -h /data; lvs
$ pvcreate /dev/sdc1; vgcreate vg_data /dev/sdc1; lvcreate -L 100G -n data vg_data; mkfs.ext4 /dev/vg_data/dataPhysical 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
$ lvextend -L +50G /dev/vg_data/data; resize2fs /dev/vg_data/dataSize 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
$ lvcreate -L 5G -s -n data-snap /dev/vg_data/dataLogical volume 'data-snap' successfully created$ mount -o ro,nouuid /dev/vg_data/data-snap /mnt/snap; ls /mnt/snap; umount /mnt/snap; lvremove /dev/vg_data/data-snapSnapshots dir
file1
file2
Do you really want to remove active logical volume data-snap? [y/n]: y
Logical volume 'data-snap' successfully removedMonitoring LVM
$ 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.00gKnowledge check
Knowledge check · 3 questions
Q1. What is the correct order to extend a logical volume and its filesystem?
Q2. LVM snapshots are instant and use little space until the original LV changes.
Q3. Which of the following are correct LVM operations? Select all that apply.
Passing score: 75%. Answers are checked in this browser.