[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ next ]
To get the Debian kernel source at the current maximum patchlevel, it is sufficient to install the latest linux-source-version package and unpack the source, for example:
# apt-get install linux-source-2.6.18
$ tar jxf /usr/src/linux-source-2.6.18.tar.bz2
The unpacked source tree then will be available in linux-source-2.6.18 directory.
In order to get the Debian kernel source at the patchlevel different from the one provided by the current linux-source-version package, one should first install and unpack it, then roll back the unneeded patch sets using a script from the linux-patch-debian-version package. We assume that in the steps mentioned in the previous example the version 2.6.18-8 of the linux-source-2.6.18 package was installed and unpacked, so that the Debian kernel source at patchlevel 8 is available in the linux-source-2.6.18 directory. It can then be rolled back to the desired patchlevel (1 in the example below) by running
# apt-get install linux-patch-debian-2.6.18
$ cd linux-source-2.6.18
$ /usr/src/kernel-patches/all/2.6.18/apply/debian 2.6.18-1
The last command will unapply the set of patches, which lead from patchlevel 1 to patchlevel 8 and the resulting tree will appear as if it came from the version 2.6.18-1 of the linux-source-2.6.18 package. This system ensures that the source code for any revision of the Debian kernel source may be recovered from the latest one, without keeping multiple copies of the source in the archive.
The version version-N (like 2.6.18-8) of the linux-patch-debian-version package contains all the individual patches applied to the source to achieve any patchlevel up to N. They are stored in the directory /usr/src/kernel-patches/all/version/debian/.
To locally build a kernel image identical to the one distributed in the Debian archive use the following procedure:
This will download and unpack the linux-major source package, making the tree available in the linux-major-version directory. As always, the revision part of the version of this package (for example, 8 in 2.6.18-8) will determine its patchlevel with respect to the original upstream kernel source.
The last two commands will install the build dependencies required by the kernel build process.
The last command will start the kernel build and should result in creation of the kernel packages, identical to the official ones in the original directory (in which the source package was unpacked). It is possible to specify the targets binary-arch or binary-indep targets instead of the binary, if only architecture-dependent (such as the linux-image) or architecture-independent packages are required. It is possible to further restrict the build to only the desired flavours of the kernel images by invoking the individual targets directly. For example, to build only the binary packages for 686 flavour on i386 architecture, use the following commands:
$ fakeroot debian/rules debian/build debian/stamps
$ fakeroot make -f debian/rules.gen binary-arch-i386-none-686
The target in the last command has general form of target-arch-subarch-flavour. Replace the subarch with none if it is empty.
It is possible to apply extra patches to the tree before starting the build. To do that, before invoking the binary or binary-arch target, use the setup target to unpack the tree and prepare it for a build:
$ fakeroot debian/rules debian/build debian/stamps
$ fakeroot make -f debian/rules.gen setup-i386-none-686
This will unpack the kernel tree in the debian/build/build-i386-none-686 directory, where the extra patches may be applied. After that the binary or binary-arch target may be invoked to complete the build, as described above.
This section describes the simplest possible procedure to build a custom kernel the "Debian way". It is assumed that user is somewhat familiar with kernel configuration and build process. If that's not the case, it is recommended to consult the kernel documentation and many excellent online resources dedicated to it.
The easiest way to build a custom kernel (the kernel with the configuration different from the one used in the official packages) from the Debian kernel source is to use the linux-source package and the make-kpkg command, provided by the kernel-package package. First, prepare the kernel tree:
# apt-get install linux-source-2.6.18
$ tar xjf /usr/src/linux-source-2.6.18.tar.bz2
$ cd linux-source-2.6.18
The kernel now needs to be configured, that is you have to set the kernel options and select the drivers which are going to be included, either as built-in, or as external modules. The kernel build infrastructure offers a number of targets, which invoke different configuration frontends. For example, one can use console-based menu configuration by invoking the command
$ make menuconfig
Instead of menuconfig one can use config (text-based line-by-line configuration frontend) or xconfig (graphical configuration frontend). It is also possible to reuse your old configuration file by placing it as a .config file in the top-level directory and running one of the configuration targets (if you want to adjust something) or make oldconfig (to keep the same configuration). Note that different frontends may require different additional libraries and utilities to be installed to function properly. For example, the menuconfig frontend requires the ncurses library, which at time of writing is provided by the libncurses5-dev package.
After the configuration process is finished, the new or updated kernel configuration will be stored in .config file in the top-level directory. Once it's in place, you need to decide whether you want a kernel with or without initrd/initramfs support. See Managing the initial ramfs (initramfs) archive, Chapter 6 for details on what initrd is. If you decide to go for a initrd-enabled kernel, it should include the initrd support in its configuration. The build for a non-initrd kernel is started using the commands
$ make-kpkg clean
$ fakeroot make-kpkg --revision=custom.1.0 kernel_image
The custom.1.0 part in this command is the version identifier, which will get appended to the kernel package name. Feel free to adjust it to your liking. For an initrd-enabled kernel add an extra --initrd argument to the second command:
$ make-kpkg clean
$ fakeroot make-kpkg --initrd --revision=custom.1.0 kernel_image
As a result of the build a custom kernel package linux-image-2.6.18_custom.1.0_i386.deb (name will reflect the version of the kernel and the revision chosen in the command line above) will be created in the directory one level above the top of the tree. It may be installed using dpkg as any other package:
# dpkg -i ../linux-image-2.6.17_custom.1.0_i386.deb
This command will unpack the kernel, generate the initrd if necessary (see Managing the initial ramfs (initramfs) archive, Chapter 6 for details), and configure the bootloader to make the newly installed kernel the default one. If this command completed without any problems, you can reboot using the
# shutdown -r now
command to boot the new kernel.
For much more information about make-kpkg, bootloaders and their configuration please check their documentation, which can be accessed using the commands man make-kpkg, man lilo, man lilo.conf, man grub, and so on. You can also look for documentation in the /usr/share/doc/package directories, with package being the name of the package involved.
Building a kernel from the "pristine" (also sometimes called
"vanilla") kernel source, distributed from www.kernel.org and its mirrors, may be
occasionally useful for debugging or in the situations when a newer kernel
version is desired. The procedure differs only in obtaining the kernel source:
instead of unpacking the kernel source from Debian packages, the
"pristine" source is downloaded using your favourite browser or using
wget, as follows:
$ wget http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.19.tar.bz2
The integrity of the downloaded archive may be verified by fetching the corresponding cryptographic signature
$ wget http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.19.tar.bz2.sign
and running the command (gnupg package must be installed):
$ gpg --verify linux-2.6.19.tar.bz2.sign
Successful verification results in output similar to the one below:
gpg: Signature made Wed 29 Nov 2006 02:50:07 PM PST using DSA key ID 517D0F0E
gpg: Good signature from "Linux Kernel Archives Verification Key <ftpadmin@kernel.org>"
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: C75D C40A 11D7 AF88 9981 ED5B C86B A06A 517D 0F0E
After that the archive may be unpacked using
$ tar xjf linux-2.6.19.tar.bz2
$ cd linux-2.6.19
The unpacked kernel tree (in linux-2.6.19 now has to be configured. The existing configuration file may be used as a starting point
$ cp /boot/config-2.6.18-3-686 ./.config
After the configuration with one of the configuration frontends (invoked by make oldconfig, make config, make menuconfig, etc) is completed, the build may be started using make-kpkg command as described above.
Some kernel modules are not included in the upstream or Debian kernel source, but are provided as third-party source packages. For some of the most popular out-of-tree modules, the binary Debian packages with modules built against the stock Debian kernels are provided. For example, if you are running stock Debian kernel 2.6.18-3-686 (use the uname -r command to verify the version) from the linux-image-2.6.18-3-686 package, and would like to use the squash filesystem, all you need to do is install squashfs-modules-2.6.18-3-686 binary package, which provides the neccessary binary kernel modules.
If you are not so lucky, and there are no binary module packages in the archive, there is a fair chance that the Debian archive contains the packaged source for the kernel modules. Names of such packages typically end in -source, for example squashfs-source, thinkpad-source, rt2x00-source and many others. These packages contain debianized source code of the kernel modules, suitable for building using the module-assistant (or m-a) script from the module-assistant package. Typical sequence to build a custom binary module package, matching a kernel 2.6.18-3-686 (as returned by uname -r) from the debianized source consists of the following steps:
Install a set of kernel headers, matching the kernel for which the modules are going to be built:
# apt-get install linux-headers-2.6.18-3-686
Install the package containing the source:
# apt-get install squashfs-source
Invoke module-assistant (aka m-a) to do the heavy lifting:
# m-a build squashfs
As a result, a Debian package is going to be built and placed in /usr/src. It can be installed the usual way, using dpkg -i. Two last steps (building and installation) may be combined using the invocation
# m-a auto-install squashfs
Check out the module-assistant documentation (man module-assistant) for other options and much more information on how to use it.
Finally, in some rare circumstances, you might need to build the kernel modules from the upstream source packages. In that case, follow the documentation included with the package to build the modules. If the build process will require you to specify the directory with the kernel headers, matching the currently running kernel, for stock Debian kernels this directory is /usr/src/linux-headers-uname, provided by the linux-headers-uname package. Here uname is the output of the uname -r command. If you are building and running your own custom kernels, it is a good idea to keep the original build tree around, as it also can be used for out-of-tree module building.
[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ next ]
Debian Linux Kernel Handbook
version 1.0.1, Wed Jan 24 21:46:35 PST 2007