Linux Labs

Storage / Stage 7 of 11

LVM snapshots and rollback

Not running Starting usually ~20 s
Leave the lesson

Step 2 of 7 · theory · 5 min

A snapshot keeps only what changed

A snapshot shows the volume as of the moment it was taken, yet it is not a full copy. Here is how it works and what it will not survive.

An LVM snapshot shows a volume as it was when the snapshot was taken. The volume it was taken from is the origin, here data.

A snapshot works by copy-on-write (COW). While an origin block is unchanged, the snapshot reads it from the origin itself. Before the first write to a block, LVM copies its old version into the snapshot's space and only then writes the new one to the origin. That is why 64 MiB is enough: the snapshot keeps only what has changed since it was taken.

This is also its limit. The snapshot takes unchanged data from the same device as the origin. If the device under the group fails, both the volume and the snapshot are lost. A copy on another device protects against that, and it is the subject of the next module.

Check yourself 1 question

Before a risky migration, the volume's data must be protected both from a migration mistake and from a failure of the disk under the group. What is enough?

  • A snapshot protects against a migration mistake. But it reads unchanged blocks from the same disk as the origin and is lost with it when the disk fails.

  • ro guards the snapshot against accidental writes, not against a disk failure: the snapshot still depends on the origin.

  • Both snapshots take unchanged blocks from the origin on the same disk and are lost with it. Check: sudo lvs shows the same group for both.

A snapshot gives a quick rollback after a mistake, but it lives on the same devices as the origin. A copy on another device protects against a disk failure.

Key points

  • A snapshot keeps the old versions of blocks changed since it was taken and reads the rest from the origin.
  • A snapshot lives on the same devices as the origin and is lost with them when they fail.
Ubuntu 24.04
Loading…