Network Block Device

A Network Block Device (English for network block device, abbreviated NBD) is a type of virtual hard disk that is accessible via Internet protocol to a computer. NBD is provided by a server NBD. He offers this to their hard drive, hard disk partition or a file as NBD certain other computers (clients ). Another computer ( or the same ) can connect to via a TCP connection with the NBD server and then use the NBD as its own local disk.

There is currently a full NBD- only implementation for Linux. Linux speaks all mass storage devices as a so-called block. When a Linux computer to use a network block device must NBD support is enabled in the Linux kernel configuration, and the kernel module to be loaded nbd.ko. A userspace utility called nbd -client now provides the TCP connection to the NBD server, are the existing connection to the kernel and then terminates. This has the advantage that the kernel can not open the connection ( and a possible authentication, etc.) have to deal with.

The NBD server is operating system independent. So, it can also run on a non-Linux system, since no Linux-specific functions are required. There is a program called nbd -server, which does nothing more than a given file (or partition, etc.) provide at a specified TCP port.

In principle it is possible to operate on a NBD diskless computer which has a NBD as a single mass storage. However, since the establishment of the connection, an external program is required ( nbd -client ), this is only with concepts such as the init ramdisk to realize a virtual file system, which is kept in RAM and is stored in the kernel itself, so it according to booting is available.

Since the original release of NBD some weaknesses (eg the limit of 4 gigabytes per NBD), there are various extensions that are sometimes called " enhanced NBD " means. However, these are incompatible with the original NBD.

NBD protocol ( since version 2.6)

The protocol is a binary protocol. All Mehrbytewerte sent this in network byte order.

Handshake

First comes an initialization phase, to be replaced in the data between the server and the NBD- NBD client program. This protocol is independent of the NBD driver in the Linux kernel and varies for different NBD implementations.

Version ≤ 2.9.16

Once a client has connected to the NBD server, the server sends the following data structure:

  • Bit 0: There are flags available
  • Bit 1: Device is read-only
  • Bit 2: Device supports " FLUSH " command to empty the write cache
  • Bit 3 and 4: unused
  • Bit 5: Device supports the TRIM command to the file system can inform the block layer vacant

Do not accept the client the identity string or the magic number, it closes the connection. Otherwise, the connection is considered to be successfully built.

Version ≥ 2.9.17

The new handshake protocol uses the IANA - registered port 10809 and another message format that allows the server to offer multiple block devices over a TCP port from which the client can select by name a. In addition, the 32-bit flags were split into two 16-bit parts, which allow to separate and global server device dependent flags.

The client responds with its flags. Since so far no flags are defined, they only consist of 32 zero bits:

The client then sends various options that acknowledged the server according to accepting or rejecting:

So far, three options are defined:

The server responds to an option package with a reply packet:

The following response types are defined so far:

The Aushandelsphase is complete when the server has the option NBD_OPT_EXPORT_NAME positively acknowledged. He then sends the identification data of the exported block device to the client:

  • Bit 0: There are flags
  • Bit 1: Device is read-only
  • Bit 2: Server & device support NBD_CMD_FLUSH command
  • Bit 3: server & device support NBD_CMD_FLAG_FUA flag
  • Bit 4: NBD_FLAG_ROTATIONAL: exported data is located on a rotating medium ( classic hard drive), which the client may have regard to the access pattern on the blocks
  • Bit 5: Server & device support NBD_FLAG_SEND_TRIM - Kommand

Data phase

The NBD client forwards the information about the size of the block devices, any flags and the open socket via the special system calls to the kernel and exit. The kernel then takes over the further communications via this socket.

The kernel on the client side is now read and write requests (requests) to the server. These have the following package structure:

Write accesses immediately follow on the data to be written. The server responds to each request with a reply ( Reply). This has the following structure:

In responses to read requests immediately follow it the requested data.

598512
de