docs: Fix typo in nbdkit-probing manual page
[nbdkit.git] / docs / nbdkit.pod
blob01dcb196b0571ed3ec92d4299ffe97c17770a54d
1 =head1 NAME
3 nbdkit - toolkit for creating NBD servers
5 =head1 SYNOPSIS
7 __SYNOPSIS__
9 =head1 DESCRIPTION
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
18 files.
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
27 proprietary code.
29 If you want to write your own nbdkit plugin you should read
30 L<nbdkit-plugin(3)>.
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)>.
36 =head1 EXAMPLES
38 =head2 Basic file serving
40 =over 4
42 =item *
44 Serve file F<disk.img> on port 10809 using L<nbdkit-file-plugin(1)>,
45 and connect to it using L<guestfish(1)>:
47  nbdkit file disk.img
48  guestfish --rw --format=raw -a nbd://localhost
50 =item *
52 Serve file F<disk.img> on port 10809, requiring clients to use
53 encrypted (TLS) connections:
55  nbdkit --tls=require file disk.img
57 =back
59 =head2 Other nbdkit plugins
61 =over 4
63 =item *
65 Create a small disk containing test patterns using
66 L<nbdkit-data-plugin(1)>:
68  nbdkit data ' ( 0x55 0xAA )*2048 '
70 =item *
72 Forward an NBD connection to a remote server over HTTPS or SSH using
73 L<nbdkit-curl-plugin(1)> or L<nbdkit-ssh-plugin(1)>:
75  nbdkit -r curl https://example.com/disk.img
77 =for paragraph
79  nbdkit ssh host=example.com /var/tmp/disk.img
81 =item *
83 Create a sparse 1 terabyte RAM disk using L<nbdkit-memory-plugin(1)>
84 and use it as a loop device (L<nbdkit-loop(1)>):
86  nbdkit memory 1T
87  nbd-client localhost /dev/nbd0
89 =item *
91 Create a floppy disk image containing files from a local directory
92 using L<nbdkit-floppy-plugin(1)>:
94  nbdkit floppy dir/
96 =back
98 =head2 Combining plugins and filters
100 =over 4
102 =item *
104 Serve only the first partition from compressed disk image
105 F<disk.img.xz>, combining L<nbdkit-partition-filter(1)>,
106 L<nbdkit-xz-filter(1)> and L<nbdkit-file-plugin(1)>.
108  nbdkit --filter=partition --filter=xz file disk.img.xz partition=1
110 To understand this command line:
112                              plugin name and plugin parameter
113                                                │
114                                        ┌───────┴──────┐
115                                        │              │
116  nbdkit --filter=partition --filter=xz file disk.img.xz partition=1
117                  │              │                          │
118                  └──────────────┴────┬─────────────────────┘
119                                      │
120                         filters and filter parameter
122 =item *
124 Create a scratch, empty nbdkit device and inject errors and delays,
125 for testing clients, using L<nbdkit-memory-plugin(1)>,
126 L<nbdkit-error-filter(1)> and L<nbdkit-delay-filter(1)>:
128  nbdkit --filter=error --filter=delay memory 100M \
129         error-rate=10% rdelay=1 wdelay=1
131 =back
133 =head2 Writing plugins in shell script
135 =over 4
137 =item *
139 Write a simple, custom plugin in shell script using
140 L<nbdkit-sh-plugin(3)>:
142  nbdkit sh - <<'EOF'
143    case "$1" in
144      get_size) echo 1M ;;
145      pread) dd if=/dev/zero count=$3 iflag=count_bytes ;;
146      *) exit 2 ;;
147    esac
148  EOF
150 =item *
152 The same example as above can be written entirely on the command line
153 using L<nbdkit-eval-plugin(1)>:
155  nbdkit eval get_size='echo 1M' \
156              pread='dd if=/dev/zero count=$3 iflag=count_bytes'
158 =back
160 =head2 Display information
162 Display information about nbdkit or a specific plugin:
164  nbdkit --help
165  nbdkit --version
166  nbdkit --dump-config
167  nbdkit example1 --help
168  nbdkit example1 --dump-plugin
170 =head1 GLOBAL OPTIONS
172 =over 4
174 =item B<--help>
176 Display brief command line usage information and exit.
178 =item B<-4>
180 =item B<--ipv4-only>
182 =item B<-6>
184 =item B<--ipv6-only>
186 When a non-numeric argument is passed to the I<-i> option (such as a
187 Fully Qualified Domain Name, or a host name from C</etc/hosts>),
188 restrict the name resolution to IPv4 or IPv6 addresses.
190 When the I<-i> option is omitted, listen on only the IPv4 or IPv6
191 address of all interfaces (C<0.0.0.0> or C<::>, respectively).
193 When both I<-4> and I<-6> options are present on the command line, the
194 last one takes effect.
196 =item B<-D> PLUGIN.FLAG=N
198 =item B<-D> FILTER.FLAG=N
200 =item B<--debug> PLUGIN.FLAG=N
202 =item B<--debug> FILTER.FLAG=N
204 Set the plugin or filter Debug Flag called C<FLAG> to the integer
205 value C<N>.  See L<nbdkit-plugin(3)/Debug Flags>.
207 =item B<-D> nbdkit.FLAG=N
209 =item B<--debug> nbdkit.FLAG=N
211 (nbdkit E<ge> 1.18)
213 Set the nbdkit server Debug Flag called C<FLAG> to the integer value
214 C<N>.  See L</SERVER DEBUG FLAGS> below.
216 =item B<--dump-config>
218 Dump out the compile-time configuration values and exit.
219 See L<nbdkit-probing(1)>.
221 =item B<--dump-plugin>
223 Dump out information about the plugin and exit.
224 See L<nbdkit-probing(1)>.
226 =item B<--exit-with-parent>
228 If the parent process exits, we exit.  This can be used to avoid
229 complicated cleanup or orphaned nbdkit processes.  There are some
230 important caveats with this, see L<nbdkit-captive(1)/EXIT WITH PARENT>.
232 An alternative to this is L<nbdkit-captive(1)/CAPTIVE NBDKIT>.
234 This option implies I<--foreground>.
236 =item B<-e> EXPORTNAME
238 =item B<--export=>EXPORTNAME
240 =item B<--export-name=>EXPORTNAME
242 =item B<--exportname=>EXPORTNAME
244 Set a preferred exportname to expose in the shell environment created
245 during I<--run>.  The use of this option without I<--run> has no
246 effect.  This option does I<not> change what nbdkit advertises as a
247 server, but can aid in writing a captive client that wants to access
248 particular content from a plugin that differentiates content based on
249 the client's choice of export name.
251 If not set, the I<--run> environment is set to access the default
252 exportname C<""> (empty string).
254 =item B<--filter=>FILTER
256 Add a filter before the plugin.  This option may be given one or more
257 times to stack filters in front of the plugin.  They are processed in
258 the order they appear on the command line.  See L</FILTERS> and
259 L<nbdkit-filter(3)>.
261 =item B<-f>
263 =item B<--foreground>
265 =item B<--no-fork>
267 I<Don't> fork into the background.
269 =item B<-g> GROUP
271 =item B<--group=>GROUP
273 Change group to C<GROUP> after starting up.  A group name or numeric
274 group ID can be used.
276 The server needs sufficient permissions to be able to do this.
277 Normally this would mean starting the server up as root.
279 See also I<-u>.
281 =item B<-i> IPADDR
283 =item B<--ip-addr=>IPADDR
285 =item B<--ipaddr=>IPADDR
287 Listen on the specified interface.  The default is to listen on all
288 interfaces.  See also I<-4>, I<-6>, and I<-p>.
290 =item B<--log=stderr>
292 =item B<--log=syslog>
294 =item B<--log=null>
296 Send error messages to standard error (I<--log=stderr>), or to the
297 system log (I<--log=syslog>), or discard them completely
298 (I<--log=null>, not recommended for normal use).
300 The default is to send error messages to stderr, unless nbdkit
301 forks into the background in which case they are sent to syslog.
303 For more details see L<nbdkit-service(1)/LOGGING>.
305 =item B<--mask-handshake=>MASK
307 This option can be used to mask off particular global features which
308 are advertised during new-style handshake (defaulting to all supported
309 bits set).  See L<nbdkit-protocol(1)>.
311 =item B<-n>
313 =item B<--new-style>
315 =item B<--newstyle>
317 Use the newstyle NBD protocol.  This is the default in nbdkit
318 E<ge> 1.3.  In earlier versions the default was oldstyle.
319 See L<nbdkit-protocol(1)>.
321 =item B<--no-sr>
323 Do not advertise structured replies.  A client must request structured
324 replies to take advantage of block status and potential sparse reads;
325 however, as structured reads are not a mandatory part of the newstyle
326 NBD protocol, this option can be used to debug client fallbacks for
327 dealing with older servers.  See L<nbdkit-protocol(1)>.
329 =item B<-o>
331 =item B<--old-style>
333 =item B<--oldstyle>
335 Use the oldstyle NBD protocol.  This I<was> the default in nbdkit
336 E<le> 1.2, but now the default is newstyle.  Note this is incompatible
337 with newer features such as export names and TLS.
338 See L<nbdkit-protocol(1)>.
340 =item B<-P> PIDFILE
342 =item B<--pid-file=>PIDFILE
344 =item B<--pidfile=>PIDFILE
346 Write C<PIDFILE> (containing the process ID of the server) after
347 nbdkit becomes ready to accept connections.
349 If the file already exists, it is overwritten.  nbdkit I<does not>
350 delete the file when it exits.
352 =item B<-p> PORT
354 =item B<--port=>PORT
356 Change the TCP/IP port number on which nbdkit serves requests.
357 The default is C<10809>.  See also I<-i>.
359 =item B<-r>
361 =item B<--read-only>
363 =item B<--readonly>
365 The export will be read-only.  If a client writes, then it will get an
366 error.
368 Note that some plugins inherently don't support writes.  With those
369 plugins the I<-r> option is added implicitly.
371 L<nbdkit-cow-filter(1)> can be placed over read-only plugins to
372 provide copy-on-write (or "snapshot") functionality.  If you are using
373 qemu as a client then it also supports snapshots.
375 =item B<--run> 'COMMAND ARGS ...'
377 Run nbdkit as a captive subprocess of the command.  When the command
378 exits, nbdkit is killed.  See L<nbdkit-captive(1)/CAPTIVE NBDKIT>.
380 Note that the command is executed by F</bin/sh>.  On some platforms
381 like Debian this might not be a full-featured shell.
383 This option implies I<--foreground>.
385 =item B<--selinux-label=>SOCKET-LABEL
387 Apply the SELinux label C<SOCKET-LABEL> to the nbdkit listening
388 socket.
390 The common — perhaps only — use of this option is to allow libvirt
391 guests which are using SELinux and sVirt confinement to access nbdkit
392 Unix domain sockets.  The example below shows how to do this.  Note
393 that the socket and filesystem labels are different.
395  nbdkit -U /tmp/sock --selinux-label=system_u:object_r:svirt_socket_t:s0 ...
396  chcon system_u:object_r:svirt_image_t:s0 /tmp/sock
398 =item B<-s>
400 =item B<--single>
402 =item B<--stdin>
404 Don't fork.  Handle a single NBD connection on stdin/stdout.  After
405 stdin closes, the server exits.
407 You can use this option to run nbdkit from inetd or similar
408 superservers; or just for testing; or if you want to run nbdkit in a
409 non-conventional way.  Note that if you want to run nbdkit from
410 systemd, then it may be better to use
411 L<nbdkit-service(1)/SOCKET ACTIVATION> instead of this option.
413 This option implies I<--foreground>.
415 =item B<--swap>
417 (nbdkit E<ge> 1.18)
419 Specifies that the NBD device will be used as swap space loop mounted
420 on the same machine which is running nbdkit.  To avoid deadlocks this
421 locks the whole nbdkit process into memory using L<mlockall(2)>.  This
422 may require additional permissions, such as starting the server as
423 root or raising the C<RLIMIT_MEMLOCK> (L<ulimit(1)> I<-l>) limit on
424 the process.
426 =item B<-t> THREADS
428 =item B<--threads=>THREADS
430 Set the number of threads to be used per connection, which in turn
431 controls the number of outstanding requests that can be processed at
432 once.  Only matters for plugins with thread_model=parallel (where it
433 defaults to 16).  To force serialized behavior (useful if the client
434 is not prepared for out-of-order responses), set this to 1.
436 =item B<--tls=off>
438 =item B<--tls=on>
440 =item B<--tls=require>
442 Disable, enable or require TLS (authentication and encryption
443 support).  See L<nbdkit-tls(1)>.
445 =item B<--tls-certificates=>/path/to/certificates
447 Set the path to the TLS certificates directory.  If not specified,
448 some built-in paths are checked.  See L<nbdkit-tls(1)> for more
449 details.
451 =item B<--tls-psk=>/path/to/pskfile
453 Set the path to the pre-shared keys (PSK) file.  If used, this
454 overrides certificate authentication.  There is no built-in path.  See
455 L<nbdkit-tls(1)> for more details.
457 =item B<--tls-verify-peer>
459 Enables TLS client certificate verification.  The default is I<not> to
460 check the client's certificate.
462 =item B<-U> SOCKET
464 =item B<--unix=>SOCKET
466 =item B<-U ->
468 =item B<--unix ->
470 Accept connections on the Unix domain socket C<SOCKET> (which is a
471 path).
473 nbdkit creates this socket, but it will probably have incorrect
474 permissions (too permissive).  If it is a problem that some
475 unauthorized user could connect to this socket between the time that
476 nbdkit starts up and the authorized user connects, then put the socket
477 into a directory that has restrictive permissions.
479 nbdkit does B<not> delete the socket file when it exits.  The caller
480 should delete the socket file after use (else if you try to start
481 nbdkit up again you will get an C<Address already in use> error).
483 If the socket name is I<-> then nbdkit generates a randomly named
484 private socket.  This is useful with L<nbdkit-captive(1)/CAPTIVE NBDKIT>.
486 =item B<-u> USER
488 =item B<--user=>USER
490 Change user to C<USER> after starting up.  A user name or numeric user
491 ID can be used.
493 The server needs sufficient permissions to be able to do this.
494 Normally this would mean starting the server up as root.
496 See also I<-g>.
498 =item B<-v>
500 =item B<--verbose>
502 Enable verbose messages.
504 It's a good idea to use I<-f> as well so the process does not fork
505 into the background (but not required).
507 =item B<-V>
509 =item B<--version>
511 Print the version number of nbdkit and exit.
513 The I<--dump-config> option provides separate major and minor numbers
514 and may be easier to parse from shell scripts.
516 =item B<--vsock>
518 (nbdkit E<ge> 1.16)
520 Use the AF_VSOCK protocol (instead of TCP/IP).  You must use this in
521 conjunction with I<-p>/I<--port>.  See L<nbdkit-service(1)/AF_VSOCK>.
523 =back
525 =head1 PLUGIN NAME
527 You can give the full path to the plugin, like this:
529  nbdkit $libdir/nbdkit/plugins/nbdkit-file-plugin.so [...]
531 but it is usually more convenient to use this equivalent syntax:
533  nbdkit file [...]
535 C<$libdir> is set at compile time.  To print it out, do:
537  nbdkit --dump-config
539 =head1 PLUGIN CONFIGURATION
541 After specifying the plugin name you can (optionally, it depends
542 on the plugin) give plugin configuration on the command line in
543 the form of C<key=value>.  For example:
545  nbdkit file file=disk.img
547 To list all the options supported by a plugin, do:
549  nbdkit --help file
551 To dump information about a plugin, do:
553  nbdkit file --dump-plugin
555 =head2 Magic parameters
557 Some plugins declare a special "magic config key".  This is a key
558 which is assumed if no C<key=> part is present.  For example:
560  nbdkit file disk.img
562 is assumed to be C<file=disk.img> because the file plugin declares
563 C<file> as its magic config key.  There can be ambiguity in the
564 parsing of magic config keys if the value might look like a
565 C<key=value>.  If there could be ambiguity then modify the value,
566 eg. by prefixing it with C<./>
568 There is also a special exception for plugins which do not declare a
569 magic config key, but where the first plugin argument does not contain
570 an C<'='> character: it is assumed to be C<script=value>.  This is
571 used by scripting language plugins:
573  nbdkit perl foo.pl [args...]
575 has the same meaning as:
577  nbdkit perl script=foo.pl [args...]
579 =head2 Shebang scripts
581 You can use C<#!> to run nbdkit plugins written in most scripting
582 languages.  The file should be executable.  For example:
584  #!/usr/sbin/nbdkit perl
585  sub open {
586    # etc
589 (see L<nbdkit-perl-plugin(3)> for a full example).
591 =head1 SERVER DEBUG FLAGS
593 As well as enabling or disabling debugging in the server using
594 I<--verbose> you can control extra debugging in the server using the
595 S<I<-D nbdkit.*>> flags listed in this section.  Note these flags are
596 an internal implementation detail of the server and may be changed or
597 removed at any time in the future.
599 =over 4
601 =item B<-D nbdkit.backend.controlpath=0>
603 =item B<-D nbdkit.backend.controlpath=1>
605 =item B<-D nbdkit.backend.datapath=0>
607 =item B<-D nbdkit.backend.datapath=1>
609 These flags control the verbosity of nbdkit backend debugging messages
610 (the ones which show every request processed by the server).  The
611 default for both settings is C<1> (normal debugging) but you can set
612 them to C<0> to suppress these messages.
614 S<I<-D nbdkit.backend.datapath=0>> is the more useful setting which
615 lets you suppress messages about pread, pwrite, zero, trim,
616 etc. commands.  When transferring large amounts of data these messages
617 are numerous and not usually very interesting.
619 S<I<-D nbdkit.backend.controlpath=0>> suppresses the non-datapath
620 commands (config, open, close, can_write, etc.)
622 =item B<-D nbdkit.tls.log=>N
624 Enable TLS logging.  C<N> can be in the range 0 (no logging) to 99.
625 See L<gnutls_global_set_log_level(3)>.
627 =item B<-D nbdkit.tls.session=1>
629 Print additional information about the TLS session, such as the type
630 of authentication and encryption, and client certificate information.
632 =back
634 =head1 SIGNALS
636 nbdkit responds to the following signals:
638 =over 4
640 =item C<SIGINT>
642 =item C<SIGQUIT>
644 =item C<SIGTERM>
646 The server exits cleanly.
648 =item C<SIGPIPE>
650 This signal is ignored.
652 =back
654 =head1 ENVIRONMENT VARIABLES
656 =over 4
658 =item C<LISTEN_FDS>
660 =item C<LISTEN_PID>
662 If present in the environment when nbdkit starts up, these trigger
663 L<nbdkit-service(1)/SOCKET ACTIVATION>.
665 =back
667 =head1 SEE ALSO
669 =head2 Other topics
671 L<nbdkit-captive(1)> — Run nbdkit under another process and have it
672 reliably cleaned up.
674 L<nbdkit-client(1)> — How to mount NBD filesystems on a client machine.
676 L<nbdkit-loop(1)> — Use nbdkit with the Linux kernel client to create
677 loop devices and loop mounts.
679 L<nbdkit-probing(1)> — How to probe for nbdkit configuration and plugins.
681 L<nbdkit-protocol(1)> — Which parts of the NBD protocol nbdkit supports.
683 L<nbdkit-security(1)> — Lists past security issues in nbdkit.
685 L<nbdkit-service(1)> — Running nbdkit as a service, and systemd socket
686 activation.
688 L<nbdkit-tls(1)> — Authentication and encryption of NBD connections
689 (sometimes incorrectly called "SSL").
691 =head2 Plugins
693 __PLUGIN_LINKS__.
695 =head2 Filters
697 __FILTER_LINKS__.
699 =head2 For developers
701 L<nbdkit-plugin(3)>,
702 L<nbdkit-filter(3)>.
704 =head2 Writing plugins in other programming languages
706 __LANG_PLUGIN_LINKS__.
708 =head2 Release notes for previous releases of nbdkit
710 L<nbdkit-release-notes-1.32(1)>,
711 L<nbdkit-release-notes-1.30(1)>,
712 L<nbdkit-release-notes-1.28(1)>,
713 L<nbdkit-release-notes-1.26(1)>,
714 L<nbdkit-release-notes-1.24(1)>,
715 L<nbdkit-release-notes-1.22(1)>,
716 L<nbdkit-release-notes-1.20(1)>,
717 L<nbdkit-release-notes-1.18(1)>,
718 L<nbdkit-release-notes-1.16(1)>,
719 L<nbdkit-release-notes-1.14(1)>,
720 L<nbdkit-release-notes-1.12(1)>,
721 L<nbdkit-release-notes-1.10(1)>,
722 L<nbdkit-release-notes-1.8(1)>,
723 L<nbdkit-release-notes-1.6(1)>,
724 L<nbdkit-release-notes-1.4(1)>.
726 =head2 NBD clients
728 L<guestfish(1)>,
729 L<libnbd(3)>,
730 L<nbd-client(1)>,
731 L<nbdcopy(1)>,
732 L<nbdfuse(1)>,
733 L<nbdinfo(1)>,
734 L<nbdsh(1)>,
735 L<qemu(1)>.
737 =head2 nbdkit links
739 L<http://gitlab.com/nbdkit/nbdkit> — Source code.
741 =head2 Other NBD servers
743 L<qemu-nbd(1)>,
744 L<nbd-server(1)>,
745 L<https://bitbucket.org/hirofuchi/xnbd>.
747 =head2 Documentation for the NBD protocol
749 L<https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md>,
750 L<https://nbd.sourceforge.io/>.
752 =head2 Similar protocols
754 L<https://en.wikipedia.org/wiki/iSCSI>,
755 L<https://en.wikipedia.org/wiki/ATA_over_Ethernet>,
756 L<https://en.wikipedia.org/wiki/Fibre_Channel_over_Ethernet>.
758 =head2 Other manual pages of interest
760 L<gnutls_priority_init(3)>,
761 L<qemu-img(1)>,
762 L<psktool(1)>,
763 L<systemd.socket(5)>.
765 =head1 AUTHORS
767 Eric Blake
769 Laszlo Ersek
771 Richard W.M. Jones
773 Yann E. MORIN
775 Nikolaus Rath
777 François Revol
779 Nir Soffer
781 Alan Somers
783 Pino Toscano
785 =head1 COPYRIGHT
787 Copyright (C) 2013-2020 Red Hat Inc.