18a1f7d29SPaolo Bonzini===================================== 2a08b4a9fSPeter MaydellQEMU Disk Network Block Device Server 3a08b4a9fSPeter Maydell===================================== 4a08b4a9fSPeter Maydell 5a08b4a9fSPeter MaydellSynopsis 6a08b4a9fSPeter Maydell-------- 7a08b4a9fSPeter Maydell 8a08b4a9fSPeter Maydell**qemu-nbd** [*OPTION*]... *filename* 9a08b4a9fSPeter Maydell 10a08b4a9fSPeter Maydell**qemu-nbd** -L [*OPTION*]... 11a08b4a9fSPeter Maydell 12a08b4a9fSPeter Maydell**qemu-nbd** -d *dev* 13a08b4a9fSPeter Maydell 14a08b4a9fSPeter MaydellDescription 15a08b4a9fSPeter Maydell----------- 16a08b4a9fSPeter Maydell 17a08b4a9fSPeter MaydellExport a QEMU disk image using the NBD protocol. 18a08b4a9fSPeter Maydell 19a08b4a9fSPeter MaydellOther uses: 20a08b4a9fSPeter Maydell 21a08b4a9fSPeter Maydell- Bind a /dev/nbdX block device to a QEMU server (on Linux). 22a08b4a9fSPeter Maydell- As a client to query exports of a remote NBD server. 23a08b4a9fSPeter Maydell 24a08b4a9fSPeter MaydellOptions 25a08b4a9fSPeter Maydell------- 26a08b4a9fSPeter Maydell 27a08b4a9fSPeter Maydell.. program:: qemu-nbd 28a08b4a9fSPeter Maydell 29a08b4a9fSPeter Maydell*filename* is a disk image filename, or a set of block 30a2c2d44aSEric Blakedriver options if :option:`--image-opts` is specified. 31a08b4a9fSPeter Maydell 32a08b4a9fSPeter Maydell*dev* is an NBD device. 33a08b4a9fSPeter Maydell 348f75cae2SRao, Lei.. option:: --object type,id=ID,... 35a08b4a9fSPeter Maydell 36a08b4a9fSPeter Maydell Define a new instance of the *type* object class identified by *ID*. 37a08b4a9fSPeter Maydell See the :manpage:`qemu(1)` manual page for full details of the properties 38a08b4a9fSPeter Maydell supported. The common object types that it makes sense to define are the 39a08b4a9fSPeter Maydell ``secret`` object, which is used to supply passwords and/or encryption 40a08b4a9fSPeter Maydell keys, and the ``tls-creds`` object, which is used to supply TLS 41c5ba6219SPhilippe Mathieu-Daudé credentials for the ``qemu-nbd`` server or client. 42a08b4a9fSPeter Maydell 43a08b4a9fSPeter Maydell.. option:: -p, --port=PORT 44a08b4a9fSPeter Maydell 45a08b4a9fSPeter Maydell TCP port to listen on as a server, or connect to as a client 46a08b4a9fSPeter Maydell (default ``10809``). 47a08b4a9fSPeter Maydell 48a08b4a9fSPeter Maydell.. option:: -o, --offset=OFFSET 49a08b4a9fSPeter Maydell 50a08b4a9fSPeter Maydell The offset into the image. 51a08b4a9fSPeter Maydell 52a08b4a9fSPeter Maydell.. option:: -b, --bind=IFACE 53a08b4a9fSPeter Maydell 54a08b4a9fSPeter Maydell The interface to bind to as a server, or connect to as a client 55a08b4a9fSPeter Maydell (default ``0.0.0.0``). 56a08b4a9fSPeter Maydell 57a08b4a9fSPeter Maydell.. option:: -k, --socket=PATH 58a08b4a9fSPeter Maydell 59a08b4a9fSPeter Maydell Use a unix socket with path *PATH*. 60a08b4a9fSPeter Maydell 61a08b4a9fSPeter Maydell.. option:: --image-opts 62a08b4a9fSPeter Maydell 63a08b4a9fSPeter Maydell Treat *filename* as a set of image options, instead of a plain 64a08b4a9fSPeter Maydell filename. If this flag is specified, the ``-f`` flag should 65a08b4a9fSPeter Maydell not be used, instead the :option:`format=` option should be set. 66a08b4a9fSPeter Maydell 67a08b4a9fSPeter Maydell.. option:: -f, --format=FMT 68a08b4a9fSPeter Maydell 69a08b4a9fSPeter Maydell Force the use of the block driver for format *FMT* instead of 70a08b4a9fSPeter Maydell auto-detecting. 71a08b4a9fSPeter Maydell 72a08b4a9fSPeter Maydell.. option:: -r, --read-only 73a08b4a9fSPeter Maydell 74a08b4a9fSPeter Maydell Export the disk as read-only. 75a08b4a9fSPeter Maydell 76dbc7b014SEric Blake.. option:: -A, --allocation-depth 77dbc7b014SEric Blake 78dbc7b014SEric Blake Expose allocation depth information via the 79dbc7b014SEric Blake ``qemu:allocation-depth`` metadata context accessible through 80dbc7b014SEric Blake NBD_OPT_SET_META_CONTEXT. 81dbc7b014SEric Blake 82a08b4a9fSPeter Maydell.. option:: -B, --bitmap=NAME 83a08b4a9fSPeter Maydell 84a08b4a9fSPeter Maydell If *filename* has a qcow2 persistent bitmap *NAME*, expose 85dbc7b014SEric Blake that bitmap via the ``qemu:dirty-bitmap:NAME`` metadata context 86a08b4a9fSPeter Maydell accessible through NBD_OPT_SET_META_CONTEXT. 87a08b4a9fSPeter Maydell 88a08b4a9fSPeter Maydell.. option:: -s, --snapshot 89a08b4a9fSPeter Maydell 90a08b4a9fSPeter Maydell Use *filename* as an external snapshot, create a temporary 91a08b4a9fSPeter Maydell file with ``backing_file=``\ *filename*, redirect the write to 92a08b4a9fSPeter Maydell the temporary one. 93a08b4a9fSPeter Maydell 94a08b4a9fSPeter Maydell.. option:: -l, --load-snapshot=SNAPSHOT_PARAM 95a08b4a9fSPeter Maydell 96a08b4a9fSPeter Maydell Load an internal snapshot inside *filename* and export it 97a08b4a9fSPeter Maydell as an read-only device, SNAPSHOT_PARAM format is 98a08b4a9fSPeter Maydell ``snapshot.id=[ID],snapshot.name=[NAME]`` or ``[ID_OR_NAME]`` 99a08b4a9fSPeter Maydell 100a08b4a9fSPeter Maydell.. option:: --cache=CACHE 101a08b4a9fSPeter Maydell 10209615257SNir Soffer The cache mode to be used with the file. Valid values are: 10309615257SNir Soffer ``none``, ``writeback`` (the default), ``writethrough``, 10409615257SNir Soffer ``directsync`` and ``unsafe``. See the documentation of 10509615257SNir Soffer the emulator's ``-drive cache=...`` option for more info. 106a08b4a9fSPeter Maydell 107a08b4a9fSPeter Maydell.. option:: -n, --nocache 108a08b4a9fSPeter Maydell 109a08b4a9fSPeter Maydell Equivalent to :option:`--cache=none`. 110a08b4a9fSPeter Maydell 111a08b4a9fSPeter Maydell.. option:: --aio=AIO 112a08b4a9fSPeter Maydell 113a08b4a9fSPeter Maydell Set the asynchronous I/O mode between ``threads`` (the default), 114a08b4a9fSPeter Maydell ``native`` (Linux only), and ``io_uring`` (Linux 5.1+). 115a08b4a9fSPeter Maydell 116a08b4a9fSPeter Maydell.. option:: --discard=DISCARD 117a08b4a9fSPeter Maydell 118a08b4a9fSPeter Maydell Control whether ``discard`` (also known as ``trim`` or ``unmap``) 119a08b4a9fSPeter Maydell requests are ignored or passed to the filesystem. *DISCARD* is one of 120a08b4a9fSPeter Maydell ``ignore`` (or ``off``), ``unmap`` (or ``on``). The default is 121a08b4a9fSPeter Maydell ``ignore``. 122a08b4a9fSPeter Maydell 123a08b4a9fSPeter Maydell.. option:: --detect-zeroes=DETECT_ZEROES 124a08b4a9fSPeter Maydell 125a08b4a9fSPeter Maydell Control the automatic conversion of plain zero writes by the OS to 126a08b4a9fSPeter Maydell driver-specific optimized zero write commands. *DETECT_ZEROES* is one of 127a08b4a9fSPeter Maydell ``off``, ``on``, or ``unmap``. ``unmap`` 128a08b4a9fSPeter Maydell converts a zero write to an unmap operation and can only be used if 129a08b4a9fSPeter Maydell *DISCARD* is set to ``unmap``. The default is ``off``. 130a08b4a9fSPeter Maydell 131a08b4a9fSPeter Maydell.. option:: -c, --connect=DEV 132a08b4a9fSPeter Maydell 133a08b4a9fSPeter Maydell Connect *filename* to NBD device *DEV* (Linux only). 134a08b4a9fSPeter Maydell 135a08b4a9fSPeter Maydell.. option:: -d, --disconnect 136a08b4a9fSPeter Maydell 137a08b4a9fSPeter Maydell Disconnect the device *DEV* (Linux only). 138a08b4a9fSPeter Maydell 139a08b4a9fSPeter Maydell.. option:: -e, --shared=NUM 140a08b4a9fSPeter Maydell 141a08b4a9fSPeter Maydell Allow up to *NUM* clients to share the device (default 14258a6fdccSEric Blake ``1``), 0 for unlimited. 143a08b4a9fSPeter Maydell 144a08b4a9fSPeter Maydell.. option:: -t, --persistent 145a08b4a9fSPeter Maydell 146a08b4a9fSPeter Maydell Don't exit on the last connection. 147a08b4a9fSPeter Maydell 148a08b4a9fSPeter Maydell.. option:: -x, --export-name=NAME 149a08b4a9fSPeter Maydell 150a08b4a9fSPeter Maydell Set the NBD volume export name (default of a zero-length string). 151a08b4a9fSPeter Maydell 152a08b4a9fSPeter Maydell.. option:: -D, --description=DESCRIPTION 153a08b4a9fSPeter Maydell 154a08b4a9fSPeter Maydell Set the NBD volume export description, as a human-readable 155a08b4a9fSPeter Maydell string. 156a08b4a9fSPeter Maydell 157a08b4a9fSPeter Maydell.. option:: -L, --list 158a08b4a9fSPeter Maydell 159a08b4a9fSPeter Maydell Connect as a client and list all details about the exports exposed by 160a08b4a9fSPeter Maydell a remote NBD server. This enables list mode, and is incompatible 161a08b4a9fSPeter Maydell with options that change behavior related to a specific export (such as 162a08b4a9fSPeter Maydell :option:`--export-name`, :option:`--offset`, ...). 163a08b4a9fSPeter Maydell 164a08b4a9fSPeter Maydell.. option:: --tls-creds=ID 165a08b4a9fSPeter Maydell 166a08b4a9fSPeter Maydell Enable mandatory TLS encryption for the server by setting the ID 167a2c2d44aSEric Blake of the TLS credentials object previously created with the 168a2c2d44aSEric Blake :option:`--object` option; or provide the credentials needed for 169a2c2d44aSEric Blake connecting as a client in list mode. 170a08b4a9fSPeter Maydell 171003b2b25SDaniel P. Berrangé.. option:: --tls-hostname=hostname 172003b2b25SDaniel P. Berrangé 173003b2b25SDaniel P. Berrangé When validating an x509 certificate received over a TLS connection, 174003b2b25SDaniel P. Berrangé the hostname that the NBD client used to connect will be checked 175003b2b25SDaniel P. Berrangé against information in the server provided certificate. Sometimes 176003b2b25SDaniel P. Berrangé it might be required to override the hostname used to perform this 177003b2b25SDaniel P. Berrangé check. For example, if the NBD client is using a tunnel from localhost 178a2c2d44aSEric Blake to connect to the remote server, the :option:`--tls-hostname` option should 179003b2b25SDaniel P. Berrangé be used to set the officially expected hostname of the remote NBD 180003b2b25SDaniel P. Berrangé server. This can also be used if accessing NBD over a UNIX socket 181003b2b25SDaniel P. Berrangé where there is no inherent hostname available. This is only permitted 182a2c2d44aSEric Blake when acting as a NBD client with the :option:`--list` option. 183003b2b25SDaniel P. Berrangé 184a08b4a9fSPeter Maydell.. option:: --fork 185a08b4a9fSPeter Maydell 186a08b4a9fSPeter Maydell Fork off the server process and exit the parent once the server is running. 187a08b4a9fSPeter Maydell 188a08b4a9fSPeter Maydell.. option:: --pid-file=PATH 189a08b4a9fSPeter Maydell 190a08b4a9fSPeter Maydell Store the server's process ID in the given file. 191a08b4a9fSPeter Maydell 192a08b4a9fSPeter Maydell.. option:: --tls-authz=ID 193a08b4a9fSPeter Maydell 194a08b4a9fSPeter Maydell Specify the ID of a qauthz object previously created with the 195a08b4a9fSPeter Maydell :option:`--object` option. This will be used to authorize connecting users 196a08b4a9fSPeter Maydell against their x509 distinguished name. 197a08b4a9fSPeter Maydell 198a08b4a9fSPeter Maydell.. option:: -v, --verbose 199a08b4a9fSPeter Maydell 200*35e087deSDenis V. Lunev Display extra debugging information. This option also keeps the original 201*35e087deSDenis V. Lunev *STDERR* stream open if the ``qemu-nbd`` process is daemonized due to 202*35e087deSDenis V. Lunev other options like :option:`--fork` or :option:`-c`. 203a08b4a9fSPeter Maydell 204a08b4a9fSPeter Maydell.. option:: -h, --help 205a08b4a9fSPeter Maydell 206a08b4a9fSPeter Maydell Display this help and exit. 207a08b4a9fSPeter Maydell 208a08b4a9fSPeter Maydell.. option:: -V, --version 209a08b4a9fSPeter Maydell 210a08b4a9fSPeter Maydell Display version information and exit. 211a08b4a9fSPeter Maydell 212a08b4a9fSPeter Maydell.. option:: -T, --trace [[enable=]PATTERN][,events=FILE][,file=FILE] 213a08b4a9fSPeter Maydell 214a08b4a9fSPeter Maydell .. include:: ../qemu-option-trace.rst.inc 215a08b4a9fSPeter Maydell 216a08b4a9fSPeter MaydellExamples 217a08b4a9fSPeter Maydell-------- 218a08b4a9fSPeter Maydell 219a08b4a9fSPeter MaydellStart a server listening on port 10809 that exposes only the 220a08b4a9fSPeter Maydellguest-visible contents of a qcow2 file, with no TLS encryption, and 221a08b4a9fSPeter Maydellwith the default export name (an empty string). The command is 222a08b4a9fSPeter Maydellone-shot, and will block until the first successful client 223a08b4a9fSPeter Maydelldisconnects: 224a08b4a9fSPeter Maydell 225a08b4a9fSPeter Maydell:: 226a08b4a9fSPeter Maydell 227a08b4a9fSPeter Maydell qemu-nbd -f qcow2 file.qcow2 228a08b4a9fSPeter Maydell 229a08b4a9fSPeter MaydellStart a long-running server listening with encryption on port 10810, 2302d2e4843SThomas Huthand allow clients with a specific X.509 certificate to connect to 231a08b4a9fSPeter Maydella 1 megabyte subset of a raw file, using the export name 'subset': 232a08b4a9fSPeter Maydell 233a08b4a9fSPeter Maydell:: 234a08b4a9fSPeter Maydell 235a08b4a9fSPeter Maydell qemu-nbd \ 236a08b4a9fSPeter Maydell --object tls-creds-x509,id=tls0,endpoint=server,dir=/path/to/qemutls \ 237a08b4a9fSPeter Maydell --object 'authz-simple,id=auth0,identity=CN=laptop.example.com,,\ 238a08b4a9fSPeter Maydell O=Example Org,,L=London,,ST=London,,C=GB' \ 239a08b4a9fSPeter Maydell --tls-creds tls0 --tls-authz auth0 \ 240a08b4a9fSPeter Maydell -t -x subset -p 10810 \ 241a08b4a9fSPeter Maydell --image-opts driver=raw,offset=1M,size=1M,file.driver=file,file.filename=file.raw 242a08b4a9fSPeter Maydell 243a08b4a9fSPeter MaydellServe a read-only copy of a guest image over a Unix socket with as 244a08b4a9fSPeter Maydellmany as 5 simultaneous readers, with a persistent process forked as a 245a08b4a9fSPeter Maydelldaemon: 246a08b4a9fSPeter Maydell 247a08b4a9fSPeter Maydell:: 248a08b4a9fSPeter Maydell 249a08b4a9fSPeter Maydell qemu-nbd --fork --persistent --shared=5 --socket=/path/to/sock \ 250a08b4a9fSPeter Maydell --read-only --format=qcow2 file.qcow2 251a08b4a9fSPeter Maydell 252a08b4a9fSPeter MaydellExpose the guest-visible contents of a qcow2 file via a block device 253a08b4a9fSPeter Maydell/dev/nbd0 (and possibly creating /dev/nbd0p1 and friends for 254a08b4a9fSPeter Maydellpartitions found within), then disconnect the device when done. 255c5ba6219SPhilippe Mathieu-DaudéAccess to bind ``qemu-nbd`` to a /dev/nbd device generally requires root 256a08b4a9fSPeter Maydellprivileges, and may also require the execution of ``modprobe nbd`` 257a08b4a9fSPeter Maydellto enable the kernel NBD client module. *CAUTION*: Do not use 258a08b4a9fSPeter Maydellthis method to mount filesystems from an untrusted guest image - a 259a08b4a9fSPeter Maydellmalicious guest may have prepared the image to attempt to trigger 260a08b4a9fSPeter Maydellkernel bugs in partition probing or file system mounting. 261a08b4a9fSPeter Maydell 262a08b4a9fSPeter Maydell:: 263a08b4a9fSPeter Maydell 264a08b4a9fSPeter Maydell qemu-nbd -c /dev/nbd0 -f qcow2 file.qcow2 265a08b4a9fSPeter Maydell qemu-nbd -d /dev/nbd0 266a08b4a9fSPeter Maydell 267a08b4a9fSPeter MaydellQuery a remote server to see details about what export(s) it is 268a08b4a9fSPeter Maydellserving on port 10809, and authenticating via PSK: 269a08b4a9fSPeter Maydell 270a08b4a9fSPeter Maydell:: 271a08b4a9fSPeter Maydell 272a08b4a9fSPeter Maydell qemu-nbd \ 273a08b4a9fSPeter Maydell --object tls-creds-psk,id=tls0,dir=/tmp/keys,username=eblake,endpoint=client \ 274a08b4a9fSPeter Maydell --tls-creds tls0 -L -b remote.example.com 275a08b4a9fSPeter Maydell 276a08b4a9fSPeter MaydellSee also 277a08b4a9fSPeter Maydell-------- 278a08b4a9fSPeter Maydell 279a08b4a9fSPeter Maydell:manpage:`qemu(1)`, :manpage:`qemu-img(1)` 280