15

I want to test some physical links in a setup. The software tooling that I can use to test this require a block device to read/write from/to. The block devices I have available can't saturate the physical link so I can't fully test it.

I know I can setup a virtual block device which is backed by a file. So my idea was to somehow setup a virtual block device to /dev/null but the problem is of course that I can't read from it. Is there a way I could setup a virtual block device that writes to /dev/null but just returns always zero when read?

Thank you for any help!

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
John Smith
  • 337
  • 2
  • 8
  • 1
    You could also see if this looks interesting to you https://www.kernel.org/doc/Documentation/block/null_blk.txt –  Nov 08 '19 at 12:03
  • 1
    Being that the context seems to be Linux and this is a highly OS-specific (kernel-specific) question, I added `linux` tag. Please feel free to remove if this is in error, or add other tags as appropriate. – R.. GitHub STOP HELPING ICE Nov 08 '19 at 13:55

2 Answers2

33

https://wiki.gentoo.org/wiki/Device-mapper#Zero

See Documentation/device-mapper/zero.txt for usage. This target has no target-specific parameters.

The "zero" target create that functions similarly to /dev/zero: All reads return binary zero, and all writes are discarded. Normally used in tests [...]

This creates a 1GB (1953125-sector) zero target:

root# dmsetup create 1gb-zero --table '0 1953125 zero'
sourcejedi
  • 48,311
  • 17
  • 143
  • 296
5

If you don't need it to have a specific limited size, you can just use /dev/zero directly. Technically it's a character device, not block.

/dev/zero discards writes like /dev/null but reads as zero instead of EOF.

As documented in the man page, on Linux you can make your own under any name with
mknod -m 666 /dev/zero c 1 5 Or of course make a symlink to /dev/zero.

Peter Cordes
  • 6,328
  • 22
  • 41