xref: /qemu/docs/tools/qemu-nbd.rst (revision a4340e7c522e3f20abeac061a5a8b319f715c1d0)
1*a4340e7cSPierrick Bouvier.. _qemu-nbd:
2*a4340e7cSPierrick Bouvier
38a1f7d29SPaolo Bonzini=====================================
487c0868fSPeter MaydellQEMU Disk Network Block Device Server
587c0868fSPeter Maydell=====================================
687c0868fSPeter Maydell
787c0868fSPeter MaydellSynopsis
887c0868fSPeter Maydell--------
987c0868fSPeter Maydell
1087c0868fSPeter Maydell**qemu-nbd** [*OPTION*]... *filename*
1187c0868fSPeter Maydell
1287c0868fSPeter Maydell**qemu-nbd** -L [*OPTION*]...
1387c0868fSPeter Maydell
1487c0868fSPeter Maydell**qemu-nbd** -d *dev*
1587c0868fSPeter Maydell
1687c0868fSPeter MaydellDescription
1787c0868fSPeter Maydell-----------
1887c0868fSPeter Maydell
1987c0868fSPeter MaydellExport a QEMU disk image using the NBD protocol.
2087c0868fSPeter Maydell
2187c0868fSPeter MaydellOther uses:
2287c0868fSPeter Maydell
2387c0868fSPeter Maydell- Bind a /dev/nbdX block device to a QEMU server (on Linux).
2487c0868fSPeter Maydell- As a client to query exports of a remote NBD server.
2587c0868fSPeter Maydell
2687c0868fSPeter MaydellOptions
2787c0868fSPeter Maydell-------
2887c0868fSPeter Maydell
2987c0868fSPeter Maydell.. program:: qemu-nbd
3087c0868fSPeter Maydell
3187c0868fSPeter Maydell*filename* is a disk image filename, or a set of block
32a2c2d44aSEric Blakedriver options if :option:`--image-opts` is specified.
3387c0868fSPeter Maydell
3487c0868fSPeter Maydell*dev* is an NBD device.
3587c0868fSPeter Maydell
368f75cae2SRao, Lei.. option:: --object type,id=ID,...
3787c0868fSPeter Maydell
3887c0868fSPeter Maydell  Define a new instance of the *type* object class identified by *ID*.
3987c0868fSPeter Maydell  See the :manpage:`qemu(1)` manual page for full details of the properties
4087c0868fSPeter Maydell  supported. The common object types that it makes sense to define are the
4187c0868fSPeter Maydell  ``secret`` object, which is used to supply passwords and/or encryption
4287c0868fSPeter Maydell  keys, and the ``tls-creds`` object, which is used to supply TLS
43c5ba6219SPhilippe Mathieu-Daudé  credentials for the ``qemu-nbd`` server or client.
4487c0868fSPeter Maydell
4587c0868fSPeter Maydell.. option:: -p, --port=PORT
4687c0868fSPeter Maydell
4787c0868fSPeter Maydell  TCP port to listen on as a server, or connect to as a client
4887c0868fSPeter Maydell  (default ``10809``).
4987c0868fSPeter Maydell
5087c0868fSPeter Maydell.. option:: -o, --offset=OFFSET
5187c0868fSPeter Maydell
5287c0868fSPeter Maydell  The offset into the image.
5387c0868fSPeter Maydell
5487c0868fSPeter Maydell.. option:: -b, --bind=IFACE
5587c0868fSPeter Maydell
5687c0868fSPeter Maydell  The interface to bind to as a server, or connect to as a client
5787c0868fSPeter Maydell  (default ``0.0.0.0``).
5887c0868fSPeter Maydell
5987c0868fSPeter Maydell.. option:: -k, --socket=PATH
6087c0868fSPeter Maydell
6187c0868fSPeter Maydell  Use a unix socket with path *PATH*.
6287c0868fSPeter Maydell
6387c0868fSPeter Maydell.. option:: --image-opts
6487c0868fSPeter Maydell
6587c0868fSPeter Maydell  Treat *filename* as a set of image options, instead of a plain
6687c0868fSPeter Maydell  filename. If this flag is specified, the ``-f`` flag should
6787c0868fSPeter Maydell  not be used, instead the :option:`format=` option should be set.
6887c0868fSPeter Maydell
6987c0868fSPeter Maydell.. option:: -f, --format=FMT
7087c0868fSPeter Maydell
7187c0868fSPeter Maydell  Force the use of the block driver for format *FMT* instead of
7287c0868fSPeter Maydell  auto-detecting.
7387c0868fSPeter Maydell
7487c0868fSPeter Maydell.. option:: -r, --read-only
7587c0868fSPeter Maydell
7687c0868fSPeter Maydell  Export the disk as read-only.
7787c0868fSPeter Maydell
78dbc7b014SEric Blake.. option:: -A, --allocation-depth
79dbc7b014SEric Blake
80dbc7b014SEric Blake  Expose allocation depth information via the
81dbc7b014SEric Blake  ``qemu:allocation-depth`` metadata context accessible through
82dbc7b014SEric Blake  NBD_OPT_SET_META_CONTEXT.
83dbc7b014SEric Blake
8487c0868fSPeter Maydell.. option:: -B, --bitmap=NAME
8587c0868fSPeter Maydell
8687c0868fSPeter Maydell  If *filename* has a qcow2 persistent bitmap *NAME*, expose
87dbc7b014SEric Blake  that bitmap via the ``qemu:dirty-bitmap:NAME`` metadata context
8887c0868fSPeter Maydell  accessible through NBD_OPT_SET_META_CONTEXT.
8987c0868fSPeter Maydell
9087c0868fSPeter Maydell.. option:: -s, --snapshot
9187c0868fSPeter Maydell
9287c0868fSPeter Maydell  Use *filename* as an external snapshot, create a temporary
9387c0868fSPeter Maydell  file with ``backing_file=``\ *filename*, redirect the write to
9487c0868fSPeter Maydell  the temporary one.
9587c0868fSPeter Maydell
9687c0868fSPeter Maydell.. option:: -l, --load-snapshot=SNAPSHOT_PARAM
9787c0868fSPeter Maydell
9887c0868fSPeter Maydell  Load an internal snapshot inside *filename* and export it
9987c0868fSPeter Maydell  as an read-only device, SNAPSHOT_PARAM format is
10087c0868fSPeter Maydell  ``snapshot.id=[ID],snapshot.name=[NAME]`` or ``[ID_OR_NAME]``
10187c0868fSPeter Maydell
10287c0868fSPeter Maydell.. option:: --cache=CACHE
10387c0868fSPeter Maydell
10409615257SNir Soffer  The cache mode to be used with the file. Valid values are:
10509615257SNir Soffer  ``none``, ``writeback`` (the default), ``writethrough``,
10609615257SNir Soffer  ``directsync`` and ``unsafe``. See the documentation of
10709615257SNir Soffer  the emulator's ``-drive cache=...`` option for more info.
10887c0868fSPeter Maydell
10987c0868fSPeter Maydell.. option:: -n, --nocache
11087c0868fSPeter Maydell
11187c0868fSPeter Maydell  Equivalent to :option:`--cache=none`.
11287c0868fSPeter Maydell
11387c0868fSPeter Maydell.. option:: --aio=AIO
11487c0868fSPeter Maydell
1157680274dSAarushi Mehta  Set the asynchronous I/O mode between ``threads`` (the default),
1167680274dSAarushi Mehta  ``native`` (Linux only), and ``io_uring`` (Linux 5.1+).
11787c0868fSPeter Maydell
11887c0868fSPeter Maydell.. option:: --discard=DISCARD
11987c0868fSPeter Maydell
12087c0868fSPeter Maydell  Control whether ``discard`` (also known as ``trim`` or ``unmap``)
12187c0868fSPeter Maydell  requests are ignored or passed to the filesystem. *DISCARD* is one of
12287c0868fSPeter Maydell  ``ignore`` (or ``off``), ``unmap`` (or ``on``).  The default is
12387c0868fSPeter Maydell  ``ignore``.
12487c0868fSPeter Maydell
12587c0868fSPeter Maydell.. option:: --detect-zeroes=DETECT_ZEROES
12687c0868fSPeter Maydell
12787c0868fSPeter Maydell  Control the automatic conversion of plain zero writes by the OS to
12887c0868fSPeter Maydell  driver-specific optimized zero write commands.  *DETECT_ZEROES* is one of
12987c0868fSPeter Maydell  ``off``, ``on``, or ``unmap``.  ``unmap``
13087c0868fSPeter Maydell  converts a zero write to an unmap operation and can only be used if
13187c0868fSPeter Maydell  *DISCARD* is set to ``unmap``.  The default is ``off``.
13287c0868fSPeter Maydell
13387c0868fSPeter Maydell.. option:: -c, --connect=DEV
13487c0868fSPeter Maydell
13587c0868fSPeter Maydell  Connect *filename* to NBD device *DEV* (Linux only).
13687c0868fSPeter Maydell
13787c0868fSPeter Maydell.. option:: -d, --disconnect
13887c0868fSPeter Maydell
13987c0868fSPeter Maydell  Disconnect the device *DEV* (Linux only).
14087c0868fSPeter Maydell
14187c0868fSPeter Maydell.. option:: -e, --shared=NUM
14287c0868fSPeter Maydell
14387c0868fSPeter Maydell  Allow up to *NUM* clients to share the device (default
14458a6fdccSEric Blake  ``1``), 0 for unlimited.
14587c0868fSPeter Maydell
14687c0868fSPeter Maydell.. option:: -t, --persistent
14787c0868fSPeter Maydell
14887c0868fSPeter Maydell  Don't exit on the last connection.
14987c0868fSPeter Maydell
15087c0868fSPeter Maydell.. option:: -x, --export-name=NAME
15187c0868fSPeter Maydell
15287c0868fSPeter Maydell  Set the NBD volume export name (default of a zero-length string).
15387c0868fSPeter Maydell
15487c0868fSPeter Maydell.. option:: -D, --description=DESCRIPTION
15587c0868fSPeter Maydell
15687c0868fSPeter Maydell  Set the NBD volume export description, as a human-readable
15787c0868fSPeter Maydell  string.
15887c0868fSPeter Maydell
15987c0868fSPeter Maydell.. option:: -L, --list
16087c0868fSPeter Maydell
16187c0868fSPeter Maydell  Connect as a client and list all details about the exports exposed by
16287c0868fSPeter Maydell  a remote NBD server.  This enables list mode, and is incompatible
16387c0868fSPeter Maydell  with options that change behavior related to a specific export (such as
16487c0868fSPeter Maydell  :option:`--export-name`, :option:`--offset`, ...).
16587c0868fSPeter Maydell
16687c0868fSPeter Maydell.. option:: --tls-creds=ID
16787c0868fSPeter Maydell
16887c0868fSPeter Maydell  Enable mandatory TLS encryption for the server by setting the ID
169a2c2d44aSEric Blake  of the TLS credentials object previously created with the
170a2c2d44aSEric Blake  :option:`--object` option; or provide the credentials needed for
171a2c2d44aSEric Blake  connecting as a client in list mode.
17287c0868fSPeter Maydell
173003b2b25SDaniel P. Berrangé.. option:: --tls-hostname=hostname
174003b2b25SDaniel P. Berrangé
175003b2b25SDaniel P. Berrangé  When validating an x509 certificate received over a TLS connection,
176003b2b25SDaniel P. Berrangé  the hostname that the NBD client used to connect will be checked
177003b2b25SDaniel P. Berrangé  against information in the server provided certificate. Sometimes
178003b2b25SDaniel P. Berrangé  it might be required to override the hostname used to perform this
179003b2b25SDaniel P. Berrangé  check. For example, if the NBD client is using a tunnel from localhost
180a2c2d44aSEric Blake  to connect to the remote server, the :option:`--tls-hostname` option should
181003b2b25SDaniel P. Berrangé  be used to set the officially expected hostname of the remote NBD
182003b2b25SDaniel P. Berrangé  server. This can also be used if accessing NBD over a UNIX socket
183003b2b25SDaniel P. Berrangé  where there is no inherent hostname available. This is only permitted
184a2c2d44aSEric Blake  when acting as a NBD client with the :option:`--list` option.
185003b2b25SDaniel P. Berrangé
18687c0868fSPeter Maydell.. option:: --fork
18787c0868fSPeter Maydell
18887c0868fSPeter Maydell  Fork off the server process and exit the parent once the server is running.
18987c0868fSPeter Maydell
19087c0868fSPeter Maydell.. option:: --pid-file=PATH
19187c0868fSPeter Maydell
19287c0868fSPeter Maydell  Store the server's process ID in the given file.
19387c0868fSPeter Maydell
19487c0868fSPeter Maydell.. option:: --tls-authz=ID
19587c0868fSPeter Maydell
19687c0868fSPeter Maydell  Specify the ID of a qauthz object previously created with the
19787c0868fSPeter Maydell  :option:`--object` option. This will be used to authorize connecting users
19887c0868fSPeter Maydell  against their x509 distinguished name.
19987c0868fSPeter Maydell
20087c0868fSPeter Maydell.. option:: -v, --verbose
20187c0868fSPeter Maydell
20235e087deSDenis V. Lunev  Display extra debugging information. This option also keeps the original
20335e087deSDenis V. Lunev  *STDERR* stream open if the ``qemu-nbd`` process is daemonized due to
20435e087deSDenis V. Lunev  other options like :option:`--fork` or :option:`-c`.
20587c0868fSPeter Maydell
20687c0868fSPeter Maydell.. option:: -h, --help
20787c0868fSPeter Maydell
20887c0868fSPeter Maydell  Display this help and exit.
20987c0868fSPeter Maydell
21087c0868fSPeter Maydell.. option:: -V, --version
21187c0868fSPeter Maydell
21287c0868fSPeter Maydell  Display version information and exit.
21387c0868fSPeter Maydell
21487c0868fSPeter Maydell.. option:: -T, --trace [[enable=]PATTERN][,events=FILE][,file=FILE]
21587c0868fSPeter Maydell
216bb43ee6cSPeter Maydell  .. include:: ../qemu-option-trace.rst.inc
21787c0868fSPeter Maydell
21887c0868fSPeter MaydellExamples
21987c0868fSPeter Maydell--------
22087c0868fSPeter Maydell
22187c0868fSPeter MaydellStart a server listening on port 10809 that exposes only the
22287c0868fSPeter Maydellguest-visible contents of a qcow2 file, with no TLS encryption, and
22387c0868fSPeter Maydellwith the default export name (an empty string). The command is
22487c0868fSPeter Maydellone-shot, and will block until the first successful client
22587c0868fSPeter Maydelldisconnects:
22687c0868fSPeter Maydell
22787c0868fSPeter Maydell::
22887c0868fSPeter Maydell
22987c0868fSPeter Maydell  qemu-nbd -f qcow2 file.qcow2
23087c0868fSPeter Maydell
23187c0868fSPeter MaydellStart a long-running server listening with encryption on port 10810,
2322d2e4843SThomas Huthand allow clients with a specific X.509 certificate to connect to
23387c0868fSPeter Maydella 1 megabyte subset of a raw file, using the export name 'subset':
23487c0868fSPeter Maydell
23587c0868fSPeter Maydell::
23687c0868fSPeter Maydell
23787c0868fSPeter Maydell  qemu-nbd \
23887c0868fSPeter Maydell    --object tls-creds-x509,id=tls0,endpoint=server,dir=/path/to/qemutls \
23987c0868fSPeter Maydell    --object 'authz-simple,id=auth0,identity=CN=laptop.example.com,,\
24087c0868fSPeter Maydell              O=Example Org,,L=London,,ST=London,,C=GB' \
24187c0868fSPeter Maydell    --tls-creds tls0 --tls-authz auth0 \
24287c0868fSPeter Maydell    -t -x subset -p 10810 \
24387c0868fSPeter Maydell    --image-opts driver=raw,offset=1M,size=1M,file.driver=file,file.filename=file.raw
24487c0868fSPeter Maydell
2450bc16997SEric BlakeServe a read-only copy of a guest image over a Unix socket with as
2460bc16997SEric Blakemany as 5 simultaneous readers, with a persistent process forked as a
2470bc16997SEric Blakedaemon:
24887c0868fSPeter Maydell
24987c0868fSPeter Maydell::
25087c0868fSPeter Maydell
25187c0868fSPeter Maydell  qemu-nbd --fork --persistent --shared=5 --socket=/path/to/sock \
2520bc16997SEric Blake    --read-only --format=qcow2 file.qcow2
25387c0868fSPeter Maydell
25487c0868fSPeter MaydellExpose the guest-visible contents of a qcow2 file via a block device
25587c0868fSPeter Maydell/dev/nbd0 (and possibly creating /dev/nbd0p1 and friends for
25687c0868fSPeter Maydellpartitions found within), then disconnect the device when done.
257c5ba6219SPhilippe Mathieu-DaudéAccess to bind ``qemu-nbd`` to a /dev/nbd device generally requires root
25887c0868fSPeter Maydellprivileges, and may also require the execution of ``modprobe nbd``
25987c0868fSPeter Maydellto enable the kernel NBD client module.  *CAUTION*: Do not use
26087c0868fSPeter Maydellthis method to mount filesystems from an untrusted guest image - a
26187c0868fSPeter Maydellmalicious guest may have prepared the image to attempt to trigger
26287c0868fSPeter Maydellkernel bugs in partition probing or file system mounting.
26387c0868fSPeter Maydell
26487c0868fSPeter Maydell::
26587c0868fSPeter Maydell
26687c0868fSPeter Maydell  qemu-nbd -c /dev/nbd0 -f qcow2 file.qcow2
26787c0868fSPeter Maydell  qemu-nbd -d /dev/nbd0
26887c0868fSPeter Maydell
26987c0868fSPeter MaydellQuery a remote server to see details about what export(s) it is
27087c0868fSPeter Maydellserving on port 10809, and authenticating via PSK:
27187c0868fSPeter Maydell
27287c0868fSPeter Maydell::
27387c0868fSPeter Maydell
27487c0868fSPeter Maydell  qemu-nbd \
27587c0868fSPeter Maydell    --object tls-creds-psk,id=tls0,dir=/tmp/keys,username=eblake,endpoint=client \
27687c0868fSPeter Maydell    --tls-creds tls0 -L -b remote.example.com
27787c0868fSPeter Maydell
27887c0868fSPeter MaydellSee also
27987c0868fSPeter Maydell--------
28087c0868fSPeter Maydell
28187c0868fSPeter Maydell:manpage:`qemu(1)`, :manpage:`qemu-img(1)`
282