Virtual block device

block-device

I'm not sure what I should be googling or if FUSE does this (I suspect not). I'd like to create a virtual block device for which all forms of access, for example reads and writes, go directly to my app.

I know I can create a file be used as a block device by doing

dd if=/dev/zero of=~/test count=100k

then create a loopback to it using

losetup /dev/loop0 ~/test`

But I would like accesses going directly to my app instead of to a file. I hope this question is fairly clear.

Best Answer

You can use NBD. Using nbdkit you can even write virtual block devices in shell script or other scripting languages (although stick to C if you want the best performance). I gave a talk about this topic at FOSDEM 2019 where I did a live demo writing a Linux kernel block device in shell script.

Related Question