Posted by nevermind on Wed 3 Aug 2005 at 13:05
We've covered building a 2.6 Kernel before in the Debian manner, but here's another introduction in case you missed the last one.
Building a 2.6 Kernel on Debian is rather easy, first we need the kernel sourceto apply this, we run the following command:
aptitude -f install kernel-source-2.6.8
This will fetch the kernel source and all needed tools to compile and configure it from debian.
Next we need to unpack the kernel:
cd /usr/src tar xvfj kernel-source-2.6.8.tar.bz2
This will create a directory called "kernel-source-2.6.8" under /usr/src.
Once the source code is unpackaged we can call the kernel configuration menu:
cd /usr/src/kernel-source-2.6.8/ make menuconfig
(If you receive some an error message rather than a build menu you should run "apt-get install libncurses5-dev").
Now we rather than make sure we've matched our kernel configuration with the correct options we can cheat - and take the kernel configuration file from the currently installed version of the kernel. This is done by using the menu to choose "Load an Alternate Configuration File".
The default 2.6 kernel configuration file of the kernel image that comes with Debian Sarge may be found in the directory "/boot".
Simply load the file "config-2.6.8-*-*", where the first "*" stands for the Debian subversion of the kernel, and the second "*" names your system architecture.
(To find out which kernel you are currently running you can run "uname -a").
If you dont want to change anything on the kernel, but just build your own, you may now exit the configuration menu.
When selecting Exit from the build menu you will be asked to confirm your changes. Ensure you select "yes", or they will be lost.
Now we are going to take a look on the debian specific make command for kernel rebuilds, called "make-kpkg".
make-kpkg is a rather simple program, that takes a few arguments, the most important arguments for our use are:
To proceed further we need to choose which kind of compilation we wish to persue:
Do we want to build the whole package? Just the kernel image? The modules Or just a package containing the headers?
A full list of supported targets can be viewed via the --targets option for make-kpkg.
To just build the kernel image and all that is needed for running the kernel and compile custom modules (e.g. nvidia) into it, we issue the following commands:
make-kpkg --initrd --revision examplerev01 kernel_image
During the build make-kpkg will ask you the following question:
Warning: You are using the initrd option, that may not work, depending on your kernel version and architecture, unless you have applied the initrd cramfs patch to the kernel, or modified mkinitrd not to use cramfs by default. The cramfs initrd patch, is included in the Debian supplied kernel sources. New kernels on most architectures do work fine. By default, I assume you know what you are doing, and I apologize for being so annoying. Should I abort[Ny]?
We can safely answer that question with "N", as we do know what we are doing;)
The compilation will take a while, bout 35 minutes on my 1.2ghz AMD Duron, so go and get yourself some air/coffee/cigarette, and listen to some of your favorite tunes. (If you wish to speed up multiple rebuilds you could look at using ccache, or distcc to build across multiple hosts - if you have more than one machine available to you).
When it finishes we can also conitinue to build a matching kernel-headers package - this is needed if you wish to build some custom kernel modules, such as Nvidia drivers, or the gmail filesystem.
make-kpkg --initrd --revision examplerev01 kernel_headers
That command should complete reasonably quickly, as its just packing the headers, that were already built by the first command.
The results of our build steps will be two files in our /usr/src directory, so lets go back to that directory, and look:
kernel-headers-2.6.8_2.6.8-3examplerev01_i386.deb kernel-image-2.6.8_2.6.8-3examplerev01_i386.deb
To install the packages we can use dpkg:
dpkg -i kernel-image-2.6.8_2.6.8-3examplerev01_i386.deb
Answer the questions it asks you with "Yes".
dpkg -i kernel-headers-2.6.8_2.6.8-3examplerev01_i386.deb
To initialize the initrd image we can run:
mkinitrd /boot/config-2.6.8 2.6.8
Thats it. Now all we need to do is to add our new kernel to our bootmanager, in my case lilo. Open /etc/lilo.conf in your favorite text editor, and add something like this to the menu, in case its not already there:
image=/vmlinuz
initrd=/initrd.img
label=Linux
read-only
optional
(The new kernel installs itself into /boot directory, and will change the symbolic links in / - so that we can refer to it as /vmlinuz, with the old kernel being refered to as /vmlinuz.old.)
Once you've updated your configuration run "lilo -v" to make it active, and reboot your machine.
This article can be found online at the Debian Administration website at the following bookmarkable URL:
This article is copyright 2005 nevermind - please ask for permission to republish or translate.