I'm a bit confused about how LVM snapshots are stored and work. I understand that when you create a snapshot with LVM, it doesn't take up any space, but as you make changes to the files on your system, your LVM snapshot volume will grow in size. If they grow in size past the size of their partition, they will be "dropped" and disappear, which is why it is not a good backup solution (other than the fact that it's also on the same physical system).
Does LVM snapshot storage work like the diagram below?
I am trying to show a scenario where the root filesystem partition is mostly empty and has a small amount of data shown in purple. I create a snapshot partition called "Snapshot 1" that gradually fills up when I make changes to the original files, although I'm pretty sure LVM is block-based rather than file-based.
Does this mean that if I had a 100 GB root partition that was only storing 20GB of data, I would never need to worry about my snapshot partition overflowing if I gave it a 21GB size? Or would the snapshot partition have to be as large or larger than the root partition because it also records the differences of the unused space (blocks of 0's)?
Unfortunately, the storage requirements are not quite that straight forward:
COW snapshots are created when a size is specified. The size is allocated from space in the VG, and is the amount of space that can be used for saving COW blocks as writes occur to the origin or snapshot. The size chosen should depend upon the amount of writes that are expected; often 20% of the origin LV is enough. If COW space runs low, it can be extended with extend (shrinking is also allowed with lvreduce.) A small amount of the COW snapshot LV size is used to track COW block locations, so the full size is not available for COW data blocks. Use lvs to check how much space is used, and see --monitor to to automatically extend the size to avoid running out of space. - man lvcreate
Note how the man page doesn't mention any particulars:
...often 20% of the origin LV is enough...A small amount of the COW snapshot LV size is used...
The conclusion I draw from this is that there's no specific way to calculate exactly what size the snapshot LV needs to be to ensure it never runs out of space.
Essentially, since the snapshot LV stores the original blocks prior to being changed, in order for it to never run out of space it would have to be large enough to hold the origin LV plus a little bit more so it can track the COW block locations.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments