Installing Linux Kernel Source

Downloading and installing kernel source is different than other package source files. Every distro of Linux is different, and the instructions are sometimes rather hard to find. This article covers the seven distros that I use. I would cover more, but I would need more machines, and a lot more time and patience.

Before tackling the seven disros, I want the following general points that apply to all distros:

  1. For each distro, I will provide the URL for the installation and download instructions. My comments are supplements to the instructions.
  2. I shall follow the general rule that the kernel source should be owned by a non-root user, and be built by a non-root user.
  3. Some distros install the source in the user’s home directory, other in the /usr/src directory. If given a choice, I prefer /usr/src.
  4. Some distros provide instructions for installing the required tool packages, some do not, and some are incomplete. The subject of tools is large enough to deserve a separate article.
  5. The standard approach for kernel source is to start with a base release from kernel.org, and the apply patches from both kernel.org and the distro team to build the source tree for the current release.
  6. I hope you have a lot of free disk space. It takes about 3 gigabytes by the time you finish building the kernel.
  7. Be aware that any drivers installed as separate packages are part of the running kernel’s library. You will have to re-install these drivers for the kernel that you are building.

CentOS 5.4

The “I need the Kernel Source” article in the Wiki How To page provides the instructions for downloading the CentOS kernel source. There are a few steps that are not so obvious regarding <version>/updates/SBRMS versus <version>/os/SPRMS:

  1. The examples show version 5, which is a link to the most current release of CentOS. If you want the kernel for a specific release, your must specify that release (for example 5.2).
  2. When you ask for updates, you only get the patches. To get the base kernel and the patches, you need to specify os.
  3. You must visit http://mirror.centos.org/centos/5/os/SRPMS/ to find the latest kernel version.

Fedora 12

It times past,  the Release Notes for Fedora contained the instructions for installing kernel source. There is now a Wiki article on Building a Custom Kernel.

I had no problems, until I ran the ‘yum-builddep’ command. It failed with an UboundedLocalError message. I posted a new thread on the Fedora Forum. Rather than waiting for an answer, I preceded with the next two steps. When I ran the ‘rpmbuild’ command, it complained about missing the ‘xmlto’ and ‘asciidoc’ commands. I installed them, and the ‘rpmbuild’ command completed without errors.

The ~/rpmbuild/BUILD/kernel-2.6.31 directory contained the source trees for both the Fedora 12 kernel (linux-2.6.31.i686) and the base kernel from kernel.org (vanilla-2.6.31). For other distros, you only have the source tree for the distro.

After I completed the source installation, I did receive a reply to my post on the Fedora Forum. The reply linked to another thread that suggested running the “yum clean all” command, followed by the ‘yum update’ command. I ran the commands, and the results were the same. It appears to be a Fedora 12 bug.

Linux Mint 8

The instructions for installing the kernel source for Linux Mint 8 are the same as those for Xubuntu (see below). Before starting, you need to add two source repositories to the /etc/apt/sources.list file. The resulting file should look like the following:

deb http://packages.linuxmint.com/ helena main upstream import deb-src http://packages.linuxmint.com/ helena main upstream import deb http://archive.ubuntu.com/ubuntu/ karmic main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu/ karmic-updates main restricted universe multiverse deb http://security.ubuntu.com/ubuntu/ karmic-security main restricted universe multiverse deb-src http://security.ubuntu.com/ubuntu/ karmic-security main restricted universe multiverse deb http://archive.canonical.com/ubuntu/ karmic partner deb http://packages.medibuntu.org/ karmic free non-free

After making the changes to the file, you need to run the ‘apt-get update’ command to synchronize the package index files. Now, you are ready to execute the commands for installing the source.

Mandriva 2010

The Manbo Kernels document is the only Mandriva document related to the Linux kernel, and it just covers the various kernel builds available. To install the source, you just need to install the kernel-source-latest package whose version number matches that of the running kernel. When you install the kernel, RPM verifies that all the necessary tools are installed.

The source appears in the /usr/src directory, and is owned by root. You will need to change the user and group of the kernel source tree.

openSUSE 11.2

Outside of the documentation provided in the kernel source, the only openSUSE document for building a kernel is “Configure, Build and Install a Custom Kernel,” which applies to openSUSE 10.3. With openSUSE, the source comes as a package, which the package manager installs in /usr/src. You just need to install the kernel-source package. You may also want to install a different kernel package for the running kernel, other than the default package. By doing so, many of the options may already be set to the values that you want.

The one problem is that the package is owned by root. To avoid using root for modifying and compiling the kernel, you need to change the user and group for the kernel source tree to those of a normal user.

SimplyMepis 8.0

The “Compiling and installing a new kernel” document from the Mepis Linux Wiki provides detailed instructions for building a new kernel. As a point of clarification, you only need to download the source tree that matches your running kernel. You do not need to download the patches, as they are for patching a vanilla kernel to bring that kernel to the current version.

If you added the src group to your list of groups, you will need to change the group for the source tree to the src group.

Xubuntu 9.10

The “Kernel Compile” community document describes three methods for installing the kernel source:

  1. Using git to download the latest development kernel source tree. This is the yet-to-be-released source tree.
  2. This approach uses the ‘apt-get source’ command to retrieve the source tree that matches the running kernel. This method actually starts with a base kernel, and then applies patches to the base. While the instruction don’t mention this until the end, the ‘apt-get source’ command install the source in your current working directory.
  3. The formating of the document mis-numbered this approach as option 1, and not 3. The Old Fashioned Debian Method involves installing a source package with the ‘apt-get install’ command. This approach installs a tar-ball in the /usr/src directory. There is a chance that the kernel package available is older than the running kernel.

I recommend using the second alternative. Just be sure that you are in your home directory before executing the ‘apt-get source’ command. If you run the commands in the order specified, they actually work.

Summary

As I mentioned at the beginning, every distro has its own little twist to downloading and installing the source. The kernel source is always available, it is just a little more difficult to retrieve than the source for applications. While some of the distros included instructions for downloading tools, the next article in the series will cover the steps for verifying that you have the correct tools for compiling the kernel.

pixelstats trackingpixel
  • Share/Bookmark

9 Comments »

  1. Installing Linux Kernel Source Said,

    February 20, 2010 @ 7:49 am

    [...] this link: Installing Linux Kernel Source Рубрика: Разные рубрики | Метки: a-lot-more, article-covers, [...]

  2. Installing Linux Kernel Source | Linux Affinity Said,

    February 20, 2010 @ 8:20 am

    [...] the original here: Installing Linux Kernel Source Posted in: Kernels ADD [...]

  3. Installing Linux Kernel Source | Drakz Free Online Service Said,

    February 20, 2010 @ 10:13 am

    [...] link: Installing Linux Kernel Source Share and [...]

  4. All About PC that connected to internet » Blog Archive » Installing Linux Kernel Source Said,

    February 20, 2010 @ 10:27 am

    [...] More here: Installing Linux Kernel Source [...]

  5. Installing Linux Kernel Source Said,

    February 20, 2010 @ 10:45 am

    [...] Originally posted here:  Installing Linux Kernel Source [...]

  6. Links 21/2/2010: Thin Clients With GNU/Linux, OpenStreetMap Helps in Haiti | Boycott Novell Said,

    February 21, 2010 @ 6:43 pm

    [...] Installing Linux Kernel Source [...]

  7. Me Said,

    April 18, 2010 @ 10:41 am

    Linux Mint 8:

    deb-src http://packages.linuxmint.com/ helena main upstream import

    Error in Line 2:
    command not found

  8. Bill Anderson Said,

    April 23, 2010 @ 2:27 pm

    This in not a command-line. The list shows you the lines that must be in the /etc/apt/sources file.

  9. Peter Krikels Said,

    June 25, 2010 @ 4:38 am

    cool :-)

Leave a Comment