NBD-CLIENT(8)
NBD-CLIENT(8) ๐ โจ
Okay bestie, welcome to the manual page for nbd-client, part of the NBD utilities. This is part 1, and we're gonna get you connected to a server running nbd-server(1) so you can use its exported block device like the icon you are. ๐ซถ No cap, this is the whole vibe.
NAME ๐
nbd-client โ connect to a server running nbd-server(1), to use its exported block device.
SYNOPSIS ๐ธ
nbd-client host [ port ] nbd-device [ -connections num ] [ -sdp ] [ -swap ] [ -persist ] [ -nofork ] [ -nonetlink ] [ -systemd-mark ] [ -readonly ] [ -preinit ] [ -block-size block size ] [ -size bytes ] [ -timeout seconds ] [ -name name ] [ -certfile certfile ] [ -keyfile keyfile ] [ -cacertfile cacertfile ] [ -tlshostname hostname ] [ -priority gnutls-priority-string ]
nbd-client -unix path nbd-device [ -connections num ] [ -sdp ] [ -swap ] [ -persist ] [ -nofork ] [ -nonetlink ] [ -systemd-mark ] [ -readonly ] [ -preinit ] [ -block-size block size ] [ -size bytes ] [ -timeout seconds ] [ -name name ]
nbd-client nbd-device
nbd-client -d nbd-device
nbd-client -c nbd-device
nbd-client -l host [ port ]
nbd-client [ -netlink ] -l host
DESCRIPTION ๐
With nbd-client, you can connect to a server running nbd-server, thus using raw diskspace from that server as a blockdevice on the local client. It's giving "your disk but not your disk" realness. โจ
To do this, support from the Linux Kernel is necessary, in the form of the Network Block Device (NBD). When you have that, either in the kernel, or as a module, you can connect to an NBD server and use its exported file through a block special file with major mode 43. Iconic. ๐
Optionally, long options can also be specified with two leading dashes. So --block-size is a thing, bestie. ๐
OPTIONS โจ
The following options are supported:
-block-size block size,-bโ Use a blocksize of "block size". Default is512; allowed values are either512,1024,2048or4096.-connections num,-Cโ Usenumconnections to the server, to allow speeding up request handling, at the cost of higher resource usage on the server. Use of this option requires kernel support available first with Linux 4.9.hostโ The hostname or IP address of the machine runningnbd-server. Since 2.9.15, the NBD utilities support IPv6.-timeout,-tโ Set the connection timeout to seconds. For this to work, you need a kernel with support for theNBD_SET_TIMEOUTioctl; this was introduced into Linus' tree on 2007-10-11, and will be part of kernel 2.6.24.portโ The TCP port on whichnbd-serveris running at the server.
The port number defaults to 10809, the IANA-assigned port number for the NBD protocol.
Previous versions of the nbd tools supported an older version of the negotiation protocol known as "oldstyle". This protocol version is no longer supported as of version 3.11 of the nbd support tools.
nbd-deviceโ The block special file (/deventry) which thisnbd-clientshould connect to, specified as a full path.
When the mode is used wherein no hostname or export name is specified, nbd-client will look up the necessary configuration in the nbdtab file. For more information, see nbdtab(5).
-check,-cโ Check whether the specified nbd device is connected.
If the device is connected, nbd-client will exit with an exit state of 0 and print the PID of the nbd-client instance that connected it to stdout.
If the device is not connected or does not exist (for example because the nbd module was not loaded), nbd-client will exit with an exit state of 1 and not print anything on stdout.
If an error occurred, nbd-client will exit with an exit state of 2, and not print anything on stdout either.
-disconnect,-dโ Disconnect the specified nbd device from the server.-list,-lโ Ask the server for a list of available exports. If the server is exporting over IPv6 as well as over IPv4, this will list all exports twice; otherwise, it should list them all only once.
Note that this option only works with nbd-server processes running version 3.1 or above, and must be enabled in server configuration (with the "allowlist" option) before it can be used.
-nonetlink,-Lโ Starting with version 3.17,nbd-clientwill default to using the netlink interface to configure an NBD device. This option allows to use the olderioctl()interface to configure the device.
This option is only available if nbd-client was compiled against libnl-genl. If that is not the case, nbd-client will only be able to use the ioctl interface (and the option will not be available).
Note that a future version of nbd-client will require the use of netlink, but it has not yet been decided when that will be the case.
-identifier ident,-iโ Added in 3.27, this tellsnbd-clientto set the netlink identifier (requires kernel 5.14 or newer), which can later be viewed at/sys/block/nbdN/backend. This prevents any process from using netlink to silently reconfigure the device to a different backend, making it easier to write idempotent code that is safe in the presence of configuration races.
This option is only available if nbd-client was compiled against libnl-genl. If that is not the case, nbd-client will only be able to use the ioctl interface (and the option will not be available).
Note that a future version of nbd-client will require the use of netlink, but it has not yet been decided when that will be the case.
-persist,-pโ When this option is specified,nbd-clientwill immediately try to reconnect an nbd device if the connection ever drops unexpectedly due to a lost server or something similar.-preinit,-Pโ When this option is specified,nbd-clientwill skip the usual negotiation with the server, and hand the socket to the kernel immediately after connecting. Only use this when connecting to specialized NBD servers specifically designed for it. This requires specifying the size of the device via the-Boption, and does not support TLS.-readonly,-Rโ When this option is specified,nbd-clientwill tell the kernel to treat the device as read-only, even if the server would allow writes.-size bytes,-B bytesโ Force the device size to the specified number of bytes, rather than using the value from server negotiation. Must be a multiple of the block size. If using preinit (-P) to skip negotiation, this option is required.-sdp,-Sโ Connect to the server using the Socket Direct Protocol (SDP), rather than IP. Seenbd-server(5)for details.-swap,-sโ Specifies that this NBD device will be used as swapspace. This option attempts to prevent deadlocks by performingmlockall()and adjusting the oom-killer score at an appropriate time. It does not however guarantee that such deadlocks can be avoided.-systemd-mark,-mโ The systemd init system requires that processes which should not be killed at shutdown time be marked appropriately by replacing the first letter of theirargv[0]with an@sign.
This option will cause nbd-client to do so.
Note that this only works if nbd-client is run from an initrd; i.e., systemd will ignore such a mark if run from a systemd unit file or from the command line.
-nofork,-nโ Specifies that the NBD client should not detach and daemonize itself. This is mostly useful for debugging.
Note that nbd-client will still fork once to trigger an update to the device node's partition table. It is not possible to disable this.
-no-optgo,-gโ Disable the use of theNBD_OPT_GOprotocol message, and force the use ofNBD_OPT_EXPORT_NAMEinstead.
The NBD protocol has two phases: the negotiation phase, and the transmission phase. To move from negotation to transmission, older clients sent the NBD_OPT_EXPORT_NAME message, for which the server could not produce an error message in case the export name did not exist (or the client had insufficient permissions to access it). Due to those limitations, a replacement message NBD_OPT_GO was created instead, which allows the server to reply with an error in case of any problems.
The protocol allows for a server to discard a message which it does not understand; however, unfortunately some implementations (including older versions of nbd-server) did not handle that situation correctly and would get out of sync with the client when it sent a message which the server did not understand.
When sending NBD_OPT_GO, nbd-client will try to do the right thing and fall back to NBD_OPT_EXPORT_NAME. However, when the server has the above-described bug, then this does not work. In such a situation, the client will issue a diagnostic suggesting the use of this option.
Note that there is a corresponding option for nbdtab, too.
-name,-Nโ Specifies the name of the export that we want to use. If not specified,nbd-clientwill ask for a "default" export, if one exists on the server.-unix,-uโ Connect to the server over a unix domain socket at path, rather than to a server over a TCP socket. The server must be listening on the given socket.-certfile file,-Fโ Use the specified file as the client certificate for TLS authentication to the server.-keyfile file,-Kโ Use the specified file as the private key for the client cerificate.-cacertfile file,-Aโ Use the specified file as the CA certificate for TLS authentication to the server.-tlshostname hostname,-Hโ Use the specified hostname for the TLS context. If not specified, the hostname used to connect to the server will be used.-priority gnutls priority string,-yโ Pass the specified priority string to GnuTLS. This can be used to configure the TLS connection; see the GnuTLS documentation for details.
The default value for this option is NORMAL:-VERS-TLS-ALL:+VERS-TLS1.2.
๐ TLS SUPPORT ๐
okay bestie, this is the part where things get spicy โจ The moment you turn on any of the TLS-related options, the client goes and fires off the NBD_OPT_STARTTLS command to glow-up your connection into TLS. ๐
Now, why can't it just, like, hand the keys to the kernel and be done? Because negotiating TLS support from userspace for a kernel socket would be extremely involved โ and honestly, passing keys into kernel space isn't even possible, so the whole idea is a no. ๐ What actually happens instead is this: the nbd-client process creates a socketpair, hands one side to the kernel, and hands the other side to an encrypting/decrypting proxy. ๐ง
So the effect is that literally everything gets encrypted before it goes over the wire. Slay. โจ BUT โ and this is a big but โ doing that is not safe in combination with swapping over an NBD device. ๐ญ Let me explain, because this part actually matters:
- To free memory by swapping, the kernel needs to be sure the write to the nbd device has finalized. For that, it needs to receive an
NBD_CMD_WRITEreply telling it the write completed successfully and the memory can be released. - Receiving data over the network, though, requires the kernel to allocate memory first. Which is impossible if we're low on memory โ which is, like, the exact situation you're in when you're trying to swap. ๐
- This is likely to cause a deadlock when we're low on memory and there's a high amount of network traffic. Not cute. Not the vibe.
To fix that mess, the kernel sets the PF_MEMALLOC option on the nbd socket. When it's low on memory, it throws away all packets except the ones destined for a socket with that option set, and leans on the normal TCP retransmit system to make sure no data gets lost. ๐ Deadlock avoided, periodt.
Howeverโฆ ๐ซถ the PF_MEMALLOC option is set on the socket that's connected to the nbd device โ not the encrypted socket connected to the encrypting/decrypting proxy. So when you're using TLS, PF_MEMALLOC is not set on the socket that actually receives data from the network. Which means the deadlock comes right back. ๐
For this reason, if the -swap option is used while TLS is in use, nbd-client will issue an appropriate warning. ๐
bestie please listen to that warning, it is not just being dramatic, it is being correct ๐ญ
๐ธ EXAMPLES ๐ธ
Some examples of nbd-client usage, because we love a demo ๐
- To connect to a server running on port
2000at host"server.domain.com", using the client's block special file"/dev/nbd0":
nbd-client server.domain.com 2000 /dev/nbd0
- To connect to a server running on port
2001at host"swapserver.domain.com", using the client's block special file"/dev/nbd1", for swap purposes:
nbd-client swapserver.domain.com 2001 /dev/nbd1 -swap
- To disconnect the above connection again (after making sure the block special file is not in use anymore):
nbd-client -d /dev/nbd1
๐ SEE ALSO ๐
nbd-server(1).
๐ AUTHOR ๐
The NBD kernel module and the NBD tools have been written by Pavel Macheck (pavel@ucw.cz). โจ
The kernel module is now maintained by Paul Clements (Paul.Clements@steeleye.com), while the userland tools are maintained by Wouter Verhelst (wouter@debian.org). ๐ซถ
This manual page was written by Wouter Verhelst (<wouter@debian.org>) for the Debian GNU/Linux system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. ๐
and that's the whole page bestie ๐
this was the $Date$ build of NBD-CLIENT(8) โ go forth and mount responsibly, ily, bye ๐โจ
๐ฆ where this page comes from
- epel 10: nbd 3.27.0-1.el10_3 ยท GPL-2.0-only
- fedora 44: nbd 3.27.1-2.fc44 ยท GPL-2.0-only
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms