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