Getting NBD (Network Block Device) Back in RHEL 7.x, CentOS 7.x, RHEL 6.x and CentOS 6.x

The quick and dirty way:

  1. Download SRC rpm for kernel you want to build module for
  2. Run `rpmbuild -bp kernel.spec`. While the magic is happening here go `make pbnj` or read the latest copy of 2600…oh wait thats not printed any more..crap.
  3. Next go to your your kernel build directory `cd /root/rpmbuild/BUILD/kernel-$(uname -r | sed ‘s/.x86_64//’)/linux-$(uname -r)`
  4. type `make menuconfig`
  5. Go to “Device Drivers | Block devices” and set “M” on “Network block device support” exit saving new kernel config.
  6. Next type `make prepare && make modules_prepare && make` (make is needed otherwise you are missing symbols that the nbd.ko needs)
  7. If your system is older, now is the time to take your significant other to dinner, catch up on some online gaming,  or play with your kids.
  8. Next we build just the block device modules by typing`make M=drivers/block`
  9. We now check the module ` modinfo drivers/block/nbd.ko` if all looks good we copy it to the running kernels extra folder in /lib/modules/$(uname -r)/extra.
  10. We can finally now load the module via `depmod -a && modprobe nbd`.

I will be doing some testing on NBD vs GlusterFS in a coming post. The one kicker is that the NBD and GlusterFS servers will be running on a RazPi’s with a 2G USB thumbdrive for the exported block device (thanks to the vendors at conferences!) .

6 Comments

  1. Paul says:

    hi,
    I stuck without nbd on a old (6.4) ;-) centos box while being in a rush, this quick reminder helped me out – so thank you very much!

    Just to mention as it may be usefull for someone:
    it may be easier to use –target to rpmbuild like:

    rpmbuild -bp –target=$(uname -m) SPECS/kernel.spec

    on centos 6.4 the path to source would be acctually in

    rpmbuild/BUILD/kernel-2.6.32-358.14.1.el6/linux-2.6.32-358.14.1.el6.i686

    also, it looks like you have a small typo in depmod: ‘demod -a’ -> ‘depmod -a’

    thank you!

  2. MisterX says:

    Thanks for the pointers and typo correction Paul ! Also glad to see I am not the last person left wanting to use nbd on RHEL6 ;)

  3. Michael says:

    Huge help with these instructions. Saved me a ton of time. Thanks a lot man. =)

  4. Awesome. nbd is essential for environments heavy on virtualization; qemu-nbd + nbd lets you setup a block device for almost any virtual disk; this allows you to fix, say, a corrupted root filesystem for a guest easily.

  5. VladStar says:

    Thanks for the article – worked like a charm!

  6. MisterX says:

    I am glad to see I am not the only person who see NBD as a very useful tool ! Thanks for the feedback folks!

Leave a Reply