Before being able to build DRBD from source, your build host must fulfill the following prerequisites:
make, gcc, the glibc
development libraries, and the flex scanner
generator must be installed.
![]() | Note |
|---|---|
You should make sure that the |
If you are running a stock kernel supplied by your
distribution, you should install a matching precompiled
kernel headers package. These are typically named
kernel-dev, kernel-headers,
linux-headers or similar. In this case, you
can skip the section called “Preparing the kernel source tree” and
continue with the section called “Compiling DRBD as a kernel module”.
If you are not running a distribution stock kernel
(i.e. your system runs on a kernel built from source with
a custom configuration), your kernel source files must be
installed. Your distribution may provide for this via its
package installation mechanism; distribution packages for
kernel sources are typically named
kernel-source or similar.
![]() | Note |
|---|---|
On RPM-based systems, these packages will be named
similar to
|
"Vanilla" kernel tarballs from the kernel.org archive
are simply named linux-version-tar.bz2 and should be
unpacked in
/usr/src/linux-, with
the symlink version/usr/src/linux pointing
to that directory.
In this case of building DRBD against kernel sources (not headers), you must continue with the section called “Preparing the kernel source tree”.
To prepare your source tree for building DRBD, you must
first enter the directory where your unpacked kernel sources
are located. Typically this is
/usr/src/linux-,
or simply a symbolic link named
version/usr/src/linux:
cd /usr/src/linux
The next step is recommended, though not strictly
necessary. Be sure to copy your existing
.config file to a safe location before
performing it. This step essentially reverts your kernel
source tree to its original state, removing any leftovers from
an earlier build or configure run:
make mrproper
Now it is time to clone your currently running kernel configuration into the kernel source tree. There are a few possible options for doing this:
Many reasonably recent kernel builds export the
currently-running configuration, in compressed form, via
the /proc filesystem, enabling you
to copy from there:
zcat /proc/config.gz > .config
SUSE kernel Makefiles include a
cloneconfig target, so on those systems,
you can issue:
make cloneconfig
Some installs put a copy of the kernel config into
/boot, which allows you to do
this:
cp /boot/config-`uname -r` .config
Finally, you may simply use a backup copy of a
.config file which you know to have
been used for building the currently-running
kernel.
![]() | Note |
|---|---|
This section only applies to building DRBD as a loadable module. If you want to build DRBD right into your kernel image, you will have to patch your kernel. See the section called “Patching DRBD into the kernel”. Using DRBD as a loadable module is the preferred option. |
After changing into your unpacked DRBD sources
directory, you should now change into the kernel module
subdirectory, simply named drbd, and
build the module there:
cd drbd make clean all
This will build the DRBD kernel module to match your
currently-running kernel, whose kernel source is expected to
be accessible via the /lib/modules/`uname
-r`/build symlink.
If the /lib/modules/`uname -r`/build
symlink does not exist, and you are
building against a running stock kernel (one that was
shipped pre-compiled with your distribution), you may also
set the KDIR variable to point to the
matching kernel headers (as opposed to
kernel sources) directory. Note that besides the actual
kernel headers — commonly found in
/usr/src/linux-
— the DRBD build process also looks for the
kernel Makefile and configuration file
(version/include.config), which pre-built kernel
headers packages commonly include. To build against
precompiled kernel headers, issue, for example:
cd drbd make clean make KDIR=/usr/src/linux-include/athlon
or
cd drbd
make clean
make KDIR=/usr/src/linux-headers-version
If you are building DRBD against a kernel
other than your currently running one,
and you do not have precompiled kernel sources for your
target kernel available, you need to build DRBD against a
complete target kernel source tree. To do so, set the
KDIR variable to point to the kernel
sources directory:
cd drbd make clean make KDIR=/path/to/kernel/source
You also have the option of setting the compiler
explicitly via the CC variable. This is
known to be necessary on some Fedora versions, for example:
cd drbd make clean make CC=gcc32
![]() | Note |
|---|---|
This section only applies to building DRBD into a kernel image, as opposed to compiling it as a loadable module. Only use this if you have a valid reason to, for example if you are building a kernel without loadable modules support. Normally, using DRBD as a loadable module is the preferred option. |
This approach involves having the DRBD build system generate a kernel patch, which you then apply to a kernel source tree. To create the patch, issue these commands:
cd drbd make clean make KDIR=/usr/src/linux kernel-patch
This command will create a file named
patch-linux-.version-drbd-version
You may review this patch and then apply it to your kernel source tree, by issuing the following commands:
cd /usr/src/linux patch -p1 </usr/src/drbd-version/patch-linux-version-drbd-version
![]() | Note |
|---|---|
This example, as all others in this section, assume
that you unpacked you DRBD source tarball in
|
After this, you can run
make config, make menuconfig, or
make xconfig, whichever your preferred way of
configuring your kernel is, and enable DRBD for your build.
For the menu- or GUI-based configuration facilities, you will
find DRBD listed in the "Block devices" section.
After this, you can build your kernel as usual (make
bzImage et al.), and the resulting kernel build will
include DRBD.
With this approach, you will need to build the DRBD userspace management tools separately. This is done by changing into the top-level directory of your unpacked DRBD sources, and issuing the make tools command:
cd /usr/src/drbd-x.y.z make tools