snapshot.txt 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. Device-mapper snapshot support
  2. ==============================
  3. Device-mapper allows you, without massive data copying:
  4. *) To create snapshots of any block device i.e. mountable, saved states of
  5. the block device which are also writable without interfering with the
  6. original content;
  7. *) To create device "forks", i.e. multiple different versions of the
  8. same data stream.
  9. In both cases, dm copies only the chunks of data that get changed and
  10. uses a separate copy-on-write (COW) block device for storage.
  11. There are two dm targets available: snapshot and snapshot-origin.
  12. *) snapshot-origin <origin>
  13. which will normally have one or more snapshots based on it.
  14. You must create the snapshot-origin device before you can create snapshots.
  15. Reads will be mapped directly to the backing device. For each write, the
  16. original data will be saved in the <COW device> of each snapshot to keep
  17. its visible content unchanged, at least until the <COW device> fills up.
  18. *) snapshot <origin> <COW device> <persistent?> <chunksize>
  19. A snapshot is created of the <origin> block device. Changed chunks of
  20. <chunksize> sectors will be stored on the <COW device>. Writes will
  21. only go to the <COW device>. Reads will come from the <COW device> or
  22. from <origin> for unchanged data. <COW device> will often be
  23. smaller than the origin and if it fills up the snapshot will become
  24. useless and be disabled, returning errors. So it is important to monitor
  25. the amount of free space and expand the <COW device> before it fills up.
  26. <persistent?> is P (Persistent) or N (Not persistent - will not survive
  27. after reboot).
  28. How this is used by LVM2
  29. ========================
  30. When you create the first LVM2 snapshot of a volume, four dm devices are used:
  31. 1) a device containing the original mapping table of the source volume;
  32. 2) a device used as the <COW device>;
  33. 3) a "snapshot" device, combining #1 and #2, which is the visible snapshot
  34. volume;
  35. 4) the "original" volume (which uses the device number used by the original
  36. source volume), whose table is replaced by a "snapshot-origin" mapping
  37. from device #1.
  38. A fixed naming scheme is used, so with the following commands:
  39. lvcreate -L 1G -n base volumeGroup
  40. lvcreate -L 100M --snapshot -n snap volumeGroup/base
  41. we'll have this situation (with volumes in above order):
  42. # dmsetup table|grep volumeGroup
  43. volumeGroup-base-real: 0 2097152 linear 8:19 384
  44. volumeGroup-snap-cow: 0 204800 linear 8:19 2097536
  45. volumeGroup-snap: 0 2097152 snapshot 254:11 254:12 P 16
  46. volumeGroup-base: 0 2097152 snapshot-origin 254:11
  47. # ls -lL /dev/mapper/volumeGroup-*
  48. brw------- 1 root root 254, 11 29 ago 18:15 /dev/mapper/volumeGroup-base-real
  49. brw------- 1 root root 254, 12 29 ago 18:15 /dev/mapper/volumeGroup-snap-cow
  50. brw------- 1 root root 254, 13 29 ago 18:15 /dev/mapper/volumeGroup-snap
  51. brw------- 1 root root 254, 10 29 ago 18:14 /dev/mapper/volumeGroup-base