3

I am trying to load the nbd network block device on my CentOS7 server. However, I got:

modprobe nbd
modprobe: FATAL: Module nbd not found.

It would be really appreciated if anyone could tell me the best way to have nbd module loaded. And eventually, I hope I can automate this tasks via ansible.

Here is my kernel version:

$ uname -r
3.10.0-327.28.3.el7.x86_64

Thanks!

HDJEMAI
  • 9,436
  • 46
  • 67
  • 93
Lucas H. Xu
  • 909
  • 1
  • 11
  • 23
  • Thanks for commenting. IMHO, I think it is related to development. For example, similar questions such as: https://stackoverflow.com/questions/4839024/how-to-find-the-version-of-a-compiled-kernel-module, https://stackoverflow.com/questions/35525960/trying-to-manage-linux-kernel-modules-modprobe-command and https://stackoverflow.com/questions/225845/how-do-i-configure-modprobe-to-find-my-module. But I appreciate your help with sharing these links and informing me other platforms. :) – Lucas H. Xu Jul 31 '17 at 20:22
  • 1
    Yeah, be careful of gauging the on-topic-ness of your question based on other questions. They are probably off-topic too. The problem is, we (the Stack Overflow community) do a bad job of enforcing site rules. You seem to fallen into a nastier trap - back in 2008 or 2009, the site rules were different; and sites like [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) did not exist. But in case I am wrong, please show the relevant code for the driver, like `insert_mod` and `remove_mod`. – jww Jul 31 '17 at 20:35
  • That's a good point and you are right about rules have changed since then. As for showing the relevant code for the driver, it would be really appreciated if you could elaborate more on that. Maybe a better question title to ask is that how to install network device block on CentOS7? It seems very straightforward to do it on Ubuntu but not CentOS. – Lucas H. Xu Jul 31 '17 at 20:59
  • After solving some of the errors for dependencies and installing rpm-build package (not in rpm package) I was able to add NBD module into the kernel for CentOS 7. Make sure to use proper version on http://vault.centos.org/ – Tripko Nov 29 '19 at 12:29

1 Answers1

7

I found this is useful. Please let me know if this doesn't work for you

uname -r
sudo su
# useradd builder
# groupadd builder
cd /home/centos
# Get Source Code, make sure you check the kernel version first and download the proper version
wget http://vault.centos.org/7.2.1511/updates/Source/SPackages/kernel-3.10.0-327.28.3.el7.src.rpm
rpm -ivh kernel-3.10.0-327.28.3.el7.src.rpm

# Build Preparation
mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros
cd ~/rpmbuild/SPECS
rpmbuild -bp --target=$(uname -m) kernel.spec
cd ~/rpmbuild/BUILD/kernel-3.10.0-327.28.3.el7/linux-3.10.0-327.28.3.el7.centos.x86_64/

# Build
make menuconfig
# Device Driver -> Block devices -> Set “M” On “Network block device support”

make prepare && make modules_prepare && make
make M=drivers/block -j8
modinfo drivers/block/nbd.ko
cp drivers/block/nbd.ko /lib/modules/3.10.0-327.28.3.el7.x86_64/extra/
depmod -a && sudo modprobe nbd

This will enable the nbd on CentOS7

Lucas H. Xu
  • 909
  • 1
  • 11
  • 23
  • 1
    This is very useful, I noticed you imply adding a user `builder` (as it is recommended to not build as root) but it's not explicit that you run the `make` at the end as this user (and where `~/rpmbuild` should be - is it `/root/rpmbuild` or `/home/builder/rpmbuild` ?) – szmoore Oct 24 '17 at 07:02
  • Also as of at least Centos `7.4.1708` and kernel version `3.10.0-693.5.2` you need to install gcc version 6 or greater, instructions here https://stackoverflow.com/questions/36327805/how-to-install-gcc-5-3-with-yum-on-centos-7-2 – szmoore Oct 24 '17 at 07:28
  • Thanks for your comments @szmoore. So if you do want to add the user `builder` (as it is recommended), you should run the `make` under `/home/builder/rpmbuild`. And thanks for posting the link to the instruction for installing `gcc` version >6 – Lucas H. Xu Oct 24 '17 at 13:46
  • 1
    Please note for newer folk who come across this, that as these instructions are pretty old, there is an additional instruction. A bit of NBD's code relies on a old function. So after you do 'make menuconfig', vim or nano or whatever drivers/block/nbd.ko and search for the line that has "REQ_TYPE_SPECIAL" and rename just that part to "REQ_TYPE_DRV_PRIV" and then save and close the file. Then continue with the instruction. – EricDAltman Dec 31 '20 at 05:30