NBD (Network Block Device)
Linux kernel module and userspace tools to expose a block device over the network. The server exports a disk image or block device; the client sees it as a local block device (e.g. /dev/nbd0) that can be formatted, mounted, or used as-is.
Packages
# server + client
nix-env -iA nixos.nbd # NixOS
apt install nbd-server nbd-client # Debian/UbuntuServer
# Serve a file as a block device
nbd-server 10809 /path/to/disk.img
# Config file: /etc/nbd-server/config
[generic]
port = 10809
[myexport]
exportname = /var/lib/nbd/disk.img
readonly = falseClient
modprobe nbd # load kernel module (if not auto-loaded)
nbd-client server.host 10809 /dev/nbd0
# Now /dev/nbd0 is available as a local block device
mount /dev/nbd0 /mnt
# ... use it ...
umount /mnt
nbd-client -d /dev/nbd0 # disconnectNixOS server config
services.nbd = {
server = {
enable = true;
exports.myimage = {
path = "/var/lib/nbd/disk.img";
allowAddresses = [ "192.168.1.0/24" ];
};
};
};Use cases
- Diskless/netboot clients with a shared root image
- Live migration of block devices
- Remote disk images for VMs
- Thin provisioning (expose a sparse file as a block device)
Comparison
| NBD | iSCSI | |
|---|---|---|
| Protocol | Simple, Linux-native | Industry standard |
| Auth | IP-based only | CHAP, mutual CHAP |
| Multipath | No | Yes |
| Overhead | Low | Higher |
| Use case | Simple LAN setups | Enterprise SAN |