nbdkit(1) A toolkit for creating NBD servers

SYNOPSIS


nbdkit [--dump-config] [-e EXPORTNAME] [-f] [-g GROUP] [-i IPADDR]
[--newstyle] [--oldstyle] [-P PIDFILE] [-p PORT] [-r]
[--run CMD] [-s] [-U SOCKET] [-u USER] [-v] [-V]
PLUGIN [key=value [key=value [...]]]

DESCRIPTION

Network Block Device (NBD) is a network protocol for accessing block devices over the network. Block devices are hard disks and things that behave like hard disks such as disk images and virtual machines.

"nbdkit" is both a toolkit for creating NBD servers from ``unconventional'' sources and the name of an NBD server.

To create a new Network Block Device source, all you need to do is write a few glue functions, possibly in C, or perhaps in a high level language like Perl or Python. The liberal licensing of nbdkit is meant to allow you to link nbdkit with proprietary libraries or to include nbdkit in proprietary code.

If you want to write an nbdkit plugin, you should read nbdkit-plugin(3).

Several plugins may be found in "$libdir/nbdkit/plugins". You can give the full path to the plugin, like this:

 nbdkit $libdir/nbdkit/plugins/nbdkit-file-plugin.so [...]

but it is usually more convenient to use this equivalent syntax:

 nbdkit file [...]

$libdir is set at compile time. To print it out, do:

 nbdkit --dump-config

EXAMPLES

Serve file "disk.img" on port 10809:

 nbdkit file file=disk.img

Run the example1 plugin and connect to it using guestfish(1):

 nbdkit example1
 guestfish --ro -a nbd://localhost

Run the example3 plugin and connect to it using guestfish(1):

 nbdkit example3 size=1G
 guestfish --ro -a nbd://localhost

To display usage information about a specific plugin:

 nbdkit --help example1

GLOBAL OPTIONS

--help
Display brief command line usage information and exit.
--dump-config
Dump out the compile-time configuration values and exit.
-e EXPORTNAME
--export EXPORTNAME
--export-name EXPORTNAME
--exportname EXPORTNAME
Set the exportname and use the newstyle protocol (implies -n).

If not set, exportname "" (empty string) is used. Exportnames are not allowed with the oldstyle protocol.

-f
--foreground
--no-fork
Don't fork into the background.
-g GROUP
--group GROUP
Change group to "GROUP" after starting up. A group name or numeric group ID can be used.

The server needs sufficient permissions to be able to do this. Normally this would mean starting the server up as root.

See also -u.

-i IPADDR
--ip-addr IPADDR
--ipaddr IPADDR
Listen on the specified interface. The default is to listen on all interfaces. See also -p.
-n
--new-style
--newstyle
Use the newstyle NBD protocol instead of the default (oldstyle) protocol. See ``NEW STYLE VS OLD STYLE PROTOCOL'' below.
-o
--old-style
--oldstyle
Use the oldstyle NBD protocol. This is currently the default (unless you use -n or -e), so this flag does nothing, but it is possible we might change the default protocol in future. See ``NEW STYLE VS OLD STYLE PROTOCOL'' below.
-P PIDFILE
--pid-file PIDFILE
--pidfile PIDFILE
Write "PIDFILE" (containing the process ID of the server) after nbdkit becomes ready to accept connections.

If the file already exists, it is overwritten. nbdkit does not delete the file when it exits.

-p PORT
--port PORT
Change the TCP/IP port number on which nbdkit serves requests. The default is 10809. See also -i.
-r
--read-only
--readonly
The export will be read-only. If a client writes, then it will get an error.

Note that some plugins inherently don't support writes. With those plugins the -r option is added implicitly.

Copy-on-write (or ``snapshot'') functionality is not supported by this server. However if you are using qemu as a client (or indirectly via libguestfs) then it supports snapshots.

--run CMD
Run nbdkit as a captive subprocess of "CMD". When "CMD" exits, nbdkit is killed. See ``CAPTIVE NBDKIT'' below.

This option implies --foreground.

-s
--single
--stdin
Don't fork. Handle a single NBD connection on stdin/stdout. After stdin closes, the server exits.

You can use this option to run nbdkit from inetd, systemd or similar superservers; or just for testing; or if you want to run nbdkit in a non-conventional way.

This option implies --foreground.

-U SOCKET
--unix SOCKET
-U -
--unix -
Accept connections on the Unix domain socket "SOCKET" (which is a path).

nbdkit creates this socket, but it will probably have incorrect permissions (too permissive). If it is a problem that some unauthorized user could connect to this socket between the time that nbdkit starts up and the authorized user connects, then put the socket into a directory that has restrictive permissions.

nbdkit does not delete the socket file when it exits. The caller should delete the socket file after use (else if you try to start nbdkit up again you will get an "Address already in use" error).

If the socket name is - then nbdkit generates a randomly named private socket. This is useful with ``CAPTIVE NBDKIT''.

-u USER
--user USER
Change user to "USER" after starting up. A user name or numeric user ID can be used.

The server needs sufficient permissions to be able to do this. Normally this would mean starting the server up as root.

See also -g.

-v
--verbose
Enable verbose messages.

It's a good idea to use -f as well so the process does not fork into the background (but not required).

-V
--version
Print the version number of nbdkit and exit.

PLUGIN CONFIGURATION

After specifying the plugin name you can (optionally, it depends on the plugin) give plugin configuration on the command line in the form of "key=value". For example:

 nbdkit file file=disk.img

To list all the options supported by a plugin, do:

 nbdkit --help file

CAPTIVE NBDKIT

You can run nbdkit as a ``captive process'', using the --run option. This means that nbdkit runs as long as (for example) qemu(1) or guestfish(1) is running. When those exit, nbdkit is killed.

Some examples should make this clear.

To run nbdkit captive under qemu:

 nbdkit file file=disk.img --run 'qemu -drive file=$nbd,if=virtio'

On the qemu command line, $nbd is substituted automatically with the right NBD path so it can connect to nbdkit. When qemu exits, nbdkit is killed and cleaned up automatically.

Running nbdkit captive under guestfish:

 nbdkit file file=disk.img --run 'guestfish --format=raw -a $nbd -i'

When guestfish exits, nbdkit is killed.

The following shell variables are available in the --run argument:

$nbd
A URL that refers to the nbdkit port or socket.

Note there is some magic here, since qemu and guestfish URLs have a different format, so nbdkit tries to guess which you are running. If the magic doesn't work, try using the variables below instead.

$port
If ≠ "", the port number that nbdkit is listening on.
$unixsocket
If ≠ "", the Unix domain socket that nbdkit is listening on.

--run implies --foreground. It is not possible, and probably not desirable, to have nbdkit fork into the background when using --run.

Even when running captive, nbdkit still listens on the regular TCP/IP port, unless you specify the -p/-U options. If you want a truly private captive nbdkit, then you should create a private random Unix socket, like this:

 nbdkit -U - plugin [args] --run '...'

NEW STYLE VS OLD STYLE PROTOCOL

The NBD protocol comes in two incompatible forms that we call ``oldstyle'' and ``newstyle''. Unfortunately which protocol you should use depends on the client and cannot be known in advance, nor can it be negotiated from the server side.

nbdkit currently defaults to the oldstyle protocol for compatibility with qemu and libguestfs. This is also the same behaviour as qemu-nbd ≤ 2.5. Use the -n or --newstyle flag on the command line to use the newstyle protocol. Use the -e or --exportname flag to set the exportname for the newstyle protocol. Use the -o or --oldstyle flag to force the oldstyle protocol.

Some common clients and the protocol they require:

 Client                          Protocol
 ------------------------------------------------------------
 qemu <= 2.5 without exportname  oldstyle
 qemu <= 2.5 with exportname     newstyle
 qemu >= 2.6                     client can talk either protocol
 nbd-client < 3.10               client can talk either protocol
 nbd-client >= 3.10              newstyle

If you use qemu ≤ 2.5 without the exportname field against a newstyle server, it will give the error:

 Server requires an export name

If you use qemu ≤ 2.5 with the exportname field against an oldstyle server, it will give the error:

 Server does not support export names

If you use the oldstyle protocol with nbd-client ≥ 3.10, it will give the error:

 Error: It looks like you're trying to connect to an oldstyle server.

If you want to claim compatibility with what the NBD proto.txt document says should be the case (which isn't based in reality), then you should always use newstyle when using port 10809, and use oldstyle on all other ports.

SIGNALS

"nbdkit" responds to the following signals:
"SIGINT"
"SIGQUIT"
"SIGTERM"
The server exits cleanly.
"SIGPIPE"
This signal is ignored.

AUTHORS

Richard W.M. Jones

COPYRIGHT

Copyright (C) 2013 Red Hat Inc.

LICENSE

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of Red Hat nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.