This guide describes DRBD version 8.4 and above. For 8.3 please look here.


4.3. Building DRBD from source

4.3.1. Checking build prerequisites

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]Note

You should make sure that the gcc you use to compile the module is the same which was used to build the kernel you are running. If you have multiple gcc versions available on your system, DRBD’s build system includes a facility to <link linkend="s-build-customcc">select a specific gcc version.

  • For building directly from a git checkout, GNU Autoconf is also required. This requirement does not apply when building from a tarball.
  • 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 Section 4.3.2, “Preparing the kernel source tree” and continue with Section 4.3.3, “Preparing the DRBD build tree”.
  • 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]Note

On RPM-based systems, these packages will be named similar to kernel-source-version.rpm, which is easily confused with kernel-version.src.rpm. The former is the correct package to install for building DRBD.

"Vanilla" kernel tarballs from the kernel.org archive are simply named linux-version-tar.bz2 and should be unpacked in /usr/src/linux-version, with the symlink /usr/src/linux pointing to that directory.

In this case of building DRBD against kernel sources (not headers), you must continue with Section 4.3.2, “Preparing the kernel source tree”.

4.3.2. 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-version, or simply a symbolic link named /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.

4.3.3. Preparing the DRBD build tree

Any DRBD compilation requires that you first configure your DRBD source tree with the included configure script.

[Note]Note

When building from a git checkout, the configure script does not yet exist. You must create it by simply typing autoconf at the top of the checkout.

Invoking the configure script with the --help option returns a full list of supported options. The table below summarizes the most important ones:

Table 4.1. Options supported by DRBD’s configure script

OptionDescriptionDefaultRemarks

--prefix

Installation directory prefix

/usr/local

This is the default to maintain Filesystem Hierarchy Standard compatibility for locally installed, unpackaged software. In packaging, this is typically overridden with /usr+.

--localstatedir

Local state directory

/usr/local/var

Even with a default prefix, most users will want to override this with /var.

--sysconfdir

System configuration directory

/usr/local/etc

Even with a default prefix, most users will want to override this with /etc.

--with-km

Build the DRBD kernel module

no

Enable this option when you are building a DRBD kernel module.

--with-utils

Build the DRBD userland utilities

yes

Disable this option when you are building a DRBD kernel module against a new kernel version, and not upgrading DRBD at the same time.

--with-heartbeat

Build DRBD Heartbeat integration

yes

You may disable this option unless you are planning to use DRBD’s Heartbeat v1 resource agent or dopd.

--with-pacemaker

Build DRBD Pacemaker integration

yes

You may disable this option if you are not planning to use the Pacemaker cluster resource manager.

--with-rgmanager

Build DRBD Red Hat Cluster Suite integration

no

You should enable this option if you are planning to use DRBD with rgmanager, the Red Hat Cluster Suite cluster resource manager. Please note that you will need to pass --with rgmanager to rpmbuild to actually get the rgmanager-package built.

--with-xen

Build DRBD Xen integration

yes (on x86 architectures)

You may disable this option if you are not planning to use the block-drbd helper script for Xen integration.

--with-bashcompletion

Build programmable bash completion for drbdadm

yes

You may disable this option if you are using a shell other than bash, or if you do not want to utilize programmable completion for the drbdadm command.

--enable-spec

Create a distribution specific RPM spec file

no

For package builders only: you may use this option if you want to create an RPM spec file adapted to your distribution. See also Section 4.4, “Building a DRBD RPM package”.


Most users will want the following configuration options:

$ ./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc --with-km

The configure script will adapt your DRBD build to distribution specific needs. It does so by auto-detecting which distribution it is being invoked on, and setting defaults accordingly. When overriding defaults, do so with caution.

The configure script creates a log file, config.log, in the directory where it was invoked. When reporting build issues on the mailing list, it is usually wise to either attach a copy of that file to your email, or point others to a location from where it may be viewed or downloaded.

4.3.4. Building DRBD userspace utilities

Building userspace utilities requires that you configured DRBD with the --with-utils option, which is enabled by default.

To build DRBD’s userspace utilities, invoke the following commands from the top of your DRBD checkout or expanded tarball:

$ make
$ sudo make install

This will build the management utilities (drbdadm, drbdsetup, and drbdmeta), and install them in the appropriate locations. Based on the other --with options selected during the configure stage, it will also install scripts to integrate DRBD with other applications.

4.3.5. Compiling DRBD as a kernel module

Building the DRBD kernel module requires that you configured DRBD with the --with-km option, which is disabled by default.

4.3.5.1. Building DRBD for the currently-running kernel

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.

4.3.5.2. Building against precompiled kernel headers

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-version/include — the DRBD build process also looks for the kernel Makefile and configuration file (.config), which pre-built kernel headers packages commonly include.

To build against precompiled kernel headers, issue, for example:

$ cd drbd
$ make clean
$ make KDIR=/lib/modules/2.6.38/build

4.3.5.3. Building against a kernel source tree

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

4.3.5.4. Using a non-default C compiler

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

4.3.5.5. Checking for successful build completion

If the module build completes successfully, you should see a kernel module file named drbd.ko in the drbd directory. You may interrogate the newly-built module with /sbin/modinfo drbd.ko if you are so inclined.


This guide describes DRBD version 8.4 and above. For 8.3 please look here.