Building DRBD from source

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 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 the section called “Preparing the kernel source tree” and continue with the section called “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 the section called “Preparing the kernel source tree”.

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.

Preparing the DRBD build tree

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

[Note]Note

The information in this section applies to DRBD 8.3.6 and above. Up until release 8.3.5, DRBD had no configure script.

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
--prefixInstallation directory prefix/usr/localThis is the default to maintain Filesystem Hierarchy Standard compatibility for locally installed, unpackaged software. In packaging, this is typically overridden with /usr.
--localstatedirLocate state directory/usr/local/varEven with a default prefix, most users will want to override this with /var.
--sysconfdirSystem configuration directory/usr/local/etcEven with a default prefix, most users will want to override this with /etc.
--with-kmBuild the DRBD kernel modulenoEnable this option when you are building a DRBD kernel module.
--with-utilsBuild the DRBD userland utilitiesyesDisable this option when you are building a DRBD kernel module against a new kernel version, and not upgrading DRBD at the same time.
--with-heartbeatBuild DRBD Heartbeat integrationyesYou may disable this option unless you are planning to use DRBD's Heartbeat v1 resource agent or dopd.
--with-pacemakerBuild DRBD Pacemaker integrationyesYou may disable this option if you are not planning to use the Pacemaker cluster resource manager.
--with-rgmanagerBuild DRBD Red Hat Cluster Suite integrationnoYou should enable this option if you are planning to use DRBD with rgmanager, the Red Hat Cluster Suite cluster resource manager.
--with-xenBuild DRBD Xen integrationyes (on x86 architectures)You may disable this option if you are not planning to use the block-drbd helper script for Xen integration.
--with-bashcompletionBuild programmable bash completion for drbdadmyesYou 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-specCreate a distribution specific RPM spec filenoFor package builders only: you may use this option if you want to create an RPM spec file adapted to your distribution. See also the section called “Building a DRBD RPM package”.

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.

Building DRBD userspace utilities

[Important]Important

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.

Compiling DRBD as a kernel module

[Important]Important

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

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.

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.31/build

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

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

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.