1nbdfuse(1) LIBNBD nbdfuse(1)
2
3
4
6 nbdfuse - mount a network block device in the local filesystem
7
9 nbdfuse [-C N|--connections N] [-d] [-o FUSE-OPTION] [-P PIDFILE]
10 [-r] [-s] [-v|--verbose]
11 MOUNTPOINT[/FILENAME] URI
12
13 nbdfuse MOUNTPOINT[/FILENAME] [ CMD [ARGS ...] ]
14
15 nbdfuse MOUNTPOINT[/FILENAME] --command CMD [ARGS ...]
16
17 nbdfuse MOUNTPOINT[/FILENAME] --fd N
18
19 nbdfuse MOUNTPOINT[/FILENAME] --tcp HOST PORT
20
21 nbdfuse MOUNTPOINT[/FILENAME] --unix SOCKET
22
23 nbdfuse MOUNTPOINT[/FILENAME] --vsock CID PORT
24
25 To unmount:
26
27 fusermount3 -u MOUNTPOINT
28
29 Other options:
30
31 nbdfuse --help
32
33 nbdfuse --fuse-help
34
35 nbdfuse -V|--version
36
38 nbdfuse is used to mount a Network Block Device (NBD) in the local
39 filesystem. The NBD virtual file is mounted at MOUNTPOINT/FILENAME
40 (defaulting to MOUNTPOINT/nbd). Reads and writes to the virtual file
41 are turned into reads and writes to the NBD device.
42
43 In nbdfuse ≥ 1.6 you can also create a "naked" mountpoint by mounting
44 over any regular file called MOUNTPOINT (the existing contents of the
45 file do not matter).
46
47 The NBD server itself can be local or remote. The server can be
48 specified as an NBD URI (like "nbd://localhost"), or as an NBD server
49 running as a subprocess of nbdfuse (using "[ ... ]"), or in various
50 other ways (see "MODES").
51
52 Use "fusermount3 -u MOUNTPOINT" to unmount the filesystem after you
53 have used it.
54
56 Present a remote NBD server as a local file
57 If there is a remote NBD server running on "example.com" at the default
58 NBD port number (10809) then you can turn it into a local file by
59 doing:
60
61 $ mkdir dir
62 $ nbdfuse dir nbd://example.com &
63 $ ls -l dir/
64 total 0
65 -rw-rw-rw-. 1 nbd nbd 1073741824 Jan 1 10:10 nbd
66
67 The file is called dir/nbd and you can read and write to it as if it is
68 a normal file. Note that writes to the file will write to the remote
69 NBD server. After using it, unmount it:
70
71 $ fusermount3 -u dir
72 $ rmdir dir
73
74 Use nbdkit to create a file backed by a temporary RAM disk
75 Using "[ ... ]" you can run an NBD server as a subprocess. In this
76 example nbdkit(1) is used to create a temporary file backed by a RAM
77 disk:
78
79 $ mkdir dir
80 $ nbdfuse dir/ramdisk [ nbdkit --exit-with-parent memory 1G ] &
81 $ ls -l dir/
82 total 0
83 -rw-rw-rw-. 1 nbd nbd 1073741824 Jan 1 10:10 ramdisk
84 $ dd if=/dev/urandom bs=1M count=100 of=mp/ramdisk conv=notrunc,nocreat
85 100+0 records in
86 100+0 records out
87 104857600 bytes (105 MB, 100 MiB) copied, 2.08319 s, 50.3 MB/s
88
89 When you have finished with the RAM disk, you can unmount it as below
90 which will cause nbdkit to exit and the RAM disk contents to be
91 discarded:
92
93 $ fusermount3 -u dir
94 $ rmdir dir
95
96 Use qemu-nbd to read and modify a qcow2 file
97 You can use qemu-nbd(8) as a subprocess to open any file format which
98 qemu understands:
99
100 $ mkdir dir
101 $ nbdfuse dir/file.raw [ qemu-nbd -f qcow2 file.qcow2 ] &
102 $ ls -l dir/
103 total 0
104 -rw-rw-rw-. 1 nbd nbd 1073741824 Jan 1 10:10 file.raw
105
106 File dir/file.raw is in raw format, backed by file.qcow2. Any changes
107 made to dir/file.raw are reflected into the qcow2 file. To unmount the
108 file do:
109
110 $ fusermount3 -u dir
111 $ rmdir dir
112
113 Use nbdkit to create a local file from a file on a web server
114 nbdkit(1) is able to both access and transparently uncompress remote
115 disk images on web servers, so you can convert them into virtual files:
116
117 $ mkdir dir
118 $ nbdfuse dir/disk.iso \
119 [ nbdkit --exit-with-parent \
120 curl --filter=xz \
121 http://builder.libguestfs.org/fedora-30.xz ] &
122 $ ls -l dir/
123 total 0
124 -rw-rw-rw-. 1 nbd nbd 6442450944 Jan 1 10:10 disk.iso
125 $ file dir/disk.iso
126 dir/disk.iso: DOS/MBR boot sector
127 $ qemu-system-x86_64 -m 4G \
128 -drive file=dir/disk.iso,format=raw,if=virtio,snapshot=on
129 $ fusermount3 -u dir
130
131 In this example we have used the virtual file to boot qemu, but qemu
132 can much more efficiently access NBD servers directly so in the real
133 world that would be the preferred method.
134
136 --help
137 Display brief command line help and exit.
138
139 -C N
140 --connections N
141 If multi-conn is used, use N connections to the server. The
142 default is 4.
143
144 Multi-conn is enabled by default when possible. Modes which run a
145 subprocess, such as --command are not able to use multi-conn. Mode
146 --fd also cannot use multi-conn. Also the server must advertise
147 multi-conn (use nbdinfo(1) to query what the server supports).
148
149 See "THREAD MODEL" below.
150
151 -C 1
152 --connections 1
153 Disable multi-conn. Only use a single connection to the NBD
154 server. See "THREAD MODEL" below.
155
156 --fuse-help
157 Display FUSE options and exit. See -o below.
158
159 -o FUSE-OPTION
160 Pass extra options to FUSE. To get a list of all the extra options
161 supported by FUSE, use --fuse-help.
162
163 Some potentially useful FUSE options:
164
165 -o allow_other
166 Allow other users to see the filesystem. This option has no
167 effect unless you enable it globally in /etc/fuse.conf.
168
169 -o kernel_cache
170 Allow the kernel to cache files (reduces the number of reads
171 that have to go through the libnbd(3) API). This is generally
172 a good idea if you can afford the extra memory usage.
173
174 -o uid=N
175 -o gid=N
176 Use these options to map UIDs and GIDs.
177
178 -P PIDFILE
179 --pidfile PIDFILE
180 When nbdfuse is ready to serve, write the nbdfuse process ID (PID)
181 to PIDFILE. This can be used in scripts to wait until nbdfuse is
182 ready. Note you mustn't try to kill nbdfuse. Use "fusermount3 -u"
183 to unmount the mountpoint which will cause nbdfuse to exit cleanly.
184
185 -r
186 --readonly
187 Access the network block device read-only. The virtual file will
188 have read-only permissions, and any writes will return errors.
189
190 -s Use single-threaded FUSE operations. See "THREAD MODEL" below.
191
192 -v
193 --verbose
194 -d Enable verbose messages to stderr. This enables libnbd debugging
195 and other messages. The -d option is an alias, used for
196 compatibility with other FUSE programs.
197
198 -V
199 --version
200 Display the package name and version and exit.
201
203 Modes are used to select the NBD server. The default mode uses an NBD
204 URI (see nbd_connect_uri(3) and
205 https://github.com/NetworkBlockDevice/nbd/blob/master/doc/uri.md). For
206 example this specifies a TLS-encrypted connection to "example.com" port
207 10809, with export name "disk":
208
209 nbdfuse dir nbds://example.com/disk
210
211 Other modes are:
212
213 [ CMD [ARGS ...] ]
214 Run an NBD server as a subprocess. In this mode an NBD server can
215 be run directly from the command line with nbdfuse communicating
216 with the server over a socket. This requires that the NBD server
217 supports systemd socket activation. See "EXAMPLES" above and
218 nbd_connect_systemd_socket_activation(3).
219
220 --command CMD [ARGS ...]
221 Select command mode. In this mode an NBD server can be run
222 directly from the command line with nbdfuse communicating with the
223 server over the server’s stdin/stdout. Normally you would use this
224 with "nbdkit -s". See nbd_connect_command(3).
225
226 --fd N
227 Select file descriptor mode. In this mode a connected socket is
228 passed to nbdfuse. nbdfuse connects to the socket on the numbered
229 file descriptor. See also nbd_connect_socket(3).
230
231 --tcp HOST PORT
232 Select TCP mode. Connect to an NBD server on a host and port over
233 an unencrypted TCP socket. See also nbd_connect_tcp(3).
234
235 --unix SOCKET
236 Select Unix mode. Connect to an NBD server on a Unix domain
237 socket. See also nbd_connect_unix(3).
238
239 --vsock CID PORT
240 Select vsock mode. Connect to an NBD server on a "AF_VSOCK"
241 socket. See also nbd_connect_vsock(3).
242
244 This section describes how the current version of nbdfuse works.
245 Previous versions worked differently in the past, and future versions
246 may work differently in the future.
247
248 nbdfuse is always multithreaded.
249
250 nbdfuse will try to open multiple network connections to the NBD server
251 if possible (called "multi-conn"). This usually improves performance.
252 Some things which disable multi-conn are:
253
254 • using "[ CMD ... ]" or --command or --fd modes
255
256 • using -C 1
257
258 • the NBD server does not advertise multi-conn (check using
259 nbdinfo(1))
260
261 You can control how many connections are made using the -C flag.
262
263 nbdfuse runs one thread per connection to service NBD commands (these
264 are called "operation threads"). In addition, FUSE itself creates
265 multiple threads to deal with requests coming from the fuse.ko kernel
266 module. The number of threads that FUSE can create is described in the
267 FUSE documentation, but with many parallel accesses to the virtual file
268 there may be many more FUSE threads created than operation threads, and
269 this should lead to good performance. FUSE requests (like read, write
270 or trim) are multiplexed on to the operation threads (= connections) at
271 random. Each operation thread can handle multiple requests in
272 parallel.
273
274 Using the -s flag causes FUSE the only run a single thread, but there
275 may still be multiple operation threads.
276
278 Loop mounting
279 It is tempting (and possible) to loop mount the file. However this
280 will be very slow and may sometimes deadlock. Better alternatives are
281 to use nbd-client(8) or qemu-nbd(8), or more securely libguestfs(3),
282 guestfish(1) or guestmount(1) which can all access NBD servers.
283
284 As a way to access NBD servers
285 You can use this to access NBD servers, but it is usually better (and
286 definitely much faster) to use libnbd(3) directly instead. To access
287 NBD servers from the command line, look at nbdsh(1). To copy to and
288 from an NBD server use nbdcopy(1).
289
291 Compared to "nbd-client"
292 This program is similar in concept to nbd-client(8) (which turns NBD
293 into /dev/nbdX device nodes), except:
294
295 • nbd-client is faster because it uses a special kernel module
296
297 • nbd-client requires root, but nbdfuse can be used by any user
298
299 • nbdfuse virtual files can be mounted anywhere in the filesystem
300
301 • nbdfuse uses libnbd to talk to the NBD server
302
303 • nbdfuse requires FUSE support in the kernel
304
305 Compared to "qemu-nbd"
306 qemu-nbd(8) can also attach itself to /dev/nbdX device nodes. The
307 differences from nbdfuse are similar to the list above.
308
310 libnbd(3), nbdcopy(1), nbdinfo(1), nbdsh(1), fusermount3(1),
311 mount.fuse3(8), nbd_connect_uri(3), nbd_connect_command(3),
312 nbd_connect_socket(3), nbd_connect_systemd_socket_activation(3),
313 nbd_connect_tcp(3), nbd_connect_unix(3), nbd_connect_vsock(3),
314 libguestfs(3), guestfish(1), guestmount(1), nbdkit(1), nbdkit-loop(1),
315 qemu-nbd(8), nbd-client(8).
316
318 Richard W.M. Jones
319
321 Copyright (C) 2019-2021 Red Hat Inc.
322
324 This library is free software; you can redistribute it and/or modify it
325 under the terms of the GNU Lesser General Public License as published
326 by the Free Software Foundation; either version 2 of the License, or
327 (at your option) any later version.
328
329 This library is distributed in the hope that it will be useful, but
330 WITHOUT ANY WARRANTY; without even the implied warranty of
331 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
332 Lesser General Public License for more details.
333
334 You should have received a copy of the GNU Lesser General Public
335 License along with this library; if not, write to the Free Software
336 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
337 02110-1301 USA
338
339
340
341libnbd-1.7.12 2021-05-29 nbdfuse(1)