public
Description: Network Block Device
Homepage: nbd.sf.net
Clone URL: git://github.com/yoe/nbd.git
nbd /
name age message
file .gitignore Thu Jan 01 04:15:55 -0800 2009 Prepare for github.com releases They have this... [yoe]
file CodingStyle Sat Aug 05 02:21:14 -0700 2006 r176: Add CodingStyle document [yoe]
file Doxyfile.in Mon May 01 06:38:23 -0700 2006 r159: Make this a bit more useful [yoe]
file INSTALL Sun Jun 03 18:13:10 -0700 2007 r255: Oops [yoe]
file Makefile.am Thu Apr 30 05:37:51 -0700 2009 More build fixes these let 'make distcheck' wo... [yoe]
file Makefile.in Sat Oct 17 11:16:13 -0700 2009 Prepare for 2.9.14 [yoe]
file README Thu Jan 01 04:44:46 -0800 2009 Build system fixes and documentation Should ma... [yoe]
file aclocal.m4 Sat Oct 17 11:16:13 -0700 2009 Prepare for 2.9.14 [yoe]
file autogen.sh Mon Aug 24 12:12:21 -0700 2009 Make autogen.sh work Makefile.am expects $(src... [yoe]
file cliserv.h Thu Jan 01 04:44:46 -0800 2009 Build system fixes and documentation Should ma... [yoe]
file config.guess Sat Oct 17 11:16:13 -0700 2009 Prepare for 2.9.14 [yoe]
file config.h.in Tue Aug 04 00:07:49 -0700 2009 Rerun autofoo [yoe]
file config.sub Sat Oct 17 11:16:13 -0700 2009 Prepare for 2.9.14 [yoe]
file configure Sat Oct 17 11:16:13 -0700 2009 Prepare for 2.9.14 [yoe]
file configure.ac Sat Oct 17 11:16:13 -0700 2009 Prepare for 2.9.14 [yoe]
file depcomp Sat Oct 17 11:16:13 -0700 2009 Prepare for 2.9.14 [yoe]
directory gznbd/ Fri Mar 14 05:30:24 -0700 2008 r319: Merge from trunk [yoe]
file install-sh Sat Oct 17 11:16:13 -0700 2009 Prepare for 2.9.14 [yoe]
file lfs.h Sun May 23 02:55:43 -0700 2004 r65: Clean up LFS defines [yoe]
file missing Sat Oct 17 11:16:13 -0700 2009 Prepare for 2.9.14 [yoe]
file nbd-client.8.in Tue May 26 08:45:02 -0700 2009 Apparently forgot this file -- update that one,... [yoe]
file nbd-client.8.sgml Sun May 24 00:14:50 -0700 2009 Update documentation to reflect new behaviour o... [yoe]
file nbd-client.c Fri Oct 16 01:52:18 -0700 2009 Document why this is necessary. [yoe]
file nbd-server.1.in Tue Aug 04 00:07:49 -0700 2009 Rerun autofoo [yoe]
file nbd-server.1.sgml Thu Jul 09 01:51:09 -0700 2009 Documentation update People are sometimes conf... [yoe]
file nbd-server.5.in Tue Aug 18 09:34:55 -0700 2009 Documentation update Sometimes users get confu... [yoe]
file nbd-server.5.sgml Tue Aug 18 09:34:55 -0700 2009 Documentation update Sometimes users get confu... [yoe]
file nbd-server.c Sat Oct 17 11:15:40 -0700 2009 Make -Wall -Werror compile again [yoe]
file nbd-tester-client.c Fri Jun 05 12:43:54 -0700 2009 Avoid unaligned access nbd-tester-client tried... [yoe]
file simple_test Fri Aug 14 01:44:02 -0700 2009 Patches from Debian [yoe]
README
NBD README
==========

Welcome to the NBD userland support files!

This package contains nbd-server and nbd-client. You'll want to run the
client on a machine where you want to use an NBD device, and the server
on a different machine; although it's technically possible to use
nbd-server and nbd-client on the same machine, you may run into some
deadlock issues if you do that[1].

To install the package, please see the INSTALL file. You'll need to
install it on both the client and the server.

Using NBD is quite easy. First, on the client, you need to create the
device nodes:

# cd /dev
# ./MAKEDEV nb0

(if you need more than one NBD device, repeat the above command for nb1,
nb2, ...)

Since there's a problem with nbd and the (default) cfq I/O scheduler,
you may want to set it to deadline:

echo 'deadline' > /sys/block/nbd0/queue/scheduler

(again, repeat the above for nbd1, nbd2, etc, if you need more than one
device)

Next, start the server. You can use a file or a block device for that:

nbd-server <port> <filename>

e.g.,

nbd-server 1234 /home/wouter/nbd-export

Note that the filename must be an absolute path; i.e., something like
/path/to/file, not ../file. See the nbd-server manpage for details on
any available options.

Finally, you'll be able to start the client:

nbd-client <hostname> <port> <nbd device>

e.g.,

nbd-client 10.0.0.1 1234 /dev/nb0

nbd-client must be ran as root; the same is not true for nbd-server (but
do make sure that /var/run is writeable by the server that nbd-server
runs as; otherwise, you won't get a PID file, though the server will
keep running).

Starting with NBD 2.9, there is also support for a configuration file.
This configuration file is expected to be found at
<sysconfdir>/nbd-server/config, and should look something like this:

# This is a comment
[generic]
  # The [generic] section is required, even if nothing is specified
  # there.
  # When either of these options are specified, nbd-server drops
  # privileges to the given user and group after opening ports, but
  # _before_ opening files.
  user = nbd
  group = nbd
[export1]
  exportname = /export/nbd/export1-file
  port = 12345
  authfile = /export/nbd/export1-authfile
  timeout = 30
  filesize = 10000000
  readonly = false
  multifile = false
  copyonwrite = false
  prerun = dd if=/dev/zero of=%s bs=1k count=500
  postrun = rm -f %s
[otherexport]
  exportname = /export/nbd/experiment
  port = 12346
  # The other options are all optional.

The configuration file is parsed with GLib's GKeyFile, which parses key
files as they are specified in the Freedesktop.org Desktop Entry
Specification, as can be found at
<http://freedesktop.org/Standards/desktop-entry-spec>. While this format
was not intended to be used for configuration files, the glib API is
flexible enough for it to be used as such.

The old command-line syntax is still supported, however.

There are packages (or similar) available for the following operating
systems:

Debian (and derivatives, like Ubuntu): "nbd-client" and "nbd-server",
  since Debian woody.
Gentoo: the "nbd" ebuild in the "sys-block" category, available in
  Portage since 2002.
FreeBSD: "net/nbd-server", available in the ports tree since 2003.
  FreeBSD doesn't have kernel support for NBD, so obviously the
  client isn't built there.
SuSE: "nbd", since SuSE 10.0
Fedora: "nbd", since Fedora 7
uClibc's "buildroot" script also seems to have support for NBD.

If you're packaging NBD for a different operating system that isn't in
the above list, I'd like to know about it.

[1] When you write something to a block device, the kernel will not
immediately write that to the physical block device; instead, your
changes are written to a cache, which is periodically flushed by a
kernel thread, 'kblockd'. If you're using a single-processor system,
then you'll have only one kblockd, meaning, the kernel can't write to
more than one block device at the same time.

If, while your kblockd is emptying the NBD buffer cache, the kernel
decides that the cache of the block device your nbd-server is writing to
needs to be emptied, then you've got a deadlock.

A kernel patch exists to create a separate kernel thread for NBD writes
which woul fix this problem; however, it has not made it into mainline
yet.

BUILDING THE SERVER FOR NON-LINUX OPERATING SYSTEMS
===================================================

Since the client requires kernel-side support, you can't just compile
nbd-client on a non-Linux kernel and hope it'll work; you'd have to
write a kernel-space driver before that would be possible.

However, nbd-server assumes nothing more than POSIX and one headerfile
from the Linux kernel. Compiling it can be done as follows:
- Fetch the nbd userland sources, and unpack them. Since you're reading
  this README file, you have already done this step.
- Fetch the "nbd.h" file from /usr/include/linux on a Linux system, or
  from include/linux in the Linux source tree, and store it in the
  toplevel directory of the nbd userland sources
- Edit the headerfile, and remove the line that says '#include
  <linux/types.h>' (on non-Linux systems, the userland source is smart
  enough to figure out how this works by itself)
- now it's just a regular './configure && make && sudo make install'