nbdkit(1) | NBDKIT | nbdkit(1) |
nbdkit - toolkit for creating NBD servers
nbdkit [-D|--debug PLUGIN|FILTER.FLAG=N] [-e|--exportname EXPORTNAME] [--exit-with-parent] [--filter FILTER ...] [-f|--foreground] [-g|--group GROUP] [-i|--ipaddr IPADDR] [--log stderr|syslog] [-n|--newstyle] [-o|--oldstyle] [-P|--pidfile PIDFILE] [-p|--port PORT] [-r|--readonly] [--run CMD] [-s|--single] [--selinux-label LABEL] [-t|--threads THREADS] [--tls off|on|require] [--tls-certificates /path/to/certificates] [--tls-psk /path/to/pskfile] [--tls-verify-peer] [-U|--unix SOCKET] [-u|--user USER] [-v|--verbose] [-V|--version] PLUGIN [KEY=VALUE [KEY=VALUE [...]]] nbdkit --dump-config nbdkit PLUGIN --dump-plugin nbdkit --help
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.
nbdkit ships with many plugins and filters for performing common tasks like serving files. See the "EXAMPLES" and "SEE ALSO" sections below, and look in the directory "$libdir/nbdkit".
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).
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
Serve file disk.img on port 10809 using nbdkit-file-plugin(1), and connect to it using guestfish(1):
nbdkit file file=disk.img guestfish --rw --format=raw -a nbd://localhost
Serve file disk.img on port 10809, requiring clients to use encrypted (TLS) connections:
nbdkit --tls=require file file=disk.img
Create a 1MB disk with one empty partition entirely on the command line using nbdkit-data-plugin(1):
nbdkit data data="@0x1b8 0xf8 0x21 0xdc 0xeb 0 0 0 0 2 0 0x83 0x20 0x20 0 1 0 0 0 0xff 0x7 @0x1fe 0x55 0xaa" \ size=1M
Forward an NBD connection over HTTP using nbdkit-curl-plugin(1):
nbdkit -r curl http://example.com/disk.img
Serve only the first partition from compressed disk image disk.img.xz, combining nbdkit-xz-plugin(1) and nbdkit-partition-filter(1):
nbdkit --filter=partition xz disk.img.xz partition=1
To understand this command line:
plugin name and plugin parameter │ ┌─────┴────┐ │ │ nbdkit --filter=partition xz disk.img.xz partition=1 │ │ └─────────────┬─────────────────┘ │ filter name and filter parameter
Create a scratch, empty nbdkit device and inject errors and delays, for testing clients, using nbdkit-memory-plugin(1), nbdkit-error-filter(1) and nbdkit-delay-filter(1):
nbdkit --filter=error --filter=delay memory size=100M \ error-rate=10% rdelay=1 wdelay=1
Display information about nbdkit or a specific plugin:
nbdkit --help nbdkit --version nbdkit --dump-config nbdkit example1 --help nbdkit example1 --dump-plugin
An alternative to this is "CAPTIVE NBDKIT" in nbdkit-captive(1).
This option implies --foreground.
If not set, exportname "" (empty string) is used. Exportnames are not allowed with the oldstyle protocol.
The server needs sufficient permissions to be able to do this. Normally this would mean starting the server up as root.
See also -u.
The default is to send error messages to stderr, unless nbdkit forks into the background in which case they are sent to syslog.
For more details see "LOGGING" in nbdkit-service(1).
If the file already exists, it is overwritten. nbdkit does not delete the file when it exits.
Note that some plugins inherently don't support writes. With those plugins the -r option is added implicitly.
nbdkit-cow-filter(1) can be placed over read-only plugins to provide copy-on-write (or "snapshot") functionality. If you are using qemu as a client then it also supports snapshots.
This option implies --foreground.
You can use this option to run nbdkit from inetd or similar superservers; or just for testing; or if you want to run nbdkit in a non-conventional way. Note that if you want to run nbdkit from systemd, then it may be better to use "SOCKET ACTIVATION" in nbdkit-service(1) instead of this option.
This option implies --foreground.
The common — perhaps only — use of this option is to allow libvirt guests which are using SELinux and sVirt confinement to access nbdkit Unix domain sockets:
nbdkit --selinux-label system_u:object_r:svirt_t:s0 ...
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" in nbdkit-captive(1).
The server needs sufficient permissions to be able to do this. Normally this would mean starting the server up as root.
See also -g.
It's a good idea to use -f as well so the process does not fork into the background (but not required).
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
To dump information about a plugin, do:
nbdkit file --dump-plugin
For some plugins, especially those supporting scripting languages like Perl, if the first plugin argument does not contain an '=' character then it is assumed to be "script=value".
That allows scripting language plugins to do:
nbdkit perl foo.pl [args...]
which has the same meaning as:
nbdkit perl script=foo.pl [args...]
You can use "#!" to run nbdkit plugins written in most scripting languages. The file should be executable. For example:
#!/usr/sbin/nbdkit perl sub open { # etc }
(see nbdkit-perl-plugin(3) for a full example).
One or more filters can be placed in front of an nbdkit plugin to modify the behaviour of the plugin, using the --filter parameter. Filters can be used for example to limit requests to an offset/limit, add copy-on-write support, or inject delays or errors (for testing).
NBD ┌─────────┐ ┌─────────┐ ┌────────┐ client ───▶│ filter1 │───▶│ filter2 │── ─ ─ ──▶│ plugin │ request └─────────┘ └─────────┘ └────────┘
Several existing filters are available in the $filterdir. Use "nbdkit --dump-config" to find the directory name.
How to write filters is described in nbdkit-filter(3).
nbdkit responds to the following signals:
nbdkit-captive(1) — Run nbdkit under another process and have it reliably cleaned up.
nbdkit-loop(1) — Use nbdkit with the Linux kernel client to create loop devices and loop mounts.
nbdkit-probing(1) — How to probe for nbdkit configuration and plugins.
nbdkit-protocol(1) — Which parts of the NBD protocol nbdkit supports.
nbdkit-service(1) — Running nbdkit as a service, and systemd socket activation.
nbdkit-tls(1) — Authentication and encryption of NBD connections (sometimes incorrectly called "SSL").
nbdkit-curl-plugin(1), nbdkit-data-plugin(1), nbdkit-example1-plugin(1), nbdkit-example2-plugin(1), nbdkit-example3-plugin(1), nbdkit-example4-plugin(1), nbdkit-ext2-plugin(1), nbdkit-file-plugin(1), nbdkit-floppy-plugin(1), nbdkit-full-plugin(1), nbdkit-guestfs-plugin(1), nbdkit-gzip-plugin(1), nbdkit-iso-plugin(1), nbdkit-libvirt-plugin(1), nbdkit-memory-plugin(1), nbdkit-nbd-plugin(1), nbdkit-null-plugin(1), nbdkit-partitioning-plugin(1), nbdkit-pattern-plugin(1), nbdkit-random-plugin(1), nbdkit-split-plugin(1), nbdkit-streaming-plugin(1), nbdkit-tar-plugin(1), nbdkit-vddk-plugin(1), nbdkit-xz-plugin(1), nbdkit-zero-plugin(1) ; nbdkit-lua-plugin(3), nbdkit-ocaml-plugin(3), nbdkit-perl-plugin(3), nbdkit-python-plugin(3), nbdkit-ruby-plugin(3), nbdkit-sh-plugin(3), nbdkit-tcl-plugin(3) .
nbdkit-blocksize-filter(1), nbdkit-cache-filter(1), nbdkit-cow-filter(1), nbdkit-delay-filter(1), nbdkit-error-filter(1), nbdkit-fua-filter(1), nbdkit-log-filter(1), nbdkit-nozero-filter(1), nbdkit-offset-filter(1), nbdkit-partition-filter(1), nbdkit-truncate-filter(1), nbdkit-xz-filter(1) .
nbdkit-lua-plugin(3), nbdkit-ocaml-plugin(3), nbdkit-perl-plugin(3), nbdkit-python-plugin(3), nbdkit-ruby-plugin(3), nbdkit-sh-plugin(3), nbdkit-tcl-plugin(3).
http://github.com/libguestfs/nbdkit — Source code.
qemu-nbd(1), nbd-server(1), https://bitbucket.org/hirofuchi/xnbd.
https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md, https://nbd.sourceforge.io/.
https://en.wikipedia.org/wiki/iSCSI, https://en.wikipedia.org/wiki/ATA_over_Ethernet, https://en.wikipedia.org/wiki/Fibre_Channel_over_Ethernet.
gnutls_priority_init(3), qemu-img(1), psktool(1), systemd.socket(5).
Eric Blake
Richard W.M. Jones
Yann E. MORIN
Nir Soffer
Pino Toscano
Copyright (C) 2013-2018 Red Hat Inc.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
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.
2019-01-26 | nbdkit-1.10.3 |