Preparing your Mandrake kernel source

Intro

You want to build a new hardware driver? Build VMware hooks? NVidia binary-only drivers? If so, then you will need to install your kernel's source code.

But installing the kernel source is just the first step. It must also be correctly prepared to match your exact running kernel. Failure to correctly prep your source would cause your new module to be built with the wrong options.

You'll need the kernel-source rpm, which is on CD3. If you don't have CD3, then you should remove it as a urpmi source add an ftp/http "main" source. 'urpmi.removemedia cdrom3' and see the urpmi faq on this site for directions on adding an online source.

Note: Mandrake 10.1 uses kernel-source-2.6 instead of kernel-source. In the interests of avoiding excess verbage, I will only use kernel-source throughout this page. Please substitute if you are using mdk10.1 or later.

Note: Mandrake 9.2 doesn't have kernel-source on CD3, it's only available from the mirrors.

There are several kernel rpms that are built from the same source, and only one kernel-source package. For example, kernel-source-2.4.21-0.28mdk is the correct kernel-source for kernel-2.4.21.0.28mdk-1-1mdk, kernel-smp-2.4.21.0.28mdk-1-1mdk, and kernel-enterprise-2.4.21.0.28mdk-1-1mdk.

kernel-source

It is absolutely imperative that your kernel-source package matches your running kernel. It is also important that you are using the latest packages for both. To do this, make sure you've added an "update" source to urpmi, that it is current (with urpmi.update). 'urpmi kernel-source will install the latest kernel source. But kernel packages are trickier, run 'urpmi -y kernel' to list all kernel-related packages, look for the latest and urpmi it (for example, 'urpmi kernel-2.4.22.0.25mdk').

Check the version of your kernel-source package with 'rpm -q kernel-source'. Check the version of all installed kernels with 'rpm -qa | grep kernel'. Check your running kernel with 'uname -r'.

Note: Mandrake 10.1 uses kernel-source-2.6, not kernel-source.

Note: Mandrake 10.0 kernels are sometimes missing an important symlink: 'ln -s /usr/src/linux-version /lib/modules/`uname -r`/build'.

Note: Mandrake 9.2 apparently forgot to put the kernel-source on the download ISOs!! Your only choice is to download it from the mdk mirrors. The best thing is to correctly configure your urpmi sources. Users with proprietary NIC drivers, like Nforce2, are kind of screwed here... you'll need to download the kernel-source rpm to another machine, burn it to a CD, and sneakernet it to your mdk machine.

Instructions

$ su -
# urpmi gcc glibc-devel
# urpmi kernel-source-2.6 (mdk10.1 and later)
# urpmi kernel-source (mdk10.0 and earlier)
# urpmi kernel-headers (additional package for mdk9.0 and earlier)
# cd /usr/src/linux
# make mrproper
# cp /boot/config-`uname -r` .config
# vi Makefile (set the EXTRAVERSION to what you want (see below))

For 2.4 kernels:
# make oldconfig
# make dep
# make include/linux/compile.h

For 2.6 kernels:
# make oldconfig
# make include/linux/version.h
# make include/asm
# make scripts

If kernel-source didn't install, see the first paragraph on this page

EXTRAVERSION

EXTRAVERSION deserves a little more comment. At the top of the Makefile, 4 variables are set, VERSION, PATCHLEVEL, SUBLEVEL, and EXTRAVERSION. The first 3 denote the exact version of your source code. You should never change these values. But the last denotes the version of the kernel build. These 4 values get concatenated together to produce your kernel's name. You can get your current kernel's name with 'uname -r', which could look like "2.4.21-0.13mdk", "2.4.21-0.13mdksecure", "2.4.21-0.13mdksmp", or "2.4.21-0.13mdk_garricks_build_005". Everything from the "-" is the EXTRAVERSION.

The kernel's name is important. Modules check the version name before they are loaded, modules are stored in a directory with the kernel name, the system map is stored with the kernel name, and other important things.

If you are preparing your source to build a module for your existing kernel, then setting EXTRAVERSION is very important, and sometimes slightly tricky. You want to remove "VERSION.PATCHLEVEL.SUBLEVEL" from your kernel's uname and put the rest in EXTRAVERSION. For example, if you are running 2.4.21-0.13mdksecure, then you would set EXTRAVERSION to "-0.13mdksecure". If you are running 2.6.8.1-12mdk-i586-up-1GB, then it should be ".1-12mdk-i586-up-1GB". Often, you can just remove the "custom".

If you are building a whole new custom kernel for yourself, be sure to set a unique EXTRAVERSION so that your new kernel doesn't clobber your existing kernel. My personal convention for new kernels is to set EXTRAVERSION to "-XXmdk-YYgs", where XX is the mdk version, and YY is my own version number.

After changing the EXTRAVERSION, run 'make clean' and 'make dep'. (clean isn't necessary above because we just ran mrproper, which is a super clean) (make dep is no longer used for 2.6 kernels).

Kernel package naming

Ever wonder why 'rpm -q kernel' doesn't work when 'rpm -qa | grep kernel' shows several packages?

Kernel naming is tough. It's hard to make a consistent naming system that easily progresses from the kernel.org release, through the source packages, re-releases, bug fixes, the kernel-source package, and the various binary builds.

First, we have the original tarball from kernel.org, which might be called something like "linux-2.6.8.tar.gz". Then you have the patch level, which could be rc3, pre4, or anything else Linus does that day. Then you have the Mandrake developers' release which is a number with "mdk". That gives you something like 2.6.8-20mdk

Unfortunately, rpm doesn't allow "-" characters in the version string, so it gets collapsed into 2.6.8.20mdk.

Since rpm doesn't like having duplicate package names installed at the same time, and users obviously need more than one kernel package, the Mandrake developers put the version into the name field; you get a _name_ of "kernel-2.6.8.20mdk" with a version of 0 or 1.

*still working on this section*

Why?

Everyone eventually asks why the kernel source doesn't come already prepared for the binary kernel and why this must be done manually. The answer is that MDK builds several kernels from the same kernel.src.rpm. These kernels include the normal kernel, smp, enterprise, secure, and boot. The kernel-source rpm also comes from the same kernel.src.rpm. So I ask you, if the kernel-source rpm should be pre-prep'd, for which binary kernel should it match?

At any rate, you only need to do this once, and it is very easy.

Back to Top level page

Flames and well-wishes to garrick@speculation.org
All content is © 2002-2004 Garrick Staples,
Registered Linux User #264142.
Valid XHTML 1.1! Cynthia Tested! Valid CSS!
Created with Vim! Powered by Mandrake!