Linux NBD Tutorial: Network Block Device Jumpstart Guide

by Ramesh Natarajan on February 16, 2009

Network Block Device - NBDThis is a guest post written by Dhineshkumar Manikannan.

Network block devices are used to access remote storage device that does not physically reside in the local machine. Using Network Block Device, we can access and use the remote storage devices in following three ways on the local machine:

  1. SWAP
  2. File System
  3. RAW



NBD presents a remote resource as local resource to the client. Also, NBD driver makes a remote resource look like a local device in Linux, allowing a cheap and safe real-time mirror to be constructed.
You can also use remote machine storage area as local machine swap area using NBD.

To setup the NBD based file system, we need a nbd-server (on remote machine, where we like to access/create the content) and nbd-client (on local machine, where we like to access the remote storage device locally).

I. NBD Server Side Configuration Steps

1. Install nbd-server

If you working on Debian flavor, get the nbd-server through apt-get.

# apt-get install nbd-server

2. Create a file content

Create a file using dd as shown below.

# dd if=/dev/zero of=/mnt/dhini bs=1024 count=36000


Use mke2fs to make the /mnt/dhini as a filesystem.

# mke2fs /mnt/dhini


When you try to make /mnt/dhini as ext2 file system, you may get a warning message as show below. Press y to continue.

/mnt/dhini is not a block special device.
Proceed anyway? (y,n) y

3. Start the NBD Server Daemon

Syntax: nbd-server  port-number   filename/filesystem

# nbd-server 1043 /mnt/dhini


You can also run the nbd-server on multiple ports as shown below.

# nbd-server 1043 1077 1076 /mnt/dhini

You can also specify the timeout to make the server to run N idle seconds

II. NBD Client Side Configuration Steps

Perform the following steps in the client machine, where you like to access the remote storage device.

1. Install nbd-client

If you working on debian flavor, get the nbd-client through apt-get.

# apt-get install nbd-client

2. Using nbd-client create a filesystem on client machine

Syntax: nbd-client  server-ip  server-port#  filename/filesystem

# nbd-client 192.168.1.11 1043 /mnt/dhini

Starting NBD client process: Connecting...Negotiation: ..size = 36000KB
bs=1024, sz=36000
connected /mnt/dhini
Activating...
fsck 1.39-WIP (31-Dec-2005)
/mnt/dhini: Superblock last write time is in the future.  FIXED.
/mnt/dhini has gone 49710 days without being checked, check forced.
/mnt/dhini: |===============================| 56.0%
/mnt/dhini: |===============================| 100.0%


Once it gets to 100%, you will get the block device on your local macine on the same path.

$ls -lh /mnt/dhini
brw-r--r-- 1 root root 43, 0 2009-02-05 17:31 /mnt/dhini


If you face any issues during the NBD configuration process, you may also configure the nbd-server and nbd-client through dpkg-reconfigure.

III. Mount the File System on Client-side

# mkdir /rem_space
# mount /mnt/dhini /rem_space

Once mounted, you may get the directory with “lost+found”. You can start accessing the files and directories properly from this point.

IV. Get Client Changes on Server-side

Mount the nbd filesystem locally

# mount  -o loop /mnt/dhini /client_changes


If you are not using “-o loop” option, you may get the following error:

mount: /mnt/dhini is not a block device (maybe try `-o loop'?)


When you list the /client_changes, You will get all the client created files and directories properly.

V. Access Remote Storage as Local Swap Memory Area

Configuration On Server side:

1. Create a file

# dd if=/dev/zero of=/mnt/dhini bs=1024 count=16000

2. Instead of create a file in ext2 filesystem create it as swap file, using mkswap

# mkswap /mnt/dhini

3. Run the server daemon

# nbd-server 1043 /mnt/dhini

Configuration On Client side:

1. Get the filesystem as swap area

# nbd-client 192.168.1.11 1043 -swap  /mnt/dhini

2. Cross check using “cat /proc/swaps “. This will list the swap areas

$ cat /proc/swaps
Filename    Type       Size      Used    Priority
/dev/hda4   partition  650624     57732  -1
/mnt/dhini  partition  15992    0        -4


This article was written by Dhineshkumar Manikannan. He is working in bk Systems (p) Ltd, and interested in contributing to the open source. The Geek Stuff welcomes your tips and guest articles


Linux Sysadmin Course Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.
Get the Linux Sysadmin Course Now!

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 7 comments… read them below or add one }

1 anonymous February 18, 2009 at 6:14 am

Sloppy.

> # nbd-server 1043 /mnt/dhini
Server uses port 1043
> # nbd-client 192.168.1.11 1077 -swap /mnt/remote
but client 1077?

And I would say the mounted swap partition is /mnt/remote and not /mnt/dhini
> /mnt/dhini partition 15992 0 -4

Plus you forget to mention that using swap over a network is a theoretical possibility but hardly recommendable for practical situations.

2 Sitaram Chamarty February 18, 2009 at 9:16 am

(1) you’ve got /mnt/remote in the nbd-client command, but the output says /mnt/dhini. Typo?

(2) conventionally, /mnt/whatever are used as the mount points (the right side of a mount command), not as loop devices (left side). That’s only a convention but common enough that newbies who see your post *may* get a little confused by your use of /mnt/dhini etc on the *left* side

3 Ramesh February 19, 2009 at 7:55 am

@Anonymous, @Sitaram,

Thanks for pointing out the issues. I’ve updated the following.

1. The port on the nbd-client should be 1043
2. the mount point should be /mnt/dhini

4 thaygiaoth August 18, 2010 at 8:29 pm

Hi Ramesh, before III. Mount the File System on Client-side section, you wrote dbkg-reconfigure not which is not correct, dpkg-reconfigure is more corrcectly

5 Ramesh Natarajan August 18, 2010 at 10:08 pm

@thaygiaoth,

Thanks for pointing out the typo. It is fixed now.

6 Fred February 5, 2014 at 2:04 pm

Way use nbd over iscsi ?

I still like NFS for shares across multiple clients.

7 Fred February 5, 2014 at 2:09 pm

Swap over a network ?

Generally a bad idea ; but cloud computing uses it .

Leave a Comment

Previous post:

Next post: