How-to: Install drbd as a kernel module

This how-to is the culmination of discussion at ~~[http://www.linode.com/forums/viewtopic.php?p=19873#19873" target="_blank">](http://www.linode.com/forums/viewtopic. … 9873#19873">http://www.linode.com/forums/viewtopic.php?p=19873#19873](. Lots of credit to irgeek and condate for their help!

Installing drbd as a kernel module should (and sometimes does) go smoothly. However, when I tried to get it running on Debian 5.0 (Lenny) using the current Latest 2.6 series kernel (2.6.18-linode16), I ran into considerable difficulty, mostly based on my inexperience with Linux and kernel/module work. We finally identified the issue as a mismatch between the version of gcc (gcc-4.2) when building the linode16 kernel and the version of gcc (gcc-4.3) installed in Debian 5.0.

Standard instructions

(provided by irgeek, and reproduced - hopefully without error - by me.)

First we grab the necessary tools:

apt-get install build-essential flex bison wget unifdef

Then retrieve the kernel sources and build the kernel. Note that at the time of writing, Linode's latest 2.6 kernel is 2.6.18-linode16, but this should match the kernel selected in your configuration profile in the Linode Manager.

cd /usr/src 
wget http://www.linode.com/src/2.6.18.8-linode16.tar.bz2 
tar -jxf 2.6.18.8-linode16.tar.bz2 
cd 2.6.18.8-linode16 
make -j4

If all went well, we get a final output like this:

Kernel: arch/i386/boot/vmlinuz is ready  (#2)

Next, we need headers and a symlink to /usr/src/linux. Again, make sure you're referencing the kernel source directory you're actually using.

make headers_install 
cd .. 
ln -s 2.6.18.8-linode16 linux

Now we can get the latest drbd sources (8.3.1 as of this writing, but check for yourself) and build our module:

wget http://oss.linbit.com/drbd/8.3/drbd-8.3.1.tar.gz 
tar -zxf drbd-8.3.1.tar.gz 
cd drbd-8.3.1 
make KDIR=/usr/src/linux/

Assuming that went well, we can install the module, insert the module, and verify it's there.

make install 
modprobe drbd 
lsmod
Module                  Size  Used by 
drbd                  257688  0

If everything worked, bravo! But if you end up with this message after your modprobe…

modprobe drbd 
FATAL: Error inserting drbd (/lib/modules/2.6.18.8-linode16/kernel/drivers/block/drbd.ko): Invalid module format

… then clearly we need to do something differently. This is where I was when trying this procedure on Debian 5.0 (Lenny) using the 2.6.18-linode16 kernel. The linode16 kernel I was running was compiled with gcc-4.2, and Debian 5.0 has gcc-4.3 installed. Fail.

First, verify the problem by looking at the tail end of your dmesg:

dmesg | tail 
(clipped)
drbd: version magic '2.6.18.8-linode16 SMP mod_unload Xen PENTIUM4 REGPARM gcc-4.3' should be '2.6.18.8-linode16 SMP mod_unload Xen PENTIUM4 REGPARM gcc-4.2' 

I checked my installed version of gcc (although the dmesg pretty much tells me that it's gcc-4.3):

gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.3.2-1.1' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --enable-cld --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.3.2 (Debian 4.3.2-1.1)

Install gcc-4.2, and change over to it so you can recompile:

apt-get install gcc-4.2 
rm /usr/bin/gcc 
ln -s /usr/bin/gcc-4.2 /usr/bin/gcc 

Go back to the procedure above, and recompile drbd:

cd /usr/src/drbd-8.3.1 
make KDIR=/usr/src/linux/ 
make install

Test to see if it worked. If so, modprobe won't return anything, and lsmod will return the module and size:

modprobe drbd 
lsmod 
Module                  Size  Used by 
drbd                  257688  0

Return to the correct version of gcc:

rm /usr/bin/gcc 
ln -s /usr/bin/gcc-4.3 /usr/bin/gcc 

I'm sure there are other interesting problems one can encounter when trying to install drbd, and I've only covered one here. Fortunately, it's the only one I've encountered.

1 Reply

Amazing code, lsmod return the module and size, it is great, Thanks.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct