16cf2a73cSMauro Carvalho Chehab=======
26cf2a73cSMauro Carvalho Chehabdm-zero
36cf2a73cSMauro Carvalho Chehab=======
46cf2a73cSMauro Carvalho Chehab
56cf2a73cSMauro Carvalho ChehabDevice-Mapper's "zero" target provides a block-device that always returns
66cf2a73cSMauro Carvalho Chehabzero'd data on reads and silently drops writes. This is similar behavior to
76cf2a73cSMauro Carvalho Chehab/dev/zero, but as a block-device instead of a character-device.
86cf2a73cSMauro Carvalho Chehab
96cf2a73cSMauro Carvalho ChehabDm-zero has no target-specific parameters.
106cf2a73cSMauro Carvalho Chehab
116cf2a73cSMauro Carvalho ChehabOne very interesting use of dm-zero is for creating "sparse" devices in
126cf2a73cSMauro Carvalho Chehabconjunction with dm-snapshot. A sparse device reports a device-size larger
136cf2a73cSMauro Carvalho Chehabthan the amount of actual storage space available for that device. A user can
146cf2a73cSMauro Carvalho Chehabwrite data anywhere within the sparse device and read it back like a normal
156cf2a73cSMauro Carvalho Chehabdevice. Reads to previously unwritten areas will return a zero'd buffer. When
166cf2a73cSMauro Carvalho Chehabenough data has been written to fill up the actual storage space, the sparse
176cf2a73cSMauro Carvalho Chehabdevice is deactivated. This can be very useful for testing device and
186cf2a73cSMauro Carvalho Chehabfilesystem limitations.
196cf2a73cSMauro Carvalho Chehab
206cf2a73cSMauro Carvalho ChehabTo create a sparse device, start by creating a dm-zero device that's the
216cf2a73cSMauro Carvalho Chehabdesired size of the sparse device. For this example, we'll assume a 10TB
226cf2a73cSMauro Carvalho Chehabsparse device::
236cf2a73cSMauro Carvalho Chehab
246cf2a73cSMauro Carvalho Chehab  TEN_TERABYTES=`expr 10 \* 1024 \* 1024 \* 1024 \* 2`   # 10 TB in sectors
256cf2a73cSMauro Carvalho Chehab  echo "0 $TEN_TERABYTES zero" | dmsetup create zero1
266cf2a73cSMauro Carvalho Chehab
276cf2a73cSMauro Carvalho ChehabThen create a snapshot of the zero device, using any available block-device as
286cf2a73cSMauro Carvalho Chehabthe COW device. The size of the COW device will determine the amount of real
296cf2a73cSMauro Carvalho Chehabspace available to the sparse device. For this example, we'll assume /dev/sdb1
306cf2a73cSMauro Carvalho Chehabis an available 10GB partition::
316cf2a73cSMauro Carvalho Chehab
326cf2a73cSMauro Carvalho Chehab  echo "0 $TEN_TERABYTES snapshot /dev/mapper/zero1 /dev/sdb1 p 128" | \
336cf2a73cSMauro Carvalho Chehab     dmsetup create sparse1
346cf2a73cSMauro Carvalho Chehab
356cf2a73cSMauro Carvalho ChehabThis will create a 10TB sparse device called /dev/mapper/sparse1 that has
366cf2a73cSMauro Carvalho Chehab10GB of actual storage space available. If more than 10GB of data is written
376cf2a73cSMauro Carvalho Chehabto this device, it will start returning I/O errors.
38