HowTo Build Debian Linux Kernels, for Linux-2.6
Table of contents |
IntroductionI use Debian Sarge (v3.1) which has a heavily patched Linux 2.6.8 as its default kernel. I would like to run kernel 2.6.12 with Reiser4 or nVidia patches. How can I most easily integrate that into my Debian system? First of all, the best read is without a doubt the document; "Creating custom kernels with Debian's kernel-package system". After you read it, this hyper-abbreviated version is a just cheatsheet. UPDATE: This page is a bit outdated, the nVidia kernel patches used as example here are no longer available from Christian Zander's website. I will soon update this page with a better example, possibly using Reiser4 or some homegrown patch/driver. |
Preparing
Check if you are in the src group. You'll need that to operate in the/usr/src directory, which is where we must work to get all kernel symlinks OK.
jocke@vmlinux:~/> groups users adm dialout cdrom floppy audio dip src gamesIf you just want to make minor changes to the standard Debian kernel you can use the latest kernel-source package. Currently that is kernel-source-2.6.8. The rest of this document uses a standard kernel.org kernel but the text applies to the debian kernel-source as well, only the directory names differ.
First
cd /usr/src
sudo apt-get install kernel-package
Then
sudo apt-get install kernel-source-2.6.8
or
wget http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.12.tar.bz2
After installing the above Debian packages, make sure to edit the file /etc/kernel-pkg.conf to your liking. See kernel-pkg.conf(5) for details.
Next, untar the source and prepare for the patching.
tar xvfj kernel-source-2.6.8.tar.bz2
cd kernel-source-2.6.8
or
tar xvfj linux-2.6.12.tar.bz2
cd linux-2.6.12
- Note #1
- The symlink
/usr/src/linuxto the current kernel source is not necessary anymore. All applications wanting to build against the kernel headers should use the headers that glibc was built against, those headers are in /usr/include/{linux,asm, asm-generic}.
- Note #2
- External kernel modules, however, do need the current kernel headers but they should use the
/lib/modules/`uname -r`/build/includeinclude path, or, for kernel 2.6 use the in-kernel make. See BuildingExternalModules for more info on that.
Patching
Debian has a lot of its kernel patches available as .deb packages. There are also a lot of other patches floating around on the web. In this example we will use one Debian patch and one regular patch.- apt-get install kernel-patch-debianlogo
- (cd .. && wget http://www.minion.de/files/NVIDIA_kernel-1.0-5341-2.6.diff)
- Backing up Makefile: "cp Makefile Makefile.orig"
- Editing it to say 2.6.3 instead of 2.6.12
- Apply patch (below)
- Restore Makefile: "mv Makefile.orig Makefile"
../kernel-patches/all/apply/debianlogoNext are the nVidia kernel patches. Beware of any nVidia kernel gotchas in the kernel configuration step below.
patch -p1 <../NVIDIA_kernel-1.0-5341-2.6.diffNow, I take the Debian config file and let the new source ask about any new features, I simply press enter for each feature since I rely on the kernel default options, unless I see something I like. Optionally I could run the old
make menuconfig, or the new make gconfig (or xconfig), if there is anything I want to change from Debian's defaults.
cp /boot/config-2.6.8-2-k7 .config make oldconfig
Building
Define a suitable version suffix. Note that the/usr/src/linux/include/version.h will be wrong if you don't remember to make-kpkg clean beforehand. See the make-kpkg manpage for a better description of what's going down with that.
Using fakeroot, sudo or running as root (which is not kosher) is required for building the .deb package. This because we want the file owner in the package to be root.
fakeroot make-kpkg clean
time CONCURRENCY_LEVEL=4 CC="gcc-2.95" fakeroot make-kpkg
--initrd --append-to-version=-k7-nvidia-jnn kernel_image
The --initrd flag only works straight off with original Debian kernel sources, with a vanilla kernel you might want to modify /etc/mkinitrd/mkinitrd.conf. Otherwise, simply press enter when you get the CramFS warning.
Time to get some coffee or a beer and watch a DVD episode of Babylon 5!
Results on a fairly decent machine:
real 42m34.965s user 30m31.154s sys 2m34.195s
Installing
Debian has some really neat things. When installing Debian kernels almost everything can be done for you, automatically. Even updating your boot loader, be it Grub or Lilo, and creating a new initrd - Debian takes care of you!
Here is the Grub side of things presented. When installing the kernel image Debian consults the file /etc/kernel-img.conf to see what to do.
/etc/kernel-img.conf:
# Turn off Lilo stuff do_symlinks = no do_bootloader = no # Initrds are OK for GRUB do_initrd = yes # Run cool GRUB stuff postinst_hook = /sbin/update-grub postrm_hook = /sbin/update-grubHere you can see that since it's not Lilo no rewrite of Grub is needed, no symlinks in /, create a new ramdisk (initrd) for me and, best of all, run update-grub to update /boot/grub/menu.lst with the entry for the new kernel. (On removal of a kernel it also runs update-grub to purge stale entries.) Now, all that is left is to install and reboot!
cd .. sudo dpkg -i kernel-image-2.6.12-k7-NVIDIA-jnn_10.00.Custom_i386.deb sudo reboot-- JoachimNilsson - 02 Feb 2005 For refactoring: Would you like to try building your own debian kernel package? Its pretty easy: - apt-get install kernel-package - extract the linux 2.6.12 sources in /usr/src (for example) - apply the patches you would like to include - copy /boot/config-2.6.8 to /usr/src/linux-2.6.12/.config - 'cd /usr/src/linux-2.6.12 && make menuconfig' and add the options you would like to have - make-kpkg --rootcmd fakeroot --revision 1 --initrd buildpackage -- JoachimNilsson - 10 Jul 2005 I just did the following from an Ubuntu linux-source-2.6.12 tree:
cd /usr/src/linux-source-2.6.12/ cp /boot/config-2.6.12* .config make menuconfig make-kpkg --rootcmd fakeroot kernel_image kernel_headers cd .. dpkg -i kernel-*-2.6.12*It should be that simple with everything! -- JoachimNilsson - 14 Nov 2005 Another test with dapper from torvalds 2.6 git
fakeroot make-kpkg clean; time fakeroot make-kpkg --initrd --append-to-version=-jnn --revision=1 configure binary-arch
The original text is Copyright (c) 2004 Matthew McEachen - written April 6, 2004 11:24 PM. This version is only slightly modified.
