1QEMU-NBD(8) QEMU QEMU-NBD(8)
2
3
4
6 qemu-nbd - QEMU Disk Network Block Device Server
7
9 qemu-nbd [OPTION]... filename
10
11 qemu-nbd -L [OPTION]...
12
13 qemu-nbd -d dev
14
16 Export a QEMU disk image using the NBD protocol.
17
18 Other uses:
19
20 • Bind a /dev/nbdX block device to a QEMU server (on Linux).
21
22 • As a client to query exports of a remote NBD server.
23
25 filename is a disk image filename, or a set of block driver options if
26 --image-opts is specified.
27
28 dev is an NBD device.
29
30 --object type,id=ID,...
31 Define a new instance of the type object class identified by ID.
32 See the qemu(1) manual page for full details of the properties
33 supported. The common object types that it makes sense to define
34 are the secret object, which is used to supply passwords and/or
35 encryption keys, and the tls-creds object, which is used to sup‐
36 ply TLS credentials for the qemu-nbd server or client.
37
38 -p, --port=PORT
39 TCP port to listen on as a server, or connect to as a client
40 (default 10809).
41
42 -o, --offset=OFFSET
43 The offset into the image.
44
45 -b, --bind=IFACE
46 The interface to bind to as a server, or connect to as a client
47 (default 0.0.0.0).
48
49 -k, --socket=PATH
50 Use a unix socket with path PATH.
51
52 --image-opts
53 Treat filename as a set of image options, instead of a plain
54 filename. If this flag is specified, the -f flag should not be
55 used, instead the format= option should be set.
56
57 -f, --format=FMT
58 Force the use of the block driver for format FMT instead of
59 auto-detecting.
60
61 -r, --read-only
62 Export the disk as read-only.
63
64 -A, --allocation-depth
65 Expose allocation depth information via the qemu:alloca‐
66 tion-depth metadata context accessible through
67 NBD_OPT_SET_META_CONTEXT.
68
69 -B, --bitmap=NAME
70 If filename has a qcow2 persistent bitmap NAME, expose that bit‐
71 map via the qemu:dirty-bitmap:NAME metadata context accessible
72 through NBD_OPT_SET_META_CONTEXT.
73
74 -s, --snapshot
75 Use filename as an external snapshot, create a temporary file
76 with backing_file=filename, redirect the write to the temporary
77 one.
78
79 -l, --load-snapshot=SNAPSHOT_PARAM
80 Load an internal snapshot inside filename and export it as an
81 read-only device, SNAPSHOT_PARAM format is snap‐
82 shot.id=[ID],snapshot.name=[NAME] or [ID_OR_NAME]
83
84 --cache=CACHE
85 The cache mode to be used with the file. Valid values are: none,
86 writeback (the default), writethrough, directsync and unsafe.
87 See the documentation of the emulator's -drive cache=... option
88 for more info.
89
90 -n, --nocache
91 Equivalent to --cache=none.
92
93 --aio=AIO
94 Set the asynchronous I/O mode between threads (the default), na‐
95 tive (Linux only), and io_uring (Linux 5.1+).
96
97 --discard=DISCARD
98 Control whether discard (also known as trim or unmap) requests
99 are ignored or passed to the filesystem. DISCARD is one of ig‐
100 nore (or off), unmap (or on). The default is ignore.
101
102 --detect-zeroes=DETECT_ZEROES
103 Control the automatic conversion of plain zero writes by the OS
104 to driver-specific optimized zero write commands. DETECT_ZEROES
105 is one of off, on, or unmap. unmap converts a zero write to an
106 unmap operation and can only be used if DISCARD is set to unmap.
107 The default is off.
108
109 -c, --connect=DEV
110 Connect filename to NBD device DEV (Linux only).
111
112 -d, --disconnect
113 Disconnect the device DEV (Linux only).
114
115 -e, --shared=NUM
116 Allow up to NUM clients to share the device (default 1), 0 for
117 unlimited. Safe for readers, but for now, consistency is not
118 guaranteed between multiple writers.
119
120 -t, --persistent
121 Don't exit on the last connection.
122
123 -x, --export-name=NAME
124 Set the NBD volume export name (default of a zero-length
125 string).
126
127 -D, --description=DESCRIPTION
128 Set the NBD volume export description, as a human-readable
129 string.
130
131 -L, --list
132 Connect as a client and list all details about the exports ex‐
133 posed by a remote NBD server. This enables list mode, and is
134 incompatible with options that change behavior related to a spe‐
135 cific export (such as --export-name, --offset, ...).
136
137 --tls-creds=ID
138 Enable mandatory TLS encryption for the server by setting the ID
139 of the TLS credentials object previously created with the --ob‐
140 ject option; or provide the credentials needed for connecting as
141 a client in list mode.
142
143 --fork Fork off the server process and exit the parent once the server
144 is running.
145
146 --pid-file=PATH
147 Store the server's process ID in the given file.
148
149 --tls-authz=ID
150 Specify the ID of a qauthz object previously created with the
151 --object option. This will be used to authorize connecting users
152 against their x509 distinguished name.
153
154 -v, --verbose
155 Display extra debugging information.
156
157 -h, --help
158 Display this help and exit.
159
160 -V, --version
161 Display version information and exit.
162
163 -T, --trace [[enable=]PATTERN][,events=FILE][,file=FILE]
164 Specify tracing options.
165
166 [enable=]PATTERN
167 Immediately enable events matching PATTERN (either event name
168 or a globbing pattern). This option is only available if
169 QEMU has been compiled with the simple, log or ftrace tracing
170 backend. To specify multiple events or patterns, specify the
171 -trace option multiple times.
172
173 Use -trace help to print a list of names of trace points.
174
175 events=FILE
176 Immediately enable events listed in FILE. The file must con‐
177 tain one event name (as listed in the trace-events-all file)
178 per line; globbing patterns are accepted too. This option is
179 only available if QEMU has been compiled with the simple, log
180 or ftrace tracing backend.
181
182 file=FILE
183 Log output traces to FILE. This option is only available if
184 QEMU has been compiled with the simple tracing backend.
185
187 Start a server listening on port 10809 that exposes only the guest-vis‐
188 ible contents of a qcow2 file, with no TLS encryption, and with the de‐
189 fault export name (an empty string). The command is one-shot, and will
190 block until the first successful client disconnects:
191
192 qemu-nbd -f qcow2 file.qcow2
193
194 Start a long-running server listening with encryption on port 10810,
195 and whitelist clients with a specific X.509 certificate to connect to a
196 1 megabyte subset of a raw file, using the export name 'subset':
197
198 qemu-nbd \
199 --object tls-creds-x509,id=tls0,endpoint=server,dir=/path/to/qemutls \
200 --object 'authz-simple,id=auth0,identity=CN=laptop.example.com,,\
201 O=Example Org,,L=London,,ST=London,,C=GB' \
202 --tls-creds tls0 --tls-authz auth0 \
203 -t -x subset -p 10810 \
204 --image-opts driver=raw,offset=1M,size=1M,file.driver=file,file.filename=file.raw
205
206 Serve a read-only copy of a guest image over a Unix socket with as many
207 as 5 simultaneous readers, with a persistent process forked as a dae‐
208 mon:
209
210 qemu-nbd --fork --persistent --shared=5 --socket=/path/to/sock \
211 --read-only --format=qcow2 file.qcow2
212
213 Expose the guest-visible contents of a qcow2 file via a block device
214 /dev/nbd0 (and possibly creating /dev/nbd0p1 and friends for partitions
215 found within), then disconnect the device when done. Access to bind
216 qemu-nbd to a /dev/nbd device generally requires root privileges, and
217 may also require the execution of modprobe nbd to enable the kernel NBD
218 client module. CAUTION: Do not use this method to mount filesystems
219 from an untrusted guest image - a malicious guest may have prepared the
220 image to attempt to trigger kernel bugs in partition probing or file
221 system mounting.
222
223 qemu-nbd -c /dev/nbd0 -f qcow2 file.qcow2
224 qemu-nbd -d /dev/nbd0
225
226 Query a remote server to see details about what export(s) it is serving
227 on port 10809, and authenticating via PSK:
228
229 qemu-nbd \
230 --object tls-creds-psk,id=tls0,dir=/tmp/keys,username=eblake,endpoint=client \
231 --tls-creds tls0 -L -b remote.example.com
232
234 qemu(1), qemu-img(1)
235
237 Anthony Liguori <anthony@codemonkey.ws>
238
240 2022, The QEMU Project Developers
241
242
243
244
2456.2.0 Jun 11, 2022 QEMU-NBD(8)