Linux – Create Virtual Block Device Writing to /dev/null

block-devicelinuxnetworkingnull

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!

Best Answer

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'
Related Question