skip to content

Before a risky package upgrade you snapshot the Linux server's root-adjacent data volume with `lvcreate -s`. The upgrade goes badly and you want to roll back. What does `lvconvert --merge vg0/snap` do, and why might the rollback not take effect the moment the command returns?

level: seniorimportance: should knowfreq 40%

answer

  1. preserved old chunks written back
  2. snapshot is consumed by the merge
  3. origin must not be open
  4. starts on next activation, reboot for root
  5. every write since the snapshot is discarded

basics

~20 s

lvconvert --merge schedules the snapshot's preserved contents to be written back over the origin, reverting it to the snapshot's point in time and deleting the snapshot when finished. If the origin is open — mounted or in use — the merge is deferred until the volume is next deactivated and reactivated.

solid answer

~50 s

`lvconvert --merge vg0/snap` starts a *snapshot merge*: device-mapper copies the preserved old chunks from the snapshot back onto the origin, so the origin ends up as it was when the snapshot was taken, and the snapshot logical volume is removed automatically once the merge completes. The catch is that merging cannot begin while the origin is open. If the filesystem is mounted or anything holds the device, LVM records the intent and reports that the merge will start on the next activation — you unmount the origin and deactivate/reactivate it (or, for a volume the running system depends on, reboot) for it to actually begin. While a merge is in progress the origin is usable and reads are served correctly from wherever the current data lives, and `lvs` shows the merge draining toward zero. Two things to say out loud: everything written to the origin since the snapshot is discarded, and for a thin snapshot the command is `lvconvert --mergethin` instead.

code

bash · 13 lines
bash
# ask for the rollback; LVM defers it while the origin is open
lvconvert --merge vg0/data-snap

# free the origin so the merge can start on the next activation
umount /data
lvchange -an vg0/data
lvchange -ay vg0/data

# watch the merging snapshot drain toward zero
lvs -o lv_name,origin,lv_attr,data_percent vg0

# a snapshot of a thin volume uses the thin variant instead
lvconvert --mergethin vg0/app-snap

go deeper

for a junior

Know that a snapshot can be merged back over its origin to undo changes, that the snapshot disappears afterwards, and that everything written since it was taken is lost.

for a middle

Explain the mechanics: the preserved old chunks are copied back onto the origin, the merge cannot start while the origin is open, and it therefore begins at the next activation — with the thin variant using --mergethin.

for a senior

Show you would plan the rollback: confirm the snapshot is still valid, copy off anything written since, unmount and reactivate (or schedule the reboot for a root volume), watch the merge drain, and state plainly which state outside this volume the rollback does not undo.

for a principal

Frame it as a change-safety strategy: which classes of change a single-host block rollback can actually cover, what it cannot (distributed state, anything already sent downstream), and whether the fleet's rollback story should rest on snapshots, redeployable images, or both.

## What a merge is A classic snapshot holds the *old* contents of every chunk that changed on the origin since creation. That is exactly the material needed to undo those changes. `lvconvert --merge vg0/snap` asks device-mapper to write those preserved chunks back over the origin, chunk by chunk, until the origin is byte-identical to its state at snapshot time. When the merge finishes, the snapshot has served its purpose and LVM removes it — you do not clean up afterwards, and you cannot merge the same snapshot twice. This makes "snapshot before the change, merge if it goes wrong" a genuine rollback primitive for upgrades, migrations and configuration changes on a single host, provided the change is confined to that volume. ## Why it may not start immediately Merging rewrites the origin underneath anything that has it open. A mounted filesystem has cached metadata and in-flight I/O that would be silently invalidated, so LVM refuses to begin while the origin is in use. Instead it flags the merge and tells you it will start on the next activation. The practical sequences are: - **A data volume:** stop the services using it, `umount` it, then `lvchange -an vg0/data` followed by `lvchange -ay vg0/data`. The merge begins on activation and you can watch it. - **A volume the running system depends on** (the root filesystem, or anything that cannot be unmounted live): issue the merge, then reboot. Early boot activates the volume and the merge starts there. This is why root-volume rollback via LVM is a reboot-shaped operation, not an online one. While a merge is running, the origin can be used: reads are satisfied correctly whether the chunk has been merged back yet or not. `lvs` shows the merging snapshot's usage draining toward zero — a straightforward progress indicator — and the origin's attribute string shows it as a merging origin. ``` $ lvconvert --merge vg0/data-snap Delaying merge since origin is open. Merging of snapshot vg0/data-snap will occur on next activation. $ umount /data && lvchange -an vg0/data && lvchange -ay vg0/data $ lvs -o lv_name,origin,lv_attr,data_percent vg0 ``` If you change your mind before the merge begins, `lvconvert --mergethin`'s classic counterpart can be cancelled by removing the snapshot with `lvremove`, which drops the pending merge along with it. ## What the rollback costs you Three consequences worth stating without being asked: 1. **Everything written since the snapshot is gone.** Not just the failed upgrade — logs, new records, anything the application accepted in the meantime. If the volume took real traffic during the attempt, a merge is a data-loss event that you are choosing deliberately. Copy off what you need first. 2. **The window is bounded by the copy-on-write area.** If the snapshot filled and was invalidated at any point, there is nothing to merge; the rollback plan evaporated quietly hours before you needed it. Check the snapshot is still valid before you rely on it, and size it for the whole change window. 3. **The scope is one volume.** A change that also touched a database on another volume, a remote service, or state outside the machine is not undone. LVM rollback is a block-level undo of one logical volume, and pairing it with anything distributed needs a plan of its own. ## Thin snapshots For a snapshot of a thin volume the operation is `lvconvert --mergethin vg0/thin-snap`. The mechanics differ underneath — instead of copying preserved chunks back, dm-thin repoints the origin's mapping tree at the snapshot's — so the merge is close to instantaneous rather than proportional to the amount changed. The same open-device restriction applies: the origin must not be in use when the merge takes effect, and the snapshot is consumed by the operation. ## The interview shape A strong answer covers three beats: what merge means (write the preserved old data back and delete the snapshot), why it defers (the origin cannot be open while it is rewritten, so it starts on the next activation — reboot for a root volume), and what it costs (all writes since the snapshot, and only for that one volume). Mentioning that an invalidated snapshot means no rollback at all is the detail that marks someone who has actually depended on this.

  • What happens to the snapshot logical volume after a successful merge?
    It is removed automatically. The merge consumes it — its preserved chunks have been written back onto the origin, so it holds nothing useful and LVM deletes it rather than leaving a stale volume behind. That also means the rollback is one-shot: to protect the next attempt you take a fresh snapshot.
  • How do you roll back the root filesystem's logical volume this way?
    You cannot merge it while the system is running on it, so you issue `lvconvert --merge`, which records the pending merge, and reboot. The volume is activated early in boot and the merge starts there. Plan it as a reboot with downtime, and make sure the initramfs and boot path can still bring the machine up from the reverted state.
  • You issued the merge but changed your mind before it started. Can you cancel it?
    Yes, as long as it has not begun: removing the snapshot with `lvremove` drops the pending merge together with the snapshot, and the origin keeps its current contents. Once the merge is actually running the origin is being rewritten, so the sensible move is to let it finish rather than to interrupt it partway.
  • The snapshot you planned to roll back to shows an invalid flag. What are your options?
    None involving that snapshot — an invalidated snapshot has stopped preserving data and cannot be merged. You are down to whatever real backups exist and to fixing forward. The lesson is procedural: size the copy-on-write area for the whole change window and check the snapshot is still valid before you commit to a risky step.

saying these in an interview costs you the question

  • Expects the origin to revert while it is still mounted
  • Thinks the snapshot survives the merge and can be reused
  • Forgets that writes since the snapshot are discarded
  • Assumes a root-volume merge can happen without a reboot
  • Relies on a snapshot without checking it is still valid

context