1@example 2@c man begin SYNOPSIS 3@command{qemu-nbd} [OPTION]... @var{filename} 4 5@command{qemu-nbd} @option{-L} [OPTION]... 6 7@command{qemu-nbd} @option{-d} @var{dev} 8@c man end 9@end example 10 11@c man begin DESCRIPTION 12 13Export a QEMU disk image using the NBD protocol. 14 15Other uses: 16@itemize 17@item 18Bind a /dev/nbdX block device to a QEMU server (on Linux). 19@item 20As a client to query exports of a remote NBD server. 21@end itemize 22 23@c man end 24 25@c man begin OPTIONS 26@var{filename} is a disk image filename, or a set of block 27driver options if @option{--image-opts} is specified. 28 29@var{dev} is an NBD device. 30 31@table @option 32@item --object type,id=@var{id},...props... 33Define a new instance of the @var{type} object class identified by @var{id}. 34See the @code{qemu(1)} manual page for full details of the properties 35supported. The common object types that it makes sense to define are the 36@code{secret} object, which is used to supply passwords and/or encryption 37keys, and the @code{tls-creds} object, which is used to supply TLS 38credentials for the qemu-nbd server or client. 39@item -p, --port=@var{port} 40The TCP port to listen on as a server, or connect to as a client 41(default @samp{10809}). 42@item -o, --offset=@var{offset} 43The offset into the image. 44@item -b, --bind=@var{iface} 45The interface to bind to as a server, or connect to as a client 46(default @samp{0.0.0.0}). 47@item -k, --socket=@var{path} 48Use a unix socket with path @var{path}. 49@item --image-opts 50Treat @var{filename} as a set of image options, instead of a plain 51filename. If this flag is specified, the @var{-f} flag should 52not be used, instead the '@code{format=}' option should be set. 53@item -f, --format=@var{fmt} 54Force the use of the block driver for format @var{fmt} instead of 55auto-detecting. 56@item -r, --read-only 57Export the disk as read-only. 58@item -P, --partition=@var{num} 59Deprecated: Only expose MBR partition @var{num}. Understands physical 60partitions 1-4 and logical partition 5. New code should instead use 61@option{--image-opts} with the raw driver wrapping a subset of the 62original image. 63@item -B, --bitmap=@var{name} 64If @var{filename} has a qcow2 persistent bitmap @var{name}, expose 65that bitmap via the ``qemu:dirty-bitmap:@var{name}'' context 66accessible through NBD_OPT_SET_META_CONTEXT. 67@item -s, --snapshot 68Use @var{filename} as an external snapshot, create a temporary 69file with backing_file=@var{filename}, redirect the write to 70the temporary one. 71@item -l, --load-snapshot=@var{snapshot_param} 72Load an internal snapshot inside @var{filename} and export it 73as an read-only device, @var{snapshot_param} format is 74'snapshot.id=[ID],snapshot.name=[NAME]' or '[ID_OR_NAME]' 75@item -n, --nocache 76@itemx --cache=@var{cache} 77The cache mode to be used with the file. See the documentation of 78the emulator's @code{-drive cache=...} option for allowed values. 79@item --aio=@var{aio} 80Set the asynchronous I/O mode between @samp{threads} (the default) 81and @samp{native} (Linux only). 82@item --discard=@var{discard} 83Control whether @dfn{discard} (also known as @dfn{trim} or @dfn{unmap}) 84requests are ignored or passed to the filesystem. @var{discard} is one of 85@samp{ignore} (or @samp{off}), @samp{unmap} (or @samp{on}). The default is 86@samp{ignore}. 87@item --detect-zeroes=@var{detect-zeroes} 88Control the automatic conversion of plain zero writes by the OS to 89driver-specific optimized zero write commands. @var{detect-zeroes} is one of 90@samp{off}, @samp{on} or @samp{unmap}. @samp{unmap} 91converts a zero write to an unmap operation and can only be used if 92@var{discard} is set to @samp{unmap}. The default is @samp{off}. 93@item -c, --connect=@var{dev} 94Connect @var{filename} to NBD device @var{dev} (Linux only). 95@item -d, --disconnect 96Disconnect the device @var{dev} (Linux only). 97@item -e, --shared=@var{num} 98Allow up to @var{num} clients to share the device (default 99@samp{1}). Safe for readers, but for now, consistency is not 100guaranteed between multiple writers. 101@item -t, --persistent 102Don't exit on the last connection. 103@item -x, --export-name=@var{name} 104Set the NBD volume export name (default of a zero-length string). 105@item -D, --description=@var{description} 106Set the NBD volume export description, as a human-readable 107string. 108@item -L, --list 109Connect as a client and list all details about the exports exposed by 110a remote NBD server. This enables list mode, and is incompatible 111with options that change behavior related to a specific export (such as 112@option{--export-name}, @option{--offset}, ...). 113@item --tls-creds=ID 114Enable mandatory TLS encryption for the server by setting the ID 115of the TLS credentials object previously created with the --object 116option; or provide the credentials needed for connecting as a client 117in list mode. 118@item --fork 119Fork off the server process and exit the parent once the server is running. 120@item --tls-authz=ID 121Specify the ID of a qauthz object previously created with the 122--object option. This will be used to authorize connecting users 123against their x509 distinguished name. 124@item -v, --verbose 125Display extra debugging information. 126@item -h, --help 127Display this help and exit. 128@item -V, --version 129Display version information and exit. 130@item -T, --trace [[enable=]@var{pattern}][,events=@var{file}][,file=@var{file}] 131@findex --trace 132@include qemu-option-trace.texi 133@end table 134 135@c man end 136 137@c man begin EXAMPLES 138Start a server listening on port 10809 that exposes only the 139guest-visible contents of a qcow2 file, with no TLS encryption, and 140with the default export name (an empty string). The command is 141one-shot, and will block until the first successful client 142disconnects: 143 144@example 145qemu-nbd -f qcow2 file.qcow2 146@end example 147 148Start a long-running server listening with encryption on port 10810, 149and whitelist clients with a specific X.509 certificate to connect to 150a 1 megabyte subset of a raw file, using the export name 'subset': 151 152@example 153qemu-nbd \ 154 --object tls-creds-x509,id=tls0,endpoint=server,dir=/path/to/qemutls \ 155 --object 'authz-simple,id=auth0,identity=CN=laptop.example.com,,\ 156 O=Example Org,,L=London,,ST=London,,C=GB' \ 157 --tls-creds tls0 --tls-authz auth0 \ 158 -t -x subset -p 10810 \ 159 --image-opts driver=raw,offset=1M,size=1M,file.driver=file,file.filename=file.raw 160@end example 161 162Serve a read-only copy of just the first MBR partition of a guest 163image over a Unix socket with as many as 5 simultaneous readers, with 164a persistent process forked as a daemon: 165 166@example 167qemu-nbd --fork --persistent --shared=5 --socket=/path/to/sock \ 168 --partition=1 --read-only --format=qcow2 file.qcow2 169@end example 170 171Expose the guest-visible contents of a qcow2 file via a block device 172/dev/nbd0 (and possibly creating /dev/nbd0p1 and friends for 173partitions found within), then disconnect the device when done. 174Access to bind qemu-nbd to an /dev/nbd device generally requires root 175privileges, and may also require the execution of @code{modprobe nbd} 176to enable the kernel NBD client module. @emph{CAUTION}: Do not use 177this method to mount filesystems from an untrusted guest image - a 178malicious guest may have prepared the image to attempt to trigger 179kernel bugs in partition probing or file system mounting. 180 181@example 182qemu-nbd -c /dev/nbd0 -f qcow2 file.qcow2 183qemu-nbd -d /dev/nbd0 184@end example 185 186Query a remote server to see details about what export(s) it is 187serving on port 10809, and authenticating via PSK: 188 189@example 190qemu-nbd \ 191 --object tls-creds-psk,id=tls0,dir=/tmp/keys,username=eblake,endpoint=client \ 192 --tls-creds tls0 -L -b remote.example.com 193@end example 194 195@c man end 196 197@ignore 198 199@setfilename qemu-nbd 200@settitle QEMU Disk Network Block Device Server 201 202@c man begin AUTHOR 203Copyright (C) 2006 Anthony Liguori <anthony@codemonkey.ws>. 204This is free software; see the source for copying conditions. There is NO 205warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 206@c man end 207 208@c man begin SEEALSO 209qemu(1), qemu-img(1) 210@c man end 211 212@end ignore 213