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