Kernel 2.6 On Fedora-based Systems
Up through all Red Hat Linux releases and Fedora Core 1, which subsequently means through Red Hat Enterprise Linux 3, Red Hat included a package entitled kernel-source-ver.i386.rpm. The purpose of this "binary" RPM was to create a /usr/src/linux-ver directory (and associated /usr/src/linux[-2.x] symbolic link). This was the standard kernel location for not only building custom kernels, but where any 3rd party kernel modules (with their own Makefile) could expect to find kernel headers, build-time configuration information, etc...
There were many issues with this approach.
First off, until kernel 2.6, if you wanted to build any 3rd party kernel module -- even one that included it's own Makefile and built systems -- you had to "prep" a kernel source tree that was exactly as your running kernel. This meant applying the correct configuration, the exact Makefile tags, etc... that were often daunting for newer users -- let alone even experienced users. It was more than just the common "build from source" routine of ./configure and make install. And the order was often important as well.
Secondly, the system headers, including C library and other kernel headers, were commonly used by applications as well as kernel building -- especially when different C compilers were being used for the system. Without going into a lot of specifics, it was not long before kernel headers and system headers became separate entities. A major reason being is that some headers and other build-time configuration information might need to be re-created in the kernel build process. In fact, early in Red Hat Linux 7, changes to kernel 2.2's mrproper ("Mr. Proper" is a non-US marketing name for "Mr. Clean") Makefile target resulted in the blowing away many of the system headers.
RPM is a build system and designed as such for a reason. Red Hat Linux and Fedora-based distros (collectively referred to Fedora-based) as well as even other package systems and distros, such as Debian and Debian-based, have used a dedicated, "protected" build environment for kernels for a long time. Starting in Red Hat Linux 6 (well over 6 years ago), Red Hat kernels, modules and other components that have required the kernel source tree have been built from the kernel-ver.src.rpm, and not via a source tree located in /usr/src/linux-ver.
This addresses many issues, including:
1. Include all components to complete a build
2. Ensure exact steps to complete a build
3. Avoid negative affects to files in the production system (chroot)
4. Force documented changes with source, SPEC, etc...
As of Red Hat Linux 7, I personally and professionally stopped building kernels from kernel-source (now kernel-sourcecode as we'll talk about in a bit). The exact order and requirements in not only building but even "prepping" the kernel source tree for 3rd party kernel modules is extremely important. But beyond that, the "mrproper" target can do some particularly nasty things to your systems' /usr/include and other directories. In the kernel.src.rpm build under the chroot, the system's /usr/include and other directories are not touched, and they have their own, self-contained support.
Starting with Fedora Core 2 based on the new kernel 2.6, Red Hat decided to deprecate the "binary" kernel-source-ver.i386.rpm.
At first, they included a new architecture-independent "binary" package name called kernel-sourcecode-ver.noarch.rpm to avoid confusion with the old approach. Mid Fedora Core 2, they considered it redundant to continue doing so and, subsequently, it is not included with Red Hat Enterprise Linux 4 onward either. There is still a "binary" RPM target defined as kernel-sourcecode in the kernel-ver.src.rpm (Source RPM), but Red Hat no loner builds it by default. Redundancy, safety, etc... are major reasons.
To build a "prep'd" kernel 2.6 source tree in FC2+/RHEL4+, you should follow these steps:
1. Download the kernel-ver.src.rpm source RPM (SRPM, .src.rpm) package for your kernel version. If you don't know your kernel version, run `uname -r`. Alternatively, and preferrably, You should use the automated methods of YUM, UP2DATE, etc... to get the correct Source RPM (.src.rpm) of the currently running version of the kernel without any manual checking.
2. Install this package, e.g., rpm -ihv kernel-`uname -r`.src.rpm
3. Prep the kernel source for your architecture, e.g., rpmbuild -bp --target=i686 /usr/src/redhat/kernel-2.6.spec
That will safely prep the kernel in the RPM chroot environment into a mode that is "ready to use" under /usr/src/redhat/BUILD/kernel-2.6*/linux-2.6*/, although you should consult the kernel-2.6.spec file to see what Makefile targets have and have not been run. You may wish to create a symbolic linke to /usr/src/linux-`uname -r` but be careful when executing any Makefile targets in the unprotected, root filesystem of the system.
Even though Red Hat does not build and distribute the kernel-sourcecode-ver.noarch.rpm, any distribution that rebuilds from Fedora Development, Core, Legacy or Red Hat Enterprise Linux kernel-ver.src.rpm may or may not choose to do the same. Some 3rd party rebuilds have decided to include it. Others agree with Red Hat, that it should be deprecated and the chroot RPM system build process be used.
As I eluded to earlier, you can still create a kernel-sourcecode-ver.noarch.rpm package that creates the /usr/src/linux-ver directory for any FC2+/RHEL4+ kernel 2.6 release. The procedure is as follows:
1. and 2., as the previous section.
3. Modify the SPEC file, e.g.,
# vi /usr/src/redhat/SPECS/kernel-2.6.spec
as follows ...
%ifarch noarch
%define builddoc 0
%define buildsource 1
%define buildup 0
...
4. Build the noarch target, which builds kernel-sourcecode
5. Install the "binary" kernel-sourcecode RPM
Now you have your /usr/src/linux-2.6 directory. I highly recommend against building your kernels in the "unprotected" and "root anchored" environment from an arbitrary set of commands (instead of the chroot of RPM with a pre-tested sequence of commands), but that is your choice.
Yes, before kernel 2.6, the location of /usr/src/linux-ver was expected so you could build 3rd party kernel modules. But it was typically safe to to do so, since you're not running the kernel's Makefile. You still typically wanted to "prep" the kernel tree itself in the RPM chroot environment, even if you were only going to symlink it to /usr/src/linux-`uname -r` after doing so. Kernel 2.6 addresses this, which brings me to my next point.
In the kernel modules directory (e.g., /lib/modules/`uname -r`/), there is a subdirectory called build. It points to the headers and other configuration, dependencies, etc... of the running kernel so 3rd party drivers can be built. Before kernel 2.6, this was a symlink to /usr/src/linux-`uname -r`. As of kernel 2.6, this is now static in the kernel itself (taking up a few MBs). The idea here is that you should be able to build 3rd party kernel modules against the current kernel without having to prep a full kernel tree.
Since most newer, 3rd party module Makefiles were already looking to /lib/modules/`uname -r`/build/ to locate the kernel headers, build-time configuration information, etc... As such, the change in kernel 2.6 should be transparent for most newer 3rd party kernel modules with their own Makefile, with exception of the fact that you no longer have to . At the same time, and in the worst case for kernel 2.6, it's often merely just a matter of:
ln -s /lib/modules/`uname -r`/build /usr/src/linux-`uname -r`
You almost never need to "prep" a kernel source tree to build 3rd party kernel modules against it.
Now as of Fedora Core 4 (and accidentally one Fedora Core 3 kernel release), as well as Red Hat Enterprise Linux 4, Red Hat decided to separate kernel 2.6's /lib/modules/`uname -r`/build/ subdirectory from the rest of the kernel modules in /lib/modules/`uname -r`. This new package is known as kernel-devel-ver.*.rpm (where * is the binary architecture, i386, i586, i686, athlon, x86_64, etc...).
So as of Fedora Core 4+ and Red Hat Enterprise Linux 4+, if you want to build 3rd party kernel modules, you need to to install the kernel-devel-ver.*.rpm package so the /lib/modules/`uname -r`/build/ subdirectory is present. A simple yum install kernel-devel or up2date kernel-devel takes care of that for an Internet connected system. By not installing it, you save several MBs of disk space (which may be useful in embedded/read-only systems, etc...), which I'm sure was Red Hat's rationale (since just the binary kernel modules can total less than 10MB in some cases).
