Linux Labs

Storage / Stage 7 of 11

LVM snapshots and rollback

Not running Starting usually ~20 s
Leave the lesson

Step 3 of 7 · on a machine · 6 min

The snapshot's space

A snapshot's space is used up by every change to the origin. Here is how to take a snapshot and make sure the space lasts.

lvcreate -s takes a snapshot. The -L size is room for changes to the origin, not a copy of the volume:

bash
sudo lvcreate -s -L 64M -n checkpoint /dev/lab_vg/data

It is taken at a consistent moment, when the data on the volume is whole from the point of view of the program writing it. The simplest way is to stop the writes: in this lesson's exercises the filesystem was unmounted before the snapshot. A snapshot taken in the middle of a database write can catch it half-done, so databases have their own ways to reach such a moment.

The Data% column of the snapshot in lvs shows how much space is used. Every changed origin block takes part of it, even when a file is simply overwritten and the space used on the volume stays the same. When Data% reaches 100, the snapshot becomes invalid: its lvs attributes show I, and it can no longer be mounted. Size the space by how much will change while the snapshot lives, and remove a snapshot you no longer need.

Exercise · look

Write to the volume and watch the snapshot

Look at Data% for the checkpoint snapshot, write a 20 MiB blob.bin file to the volume at /mnt/lvm-data and look at Data% again.

First, predict

What will Data% for checkpoint become after 20 MiB is written to the volume?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in
Ubuntu 24.04
Loading…