18c2ecf20Sopenharmony_ci=======
28c2ecf20Sopenharmony_cidm-zero
38c2ecf20Sopenharmony_ci=======
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ciDevice-Mapper's "zero" target provides a block-device that always returns
68c2ecf20Sopenharmony_cizero'd data on reads and silently drops writes. This is similar behavior to
78c2ecf20Sopenharmony_ci/dev/zero, but as a block-device instead of a character-device.
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ciDm-zero has no target-specific parameters.
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ciOne very interesting use of dm-zero is for creating "sparse" devices in
128c2ecf20Sopenharmony_ciconjunction with dm-snapshot. A sparse device reports a device-size larger
138c2ecf20Sopenharmony_cithan the amount of actual storage space available for that device. A user can
148c2ecf20Sopenharmony_ciwrite data anywhere within the sparse device and read it back like a normal
158c2ecf20Sopenharmony_cidevice. Reads to previously unwritten areas will return a zero'd buffer. When
168c2ecf20Sopenharmony_cienough data has been written to fill up the actual storage space, the sparse
178c2ecf20Sopenharmony_cidevice is deactivated. This can be very useful for testing device and
188c2ecf20Sopenharmony_cifilesystem limitations.
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ciTo create a sparse device, start by creating a dm-zero device that's the
218c2ecf20Sopenharmony_cidesired size of the sparse device. For this example, we'll assume a 10TB
228c2ecf20Sopenharmony_cisparse device::
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci  TEN_TERABYTES=`expr 10 \* 1024 \* 1024 \* 1024 \* 2`   # 10 TB in sectors
258c2ecf20Sopenharmony_ci  echo "0 $TEN_TERABYTES zero" | dmsetup create zero1
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ciThen create a snapshot of the zero device, using any available block-device as
288c2ecf20Sopenharmony_cithe COW device. The size of the COW device will determine the amount of real
298c2ecf20Sopenharmony_cispace available to the sparse device. For this example, we'll assume /dev/sdb1
308c2ecf20Sopenharmony_ciis an available 10GB partition::
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci  echo "0 $TEN_TERABYTES snapshot /dev/mapper/zero1 /dev/sdb1 p 128" | \
338c2ecf20Sopenharmony_ci     dmsetup create sparse1
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ciThis will create a 10TB sparse device called /dev/mapper/sparse1 that has
368c2ecf20Sopenharmony_ci10GB of actual storage space available. If more than 10GB of data is written
378c2ecf20Sopenharmony_cito this device, it will start returning I/O errors.
38