3 nbdkit - toolkit for creating NBD servers
11 Network Block Device (NBD) is a network protocol for accessing block
12 devices over the network. Block devices are hard disks and things
13 that behave like hard disks such as disk images and virtual machines.
15 nbdkit is both a toolkit for creating NBD servers from
16 “unconventional” sources, and the name of an NBD server. nbdkit ships
17 with many plugins for performing common tasks like serving local
20 =head2 Plugins and filters
22 nbdkit is different from other NBD servers because you can easily
23 create new Network Block Device sources by writing a few glue
24 functions, possibly in C, or perhaps in a high level language like
25 Perl or Python. The liberal licensing of nbdkit is meant to allow you
26 to link nbdkit with proprietary libraries or to include nbdkit in
29 If you want to write your own nbdkit plugin you should read
32 nbdkit also has a concept of filters which can be layered on top of
33 plugins. Several filters are provided with nbdkit and if you want to
34 write your own you should read L<nbdkit-filter(3)>.
38 =head2 Basic file serving
44 Serve file F<disk.img> on port 10809 using L<nbdkit-file-plugin(1)>,
45 and connect to it using L<guestfish(1)>:
48 guestfish --rw --format=raw -a nbd://localhost
52 Serve file F<disk.img> on port 10809, requiring clients to use
53 encrypted (TLS) connections:
55 nbdkit --tls=require file disk.img
59 =head2 Other nbdkit plugins
65 Create a 1MB disk with one empty partition entirely on the command
66 line using L<nbdkit-data-plugin(1)>:
69 data="@0x1b8 0xf8 0x21 0xdc 0xeb 0 0 0 0
70 2 0 0x83 0x20 0x20 0 1 0 0 0 0xff 0x7
75 Forward an NBD connection to a remote server over HTTPS or SSH using
76 L<nbdkit-curl-plugin(1)> or L<nbdkit-ssh-plugin(1)>:
78 nbdkit -r curl https://example.com/disk.img
80 nbdkit ssh host=example.com /var/tmp/disk.img
84 Create a RAM disk using L<nbdkit-memory-plugin(1)>:
90 Create a floppy disk image containing files from a local directory
91 using L<nbdkit-floppy-plugin(1)>:
97 =head2 Combining plugins and filters
103 Serve only the first partition from compressed disk image
104 F<disk.img.xz>, combining L<nbdkit-partition-filter(1)>,
105 L<nbdkit-xz-filter(1)> and L<nbdkit-file-plugin(1)>.
107 nbdkit --filter=partition --filter=xz file disk.img.xz partition=1
109 To understand this command line:
111 plugin name and plugin parameter
115 nbdkit --filter=partition --filter=xz file disk.img.xz partition=1
117 └──────────────┴────┬─────────────────────┘
119 filters and filter parameter
123 Create a scratch, empty nbdkit device and inject errors and delays,
124 for testing clients, using L<nbdkit-memory-plugin(1)>,
125 L<nbdkit-error-filter(1)> and L<nbdkit-delay-filter(1)>:
127 nbdkit --filter=error --filter=delay memory 100M \
128 error-rate=10% rdelay=1 wdelay=1
132 =head2 Writing plugins in scripting languages
138 Write a simple, custom plugin entirely on the command line in shell
139 script using L<nbdkit-sh-plugin(3)>:
144 pread) dd if=/dev/zero count=$3 iflag=count_bytes ;;
151 =head2 Display information
153 Display information about nbdkit or a specific plugin:
158 nbdkit example1 --help
159 nbdkit example1 --dump-plugin
161 =head1 GLOBAL OPTIONS
167 Display brief command line usage information and exit.
169 =item B<-D> PLUGIN.FLAG=N
171 =item B<-D> FILTER.FLAG=N
173 =item B<--debug> PLUGIN.FLAG=N
175 =item B<--debug> FILTER.FLAG=N
177 Set the plugin or filter Debug Flag called C<FLAG> to the integer
178 value C<N>. See L<nbdkit-plugin(3)/Debug Flags>.
180 =item B<--dump-config>
182 Dump out the compile-time configuration values and exit.
183 See L<nbdkit-probing(1)>.
185 =item B<--dump-plugin>
187 Dump out information about the plugin and exit.
188 See L<nbdkit-probing(1)>.
190 =item B<--exit-with-parent>
192 If the parent process exits, we exit. This can be used to avoid
193 complicated cleanup or orphaned nbdkit processes. There are some
194 important caveats with this, see L<nbdkit-captive(1)/EXIT WITH PARENT>.
196 An alternative to this is L<nbdkit-captive(1)/CAPTIVE NBDKIT>.
198 This option implies I<--foreground>.
200 =item B<-e> EXPORTNAME
202 =item B<--export> EXPORTNAME
204 =item B<--export-name> EXPORTNAME
206 =item B<--exportname> EXPORTNAME
210 If not set, exportname C<""> (empty string) is used. Exportnames are
211 not allowed with the oldstyle protocol.
215 =item B<--foreground>
219 I<Don't> fork into the background.
221 =item B<--filter> FILTER
223 Add a filter before the plugin. This option may be given one or more
224 times to stack filters in front of the plugin. They are processed in
225 the order they appear on the command line. See L</FILTERS> and
230 =item B<--group> GROUP
232 Change group to C<GROUP> after starting up. A group name or numeric
233 group ID can be used.
235 The server needs sufficient permissions to be able to do this.
236 Normally this would mean starting the server up as root.
242 =item B<--ip-addr> IPADDR
244 =item B<--ipaddr> IPADDR
246 Listen on the specified interface. The default is to listen on all
247 interfaces. See also I<-p>.
249 =item B<--log=stderr>
251 =item B<--log=syslog>
253 Send error messages to either standard error (I<--log=stderr>) or to
254 the system log (I<--log=syslog>).
256 The default is to send error messages to stderr, unless nbdkit
257 forks into the background in which case they are sent to syslog.
259 For more details see L<nbdkit-service(1)/LOGGING>.
267 Use the newstyle NBD protocol. This is the default in nbdkit
268 E<ge> 1.3. In earlier versions the default was oldstyle.
269 See L<nbdkit-protocol(1)>.
273 Do not advertise structured replies. A client must request structured
274 replies to take advantage of block status and potential sparse reads;
275 however, as structured reads are not a mandatory part of the newstyle
276 NBD protocol, this option can be used to debug client fallbacks for
277 dealing with older servers. See L<nbdkit-protocol(1)>.
285 Use the oldstyle NBD protocol. This I<was> the default in nbdkit
286 E<le> 1.2, but now the default is newstyle. Note this is incompatible
287 with newer features such as export names and TLS.
288 See L<nbdkit-protocol(1)>.
292 =item B<--pid-file> PIDFILE
294 =item B<--pidfile> PIDFILE
296 Write C<PIDFILE> (containing the process ID of the server) after
297 nbdkit becomes ready to accept connections.
299 If the file already exists, it is overwritten. nbdkit I<does not>
300 delete the file when it exits.
306 Change the TCP/IP port number on which nbdkit serves requests.
307 The default is C<10809>. See also I<-i>.
315 The export will be read-only. If a client writes, then it will get an
318 Note that some plugins inherently don't support writes. With those
319 plugins the I<-r> option is added implicitly.
321 L<nbdkit-cow-filter(1)> can be placed over read-only plugins to
322 provide copy-on-write (or "snapshot") functionality. If you are using
323 qemu as a client then it also supports snapshots.
327 Run nbdkit as a captive subprocess of C<CMD>. When C<CMD> exits,
328 nbdkit is killed. See L<nbdkit-captive(1)/CAPTIVE NBDKIT>.
330 This option implies I<--foreground>.
338 Don't fork. Handle a single NBD connection on stdin/stdout. After
339 stdin closes, the server exits.
341 You can use this option to run nbdkit from inetd or similar
342 superservers; or just for testing; or if you want to run nbdkit in a
343 non-conventional way. Note that if you want to run nbdkit from
344 systemd, then it may be better to use
345 L<nbdkit-service(1)/SOCKET ACTIVATION> instead of this option.
347 This option implies I<--foreground>.
349 =item B<--selinux-label> SOCKET-LABEL
351 Apply the SELinux label C<SOCKET-LABEL> to the nbdkit listening
354 The common — perhaps only — use of this option is to allow libvirt
355 guests which are using SELinux and sVirt confinement to access nbdkit
358 nbdkit --selinux-label system_u:object_r:svirt_t:s0 ...
362 =item B<--threads> THREADS
364 Set the number of threads to be used per connection, which in turn
365 controls the number of outstanding requests that can be processed at
366 once. Only matters for plugins with thread_model=parallel (where it
367 defaults to 16). To force serialized behavior (useful if the client
368 is not prepared for out-of-order responses), set this to 1.
374 =item B<--tls=require>
376 Disable, enable or require TLS (authentication and encryption
377 support). See L<nbdkit-tls(1)>.
379 =item B<--tls-certificates> /path/to/certificates
381 Set the path to the TLS certificates directory. If not specified,
382 some built-in paths are checked. See L<nbdkit-tls(1)> for more
385 =item B<--tls-psk> /path/to/pskfile
387 Set the path to the pre-shared keys (PSK) file. If used, this
388 overrides certificate authentication. There is no built-in path. See
389 L<nbdkit-tls(1)> for more details.
391 =item B<--tls-verify-peer>
393 Enables TLS client certificate verification. The default is I<not> to
394 check the client's certificate.
398 =item B<--unix> SOCKET
404 Accept connections on the Unix domain socket C<SOCKET> (which is a
407 nbdkit creates this socket, but it will probably have incorrect
408 permissions (too permissive). If it is a problem that some
409 unauthorized user could connect to this socket between the time that
410 nbdkit starts up and the authorized user connects, then put the socket
411 into a directory that has restrictive permissions.
413 nbdkit does B<not> delete the socket file when it exits. The caller
414 should delete the socket file after use (else if you try to start
415 nbdkit up again you will get an C<Address already in use> error).
417 If the socket name is I<-> then nbdkit generates a randomly named
418 private socket. This is useful with L<nbdkit-captive(1)/CAPTIVE NBDKIT>.
424 Change user to C<USER> after starting up. A user name or numeric user
427 The server needs sufficient permissions to be able to do this.
428 Normally this would mean starting the server up as root.
436 Enable verbose messages.
438 It's a good idea to use I<-f> as well so the process does not fork
439 into the background (but not required).
445 Print the version number of nbdkit and exit.
451 You can give the full path to the plugin, like this:
453 nbdkit $libdir/nbdkit/plugins/nbdkit-file-plugin.so [...]
455 but it is usually more convenient to use this equivalent syntax:
459 C<$libdir> is set at compile time. To print it out, do:
463 =head1 PLUGIN CONFIGURATION
465 After specifying the plugin name you can (optionally, it depends
466 on the plugin) give plugin configuration on the command line in
467 the form of C<key=value>. For example:
469 nbdkit file file=disk.img
471 To list all the options supported by a plugin, do:
475 To dump information about a plugin, do:
477 nbdkit file --dump-plugin
479 =head2 Magic parameters
481 Some plugins declare a special "magic config key". This is a key
482 which is assumed if no C<key=> part is present. For example:
486 is assumed to be C<file=disk.img> because the file plugin declares
487 C<file> as its magic config key. There can be ambiguity in the
488 parsing of magic config keys if the value might look like a
489 C<key=value>. If there could be ambiguity then modify the value,
490 eg. by prefixing it with C<./>
492 There is also a special exception for plugins which do not declare a
493 magic config key, but where the first plugin argument does not contain
494 an C<'='> character: it is assumed to be C<script=value>. This is
495 used by scripting language plugins:
497 nbdkit perl foo.pl [args...]
499 has the same meaning as:
501 nbdkit perl script=foo.pl [args...]
503 =head2 Shebang scripts
505 You can use C<#!> to run nbdkit plugins written in most scripting
506 languages. The file should be executable. For example:
508 #!/usr/sbin/nbdkit perl
513 (see L<nbdkit-perl-plugin(3)> for a full example).
517 nbdkit responds to the following signals:
527 The server exits cleanly.
531 This signal is ignored.
535 =head1 ENVIRONMENT VARIABLES
543 If present in the environment when nbdkit starts up, these trigger
544 L<nbdkit-service(1)/SOCKET ACTIVATION>.
552 L<nbdkit-captive(1)> — Run nbdkit under another process and have it
555 L<nbdkit-loop(1)> — Use nbdkit with the Linux kernel client to create
556 loop devices and loop mounts.
558 L<nbdkit-probing(1)> — How to probe for nbdkit configuration and plugins.
560 L<nbdkit-protocol(1)> — Which parts of the NBD protocol nbdkit supports.
562 L<nbdkit-service(1)> — Running nbdkit as a service, and systemd socket
565 L<nbdkit-tls(1)> — Authentication and encryption of NBD connections
566 (sometimes incorrectly called "SSL").
576 =head2 For developers
581 =head2 Writing plugins in other programming languages
583 __LANG_PLUGIN_LINKS__.
593 L<http://github.com/libguestfs/nbdkit> — Source code.
595 =head2 Other NBD servers
599 L<https://bitbucket.org/hirofuchi/xnbd>.
601 =head2 Documentation for the NBD protocol
603 L<https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md>,
604 L<https://nbd.sourceforge.io/>.
606 =head2 Similar protocols
608 L<https://en.wikipedia.org/wiki/iSCSI>,
609 L<https://en.wikipedia.org/wiki/ATA_over_Ethernet>,
610 L<https://en.wikipedia.org/wiki/Fibre_Channel_over_Ethernet>.
612 =head2 Other manual pages of interest
614 L<gnutls_priority_init(3)>,
617 L<systemd.socket(5)>.
633 Copyright (C) 2013-2019 Red Hat Inc.