[Libguestfs] [PATCH libnbd] ublk: Add new nbdublk program
Richard W.M. Jones
rjones at redhat.com
Thu Aug 25 12:10:55 UTC 2022
This patch adds simple support for a ublk-based NBD client.
It is also available here:
ublk is a way to write Linux block device drivers in userspace:
For simplicity of implementation and because I don't currently
understand the thread model of ublksrv, this only implements
synchronous calls for now. It should be possible to extend this to a
fully asynchronous client without too much difficulty.
It does appear to work, at least for simple cases. I have created
filesystems, files, etc on a ublk device backed by an nbdkit RAM disk,
eg: On one machine do:
$ nbdkit memory 1G
On the client machine with the right kernel etc [see below] do:
# modprobe ublk_drv
# nbdublk /dev/ublkb0 nbd://remote
# ublk list
# blockdev --getsize64 /dev/ublkb0
# mke2fs /dev/ublkb0
# ublk del -n 0
Testing this is not for the fainthearted. I would start with a
throwaway Fedora Rawhide virtual machine, fully upgraded. You will
need to recompile the kernel with CONFIG_BLK_DEV_UBLK=m
You will need to upgrade to liburing 2.2 (I pushed this to Rawhide a
few days ago).
You will need to download & compile: https://github.com/ming1/ubdsrv
Apply this patch to libnbd and compile it with:
export CFLAGS="$CFLAGS -I$HOME/ubdsrv/include"
export CXXFLAGS="$CXXFLAGS -I$HOME/ubdsrv/include"
export LDFLAGS="$LDFLAGS -L$HOME/ubdsrv/lib"
(Check that ublk dependencies are found and nbdublk is compiled)
You will then be able to run nbdublk from the compile directory using:
sudo ./run nbdublk --help
More information about the Libguestfs