NDB – Network Block Device setup

I have been trying to setup NBD to present a shared storage device for me to play around with Xen live mobility. NBD is not tricky, but the documentation, both official and Google, is flawed and confusing.

To get a basic device working and mounted, follow the simple guide below.

Setup a basic config file /etc/nbd-server/config

user = nbd
group = nbd
listenaddr = 2021:85b:2d9:1::101
allowlist = true

exportname = /dev/rootvg/nbdlv

allowlist is not stricly necessary, but it helps being able to list exported devices from the client end whilst configuring all this. Maybe remove it afterwards…

The main thing to take note of in the server configuration is the section heading which contains the device on the server to export. The section heading is what the client sees and connects to. Furthermore, the nbd-client man page appears to be incorrect, so go by the nbd-client usage text which says:

Usage: nbd-client -name|-N name host [port] nbd_device

so the correct way to connect to the device exported is:

nbd-client 2021:85b:2d9:1::101 10809 /dev/nbd0 -N grafana-root

/dev/nbd0 is a device on the client which you can choose from amongst what you can see with the listing ls /dev/nbd*.

From the client, you can see what is exported by the command

nbd-client -l 2021:85b:2d9:1::101

Negotiation: ..

If you get the error

Error: Cannot open NBD: No such file or directory
Please ensure the 'nbd' module is loaded.

you need to load the module for nbd-client: modprobe nbd

If you get the following error

Negotiation: ..Error: Unknown error in reply to NBD_OPT_GO; cannot continue

Is is because you have missed out the -N option with the share name in the command. Despite this option being mandatory, nbd-client doesn’t enforce it and the man page doesn’t even mention the option. Poor form. Or maybe it is because you can specify it in nbdtab, I have not looked in to that.

Generally, nbd is badly documented and has some bugs, not great. But once it is up and running, it is ok.

This entry was posted in Linux and tagged , , , . Bookmark the permalink.

Leave a Reply