An LVM snapshot is an instant picture of a volume at a precise moment, taken online, without stopping the service. It serves two purposes: backing up a volume in use consistently, and rolling back after a risky operation. This guide shows how to create a snapshot, use it for a backup, and above all restore an earlier state with lvconvert --merge. For intermediate Linux administrators, on Debian/Ubuntu and RHEL/AlmaLinux. All outputs come from a real test on AlmaLinux 10 (LVM 2.03.36).
What you will learn
- Create a snapshot of a logical volume with
lvcreate -s - Understand the copy-on-write mechanism and size the snapshot
- Back up a volume online without inconsistency
- Restore an earlier state (rollback) with
lvconvert --merge - Keep a full snapshot from being invalidated
Prerequisites
An LVM stack in place with at least one logical volume formatted and mounted (see the LVM guide). The Volume Group must have free space (vgs, VFree column) to host the snapshot.
What is an LVM snapshot
A snapshot is a frozen image of a logical volume (the origin) at the moment it is created. The mechanism is called copy-on-write (COW): instead of copying the whole volume, LVM only stores the blocks changed since the snapshot was taken. As long as nothing changes on the origin, the snapshot consumes almost nothing.
That is what makes the snapshot fast and light to create, even on a large volume. The size you reserve (-L) only stores these differences: you size it according to the expected volume of writes during the snapshot's lifetime, not according to the size of the origin.
Create a snapshot
You create a snapshot with the -s (--snapshot) option, reserving a size for the changed blocks:
-
Create the snapshot of an
lvdatavolume, with 256 MiB reserved:Terminal window sudo lvcreate -s -L 256M -n lvdata-snap vg_data/lvdataLogical volume "lvdata-snap" created. -
Change the origin (the volume keeps serving normally), then watch the snapshot fill up:
Terminal window sudo lvs -o lv_name,origin,data_percent vg_dataLV Origin Data%lvdatalvdata-snap lvdata 0.02
The lvdata-snap snapshot points to its origin lvdata, and its Data% climbs as the origin is changed. Here, after a small write, it is only 0.02% full: only the blocks actually changed are copied.
Back up a volume online consistently
The first use of a snapshot is the consistent backup. Backing up a volume while it is being written produces inconsistent files (half modified). The snapshot solves this problem: you freeze the state at time T, then back up the snapshot while the origin keeps running.
# 1. Freeze the current statesudo lvcreate -s -L 1G -n db-snap vg_data/lv_db
# 2. Back up the snapshot (the origin stays in service)sudo mount -o ro /dev/vg_data/db-snap /mnt/snapsudo tar czf /backup/db-$(date +%F).tar.gz -C /mnt/snap .sudo umount /mnt/snap
# 3. Release the snapshot once the backup is donesudo lvremove -y vg_data/db-snapThe database suffers no interruption: it writes to the origin, you back up the frozen image.
Restore an earlier state with lvconvert --merge
The second use, often forgotten, is the rollback. Before a risky update, you take a snapshot; if the operation goes wrong, you merge the snapshot into the origin to go back to the previous state, with lvconvert --merge.
-
Unmount the origin (an immediate merge requires it to be closed):
Terminal window sudo umount /mnt/data -
Merge the snapshot into the origin:
Terminal window sudo lvconvert --merge vg_data/lvdata-snapMerging of volume vg_data/lvdata-snap started.vg_data/lvdata: Merged: 100.00%Merge of snapshot into logical volume vg_data/lvdata has finished.Logical volume "lvdata-snap" successfully removed. -
Mount again: the origin is back to the snapshot's state, and the snapshot is consumed then removed automatically, as the last line of output says:
Terminal window sudo mount /dev/vg_data/lvdata /mnt/datacat /mnt/data/fichier.txt# contenu version 1 (later changes are gone)
As long as the merge is not finished, the origin stays tied to the merging snapshot. Meanwhile, LVM refuses to take a new snapshot of the same origin, with the message "Snapshots of an origin that has a merging snapshot are not supported". Wait until lvs no longer lists the snapshot before creating another one.
The danger: a full snapshot
A classic snapshot only has a fixed reserve to store the copied blocks, and that is its weak point. Every write on the origin consumes a little of this reserve: if the origin is changed more than the reserved size, the snapshot fills up to 100%. Here is what lvs shows for a 12 MiB snapshot after 40 MiB of writes on the origin:
LV Attr Data% lv owi-a-s--- petit swi-I-s--- 100.00The dmeventd daemon, which monitors snapshots by default (monitoring=1 in lvm.conf), writes "WARNING: Snapshot … is now 80.00% full" to the system log from 80%, then at every 5% step. When the snapshot becomes invalid, it also tries to unmount it. These messages are the last signal before the loss: watch them, or watch the Data% directly.
The fix: size generously the snapshot area when the origin is very active, and watch its Data% during its lifetime. LVM can also grow a snapshot automatically, but this extension is disabled by default: lvmconfig shows snapshot_autoextend_threshold=100, the value that turns it off. With snapshot_autoextend_threshold = 70 and snapshot_autoextend_percent = 20 in the activation section of lvm.conf, a 1 GiB snapshot grows to 1.2 GiB once 700 MiB are used, provided dmeventd monitors the volume and the VG has free space. In any case, a snapshot is not meant to live long: create it, use it, remove it.
Classic snapshots or thin snapshots?
The snapshot described here is the classic snapshot: it preallocates a fixed size and becomes invalid if it overflows. When you multiply snapshots (frequent backups, test environments), thin snapshots are more efficient: they preallocate no fixed space and share the pool's blocks.
# Snapshot of a thin volume: no -L size to reservesudo lvcreate -s -n lvdata-snap vg_data/thin_lvdataThis size-less form only works for a thin volume. On a classic logical volume, the same command without -L fails with "Please specify either size or extents with snapshots". The risk then moves to the saturation of the thin pool rather than of the snapshot itself. See the LVM thin provisioning guide.
Troubleshooting
Snapshot incidents almost all show up as a precise message or in a lvs column. Start with lvs -o lv_name,attr,origin,data_percent: the attribute and the Data% tell you whether the snapshot still exists, whether it is invalid or whether it is being merged.
| Symptom | Likely cause | Fix |
|---|---|---|
lvcreate -s refuses: not enough space | VG full | vgs (VFree), free space or add a disk |
Please specify either size or extents with snapshots | -L forgotten on a classic volume | add -L, only a thin volume goes without it |
Snapshot in swi-I-s---, cannot be mounted | full snapshot (Data% at 100) | lvremove, recreate it bigger, watch how full it gets |
Delaying merge since origin is open | origin still mounted or open | unmount, then lvchange -an and -ay, or wait for the reboot |
Snapshots of an origin that has a merging snapshot are not supported | a merge is still running | wait until lvs no longer lists the merged snapshot |
Key points
- A snapshot (
lvcreate -s) freezes a volume at time T, through copy-on-write (only changed blocks are copied). - It serves for the consistent backup (back up the snapshot while the origin runs) and for the rollback.
- The rollback is done with
lvconvert --merge; unmount the origin for an immediate effect, otherwise it applies at the next activation. - A full snapshot is invalidated: size its area according to the expected writes and watch its
Data%. - For many snapshots, prefer thin snapshots on a thin pool.
- A snapshot is temporary: create, use, remove.
Knowledge check
Check that the essentials of this guide are acquired. The questions only cover what has just been explained here.
Knowledge check
Check what you have learned with this interactive quiz
How it works
- The timer starts when you click Start
- Multiple choice, true/false and short answer questions
- You can move between questions
- Detailed results are shown at the end
Starts the quiz and the timer
Review
(0/0)Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: LVM thin provisioning: allocate storage on demand
A new full quiz with random questions
Work again only on the questions you missed
FAQ: frequently asked questions about LVM snapshots
These answers cover the questions that come up most about LVM snapshots: their principle, the rollback, sizing and the choice between a classic and a thin snapshot.
lvconvert --merge vg/snapshot, which merges the snapshot into its origin and brings the volume back to the frozen state. If the origin is unmounted, the merge starts immediately. Otherwise, the command answers "Delaying merge since origin is open" and the merge is deferred to the next activation of the volume: lvchange -an then -ay after unmounting, or the reboot for a root file system. After the merge, the snapshot is automatically consumed and removed. It is the rollback mechanism to know before any risky operation.-L) of a classic snapshot only stores the blocks changed on the origin during the snapshot's life, not a copy of the whole volume. You therefore size it according to the expected volume of writes: generous if the origin is very active or if the snapshot must live long, more modest otherwise. An undersized snapshot fills up and becomes invalid, so plan a margin and watch its Data%.lvs shows an I in its attributes, it is unmounted if possible and can no longer serve for rollback or backup. The loss is silent, hence the risk. The dmeventd daemon logs a warning from 80% full. The fix: size generously, watch Data%, and do not keep a snapshot longer than needed.-L) and becomes invalid if it overflows: perfect for one-off use (a backup, a test). The thin snapshot, created on a thin pool, preallocates no fixed space and shares the pool's blocks: it is far more efficient when you multiply snapshots (frequent backups, many environments). The risk then moves to the saturation of the thin pool rather than of the snapshot.