Skip to main content
In this lesson, you’ll learn how to mount remote block devices using Network Block Devices (NBD). This method allows your local system to access a storage device that physically resides on a different machine, thereby extending storage capabilities across your network. Special files in Linux typically reference local storage devices. For example, /dev/sda or /dev/vda represents the entire first storage device, while /dev/sda1 or /dev/vda1 refers to a specific partition on that disk.
The image illustrates network block devices, showing storage devices linked to special files, with paths like /dev/sda or /dev/vda for the entire first disk and /dev/sda1 or /dev/vda1 for the first partition.
NBDs function similarly to local block special files; however, they map remote storage devices over the network. Consider the following scenario with two servers:
  • Server 1 has two storage devices: /dev/vda and /dev/vdb.
  • Server 2 also provides two storage devices with similar identifiers.
With NBD, Server 1 can seamlessly incorporate a third disk that physically resides on Server 2. The NBD tools create a special file (e.g., /dev/nbd0), which applications treat as a standard block device, while all read and write operations on /dev/nbd0 are transparently forwarded to the actual block device (e.g., /dev/vdb) on Server 2.
The image illustrates a network block device setup between two servers, showing the connection and mapping of disks between Server 1 and Server 2. Server 1 has two disks and an NBD disk, while Server 2 has two disks, with arrows indicating data flow between them.
Below, we cover how to configure both the NBD server (the system that shares its block device) and the NBD client (the system that connects to and uses the remote block device).

Configuring the NBD Server

Follow these steps on the server that will export the block device:
  1. Use the package manager to install the NBD server:
Use the package manager to install the NBD server:
A sample output could be similar to:
  1. Open the configuration file using your preferred text editor:
Open the configuration file using your preferred text editor:
By default, the NBD daemon runs as the user nbd, which might not have access to block devices like /dev/sda. The configuration contains comments guiding you to run the daemon as root if necessary. You can either explicitly set the user and group as root or comment out these lines entirely. For instance:
In this example, the export definition under [partition2] specifies that /dev/sda1 will be shared. Make sure the device path matches your intended configuration.
  1. Save your changes and restart the NBD server to apply the new configuration: …
Save your changes and restart the NBD server to apply the new configuration:
For more configuration options, consult the manual:
This manual details generic and export-specific settings.
The image shows a section of a manual page for "nbd-server" with options for configuration, including "allowlist," "cacertfile," "certfile," and "force_tls," each with descriptions and usage details.

Configuring the NBD Client

On the client machine where you want to access the remote block device, complete the following steps:
  1. Install the NBD client utilities:
Install the NBD client utilities:
Sample output might look like:
  1. To support remote block devices, load the necessary kernel module:
To support remote block devices, load the necessary kernel module:
This module will load for the current session only. To load it automatically at boot, add it to the modules configuration:
Then insert the following line:
Save and exit the file.
  1. Establish an NBD connection by specifying the server’s IP and the export name…
Establish an NBD connection by specifying the server’s IP and the export name with the -N option (for example, partition2):
The expected output might look as follows:
The special file /dev/nbd0 now represents the remote block device. Every operation on /dev/nbd0 is forwarded to the designated block device on the server.
  1. Treat the remote block device like any local one
Treat the remote block device like any local one. For instance, mount it to the /mnt directory:
A sample listing might display the files on the mounted block device:
  1. When it’s time to disconnect the remote device, follow these steps:
    • **U…
When it’s time to disconnect the remote device, follow these steps:
  • Unmount the file system:
  • Verify block device status:
    The output should show /dev/nbd0 with a non-zero size.
  • Detach the NBD connection:
Running lsblk again should indicate that /dev/nbd0 now has a zero-byte size, confirming successful detachment.An example session might be:
  1. To view all available exports on the NBD server, use the -l option:
To view all available exports on the NBD server, use the -l option:
Example output:
This capability is enabled by the allowlist = true setting in the generic section of the NBD server configuration.

Summary

In this lesson, you learned how to export a local block device using an NBD server and connect to it remotely via an NBD client. Here’s a quick reference table summarizing the process: This completes the core concepts of using Network Block Devices. Armed with these instructions, you can now export local block devices from one server and mount them remotely on another. Let’s move on to our next lesson.

Watch Video