0

To my understanding, an LVM snapshot has a size upon creation. According to the LVM man page, a snapshot can have all its space used up and be rendered unusable(unless extended). But how does its space gets used up ?

Let's say: I have a file of 10M on the source(the original logical volume). When I create a snapshot, it will be identical. I appended some data in the source file. Now the file size is 15M. If I do the same thing all over again, by making the 15M file to 20M in size, will the 15M file replace the 10M file on the snapshot ? if not, then in what way does the snapshot gets its available space used up ?

1
  • 1
    The snapshot contains the disk blocks (or extents? Not sure) that are modified. Each time you add 5MB to that file, 5MB more will be used on the snapshot. May 22, 2021 at 7:34

1 Answer 1

2

Copy-on-write LVM snapshots contain the differences between the snapshot and the origin. So every time a change is made to either, the change is added to the snapshot, potentially increasing the space needed in the snapshot. (“Potentially” because changes to blocks that have already been snapshotted for a previous change don’t need more space, they overwrite the previous change — the goal is to track the current differences, not the history of all the changes.)

LVs aren’t aware of the structure of data stored inside them. Appending 5MiB to a file results in at least 5MiB of changes written to the origin, so the changed blocks need to be added to the snapshot (to preserve their snapshotted contents). Writing another 5MiB to the file results in another 5MiB (at least) of changes to the origin, which result in a similar amount of data being written to the snapshot (again, to preserve the original contents). The contents of the file, or indeed the volume, as seen in the snapshot, never change as a result of changes to the origin.

1
  • Wow. That's a very good explanation. It makes sense now. Thanks Stephen. May 22, 2021 at 8:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .