Background & Why You Should Use LVM Thin Provisioning
Traditional static partitioning often leads to significant waste. Suppose you create a 100GB Logical Volume (LV) for an Ubuntu Server KVM virtual machine. The moment it is created, the entire 100GB is locked into the Volume Group (VG). Meanwhile, the VM’s operating system only uses about 4GB to 5GB. The remaining 95GB sits completely idle, unavailable to other services.
This scenario is very common on Fedora workstations or homelab servers with limited NVMe storage (often just 500GB to 1TB). If you want to spin up 10 virtual machines to test Kubernetes, statically allocating 50GB to each would exhaust your drive immediately.
LVM Thin Provisioning solves this bottleneck cleanly through allocate-on-demand and overprovisioning mechanisms. Only have a 200GB physical drive? You can still comfortably allocate five 100GB virtual volumes (totalling a nominal 500GB). LVM only allocates physical blocks as the guest OS writes data.
In addition, snapshotting on Thin LVs eliminates the critical drawbacks of classic LVM:
- Instant and space-efficient: The Copy-on-Write mechanism only consumes storage when new data is written.
- No I/O penalty: Traditional LVM snapshots copy entire blocks on write, severely choking I/O after just 3–4 snapshots. With Thin snapshots, you can maintain dozens of snapshots while keeping read/write performance smooth.
- Flexible branching: You can take a snapshot from another snapshot at any time.
Installing Required Tools
Fedora Workstation uses Btrfs by default for its root partition. However, when you add a secondary SSD dedicated to KVM, Podman, or databases, LVM Thin Provisioning provides a rock-solid, easy-to-manage solution—which can also be managed visually using the Cockpit Web Console on Fedora Server.
Install the thin volume management tools with the following command:
sudo dnf install -y lvm2 thin-provisioning-tools
This package includes low-level metadata inspection utilities such as thin_check and thin_dump, which are invaluable during unexpected power outages.
Next, enable LVM’s background monitoring service:
sudo systemctl enable --now lvm2-monitor
This service runs dmeventd, which monitors storage usage and automatically extends the pool when alert thresholds are reached.
Setting Up a Thin Pool and Thin Volumes in Practice
Hands-on example: We will use a secondary drive, /dev/sdb (100GB physical capacity), to set up our lab environment.
Step 1: Initialize the Physical Volume and Volume Group
# Initialize PV
sudo pvcreate /dev/sdb
# Create a VG named vg_lab
sudo vgcreate vg_lab /dev/sdb
Step 2: Create the Thin Pool
A Thin Pool is a special LV that manages two areas: Data space (containing actual data) and Metadata space (the mapping table between virtual and physical blocks).
# Create an 80GB thin pool inside vg_lab
sudo lvcreate -L 80G -T vg_lab/pool_fast
The -T flag specifies the creation of a Thin Pool. LVM automatically allocates around 80MB to 1GB for the metadata pool, depending on the chunk size.
Step 3: Create Overprovisioned Thin Volumes
From the newly created 80GB pool, we provision two 60GB virtual volumes for virtual machines VM1 and VM2 (totalling 120GB virtual, exceeding the 80GB physical limit):
# Create a 60GB virtual thin volume for VM1
sudo lvcreate -V 60G --thinpool pool_fast vg_lab -n lv_vm1
# Create a 60GB virtual thin volume for VM2
sudo lvcreate -V 60G --thinpool pool_fast vg_lab -n lv_vm2
The -V 60G flag defines the virtual size presented to the operating system. Now format the filesystems and mount them for testing:
# Format with xfs and ext4
sudo mkfs.xfs /dev/vg_lab/lv_vm1
sudo mkfs.ext4 /dev/vg_lab/lv_vm2
# Create mount points and mount the volumes
sudo mkdir -p /mnt/vm1 /mnt/vm2
sudo mount /dev/vg_lab/lv_vm1 /mnt/vm1
sudo mount /dev/vg_lab/lv_vm2 /mnt/vm2
Step 4: Take Snapshots and Perform Fast Rollbacks
Before running a system update or testing risky scripts on VM1, take an immediate snapshot:
sudo lvcreate -s --name snap_vm1_before_update vg_lab/lv_vm1
This command completes almost instantaneously. You can mount this snapshot to inspect files or clone it into a separate development environment:
sudo mkdir -p /mnt/snap_test
sudo mount -o ro /dev/vg_lab/snap_vm1_before_update /mnt/snap_test
If tests fail and you need to roll back to the previous state:
# Unmount the original volume before merging (required)
sudo umount /mnt/vm1
# Merge snapshot data back into the original volume
sudo lvconvert --merge vg_lab/snap_vm1_before_update
# Remount the volume
sudo mount /dev/vg_lab/lv_vm1 /mnt/vm1
Safety Mechanism: Automatically Extending the Thin Pool
Overprovisioning is like airline overbooking. If the Thin Pool runs out of 100% of its physical capacity, all hosted volumes will experience I/O hangs or filesystem corruption. The solution is to configure auto-extension.
Open the configuration file /etc/lvm/lvm.conf:
sudo nano /etc/lvm/lvm.conf
Locate the activation section and adjust two settings:
thin_pool_autoextend_threshold = 75
thin_pool_autoextend_percent = 20
How it works: When the pool reaches 75% actual data capacity, the background daemon automatically extends it by 20%, provided there is unallocated space remaining in the Volume Group.
Monitoring and Space Reclamation
Managing thin storage requires routine monitoring to avoid the risk of disk exhaustion.
1. Check Actual Block Consumption
Run the following command to inspect detailed usage:
sudo lvs -o lv_name,vg_name,lv_size,data_percent,metadata_percent,pool_lv
Sample terminal output:
LV VG LSize Data% Meta% Pool
pool_fast vg_lab 80.00g 12.45 4.10
lv_vm1 vg_lab 60.00g 8.20 pool_fast
lv_vm2 vg_lab 60.00g 5.10 pool_fast
Keep a close eye on the Data% column for pool_fast. If this number exceeds 85% and the VG has no free space left for auto-extension, you must add physical storage immediately.
2. Reclaiming Space After Deleting Files (TRIM / Discard)
When you delete a 10GB file in /mnt/vm1, the filesystem merely marks it deleted in the index table. LVM Thin still retains these physical blocks because it has not received a discard request. Run fstrim to release real capacity back to the pool:
sudo fstrim -v /mnt/vm1
Enable the systemd timer for automatic weekly cleanups:
sudo systemctl enable --now fstrim.timer
Note for KVM/QEMU: When attaching a Thin LV to a virtual machine, configure the disk element with the discard='unmap' option in the libvirt XML file. This ensures trim operations performed inside the guest VM pass directly down to the host, returning freed blocks.
3. Troubleshooting When the Pool Reaches 100%
If you accidentally let the pool hit 100% capacity, LVM switches to read-only mode or blocks all write operations to protect your data. Don’t panic—follow these three recovery steps:
- Attach a new physical disk to the machine (for example,
/dev/sdcwith 50GB capacity). - Extend the Volume Group:
sudo vgextend vg_lab /dev/sdc - Extend the Thin Pool:
sudo lvextend -L +40G vg_lab/pool_fast
As soon as free space becomes available in the pool, blocked I/O processes will automatically resume processing without requiring a service restart.
