Hi!

I'm new to this forum, but had to create a Makefile for nbd-client (to utilize the nbd kernel module already existing in Kamikaze 7.09), so I thought I'll share it with You.
I'm using a WRT54GL, so I have the 2.4 kernel version. For this, I needed an older version of the nbd package, 2.7.8 was the highest still compatible version.

include $(TOPDIR)/rules.mk

PKG_NAME:=nbd
PKG_VERSION:=2.7.8
PKG_RELEASE:=1

PKG_BUILD_DIR:=$(BUILD_DIR)/nbd-$(PKG_VERSION)
PKG_SOURCE:=nbd-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@SF/nbd
PKG_MD5SUM:=2450ca676e176a83c797149db0fe9042
PKG_CAT:=zcat

include $(INCLUDE_DIR)/package.mk

define Package/nbd
  SECTION:=utils
  CATEGORY:=Utilities
  DEFAULT:=n
  TITLE:=Network Block Device client and server
  URL:=http://nbd.sourceforge.net/
endef

define Package/nbd/description
  Network Block Device (NBD) utilities
endef

define Build/Configure
  $(call Build/Configure/Default,--with-linux-headers=$(LINUX_DIR))
endef

define Package/nbd/install
        install -m0755 -d $(1)/usr/bin
        install -m0755 $(PKG_BUILD_DIR)/nbd-client $(1)/usr/bin/
        install -m0755 $(PKG_BUILD_DIR)/nbd-server $(1)/usr/bin/
endef

$(eval $(call BuildPackage,nbd))

There's two TAB characters before the words "install", besides that, it's not really important how many spaces you have...

Notice, that I used only nbd-client, but the nbd-server gets built too, and it seems to be working (haven't exported anything with it, but the binary on the router works, --help gives out info, etc.).

I had a small problem with nbd-client, you can't really "-d" an already set up block device, it stays set up, and an nbd-client keeps running. Issuing the command twice and killing the process seems to do the trick.


So how to use it, you might ask:
Let's assume you have some storage space on a Linux server near, and you want to export a large file emulating a block device (or a real partition, or a whole disk - although nbd won't support partitioning it, so you're in super-floppy mode now big_smile ). (EDIT: NEVER and I say __NEVER__ export a mounted filesystem, or use an RW filesystem from more than one client, the result WILL be a smaller disaster - I warned you!)
On the server:
-Create a big file with ext2/ext3 (or whatever you like) filesystem.
-Export it like this: "/bin/nbd-server 300 /home/someone/wrtexport.img"
300 is a custom TCP port you like, the last parameter is the filename.
On the router:
-To set up the block device: "nbd-client 192.168.1.123 300 /dev/nbd/0" (192.168.1.123 is the imaginary server in this example - if you want to swap on this device, then use the -swap parameter too)
-To mount it: "mount /dev/nbd/0 /mnt -t ext3" (ext3 as an example; because Kamikaze likes to mount my ext3 as ext2; wrong search order, had to tell it explicitly...)
-To disconnect:
    umount /mnt
    nbd-client -d /dev/nbd/0
    nbd-client -d /dev/nbd/0
    killall nbd-client

(Last edited by VLsoft on 4 May 2008, 23:48)