Saturday, July 15, 2017

nbd fails with "Negotiation: Error: Server closed connection"

While experimenting with nbd (network block device) on Linux, I ran into connection failures, where both my server and client died:

** Message: virtstyle ipliteral
** Message: connect from, assigned file is /home/user/fs/image
** Message: Authorized client
** Message: Starting to serve
** Message: Size of exported file/device is 33554432
Negotiation: Error: Server closed connection
Error: Read failed: Connection reset by peer


Turned out, this was due to me starting the server using the command line options specifying the file to serve.
./nbd-server localhost:10809 /home/user/fs/image 

Apparently this simply does not work.

Solution was to create the server config file and leave out the server command line options completely.

        exportname = /home/user/fs/image
authfile = /etc/nbd-server/allow


Then run the client with the name specified in the config.

sudo ./nbd-client -name export 10809 /dev/nbd1

I could have saved some time debugging this if I just had read the this bug report thoroughly enough: