Tuesday, July 10, 2007

steps to compile a debian kernel

DebianKernelCompileSteps

These following steps to compile a Linux kernel for Debian are taken from steps published on the web by Falko Timme [at] falkotimme [dot] com. I modified his steps for grub. He originally used lilo.


Be aware that there is some risk in compiling your own kernel! For example, it could happen that your machine does not boot properly after you have installed the new kernel so you might be forced to boot from a rescue CD to repair your system. You have been warned! This document comes without warranty of any kind!



Prepare Your Current Machine


First login to your Debian machine on the command line as root. Install the prerequisites that we need to compile and run a new kernel. At the command line execute the following:

apt-get update
apt-get install kernel-package ncurses-dev fakeroot wget bzip2 module-init-tools initrd-tools procps

If you are asked the following question:

"If you really want to remove modutils type 'yes':"

type yes.

It might also be necessary to update packages like bind9, quota, etc. - depending on your configuration. If you have problems with your existing packages try to get the appropriate package from www.backports.org.



Get the Kernel Source


Then go to /usr/src:

cd /usr/src

Then get the latest Linux kernel source (or the kernel source you need) from http://www.kernel.org/pub/linux/kernel/v2.6/:

wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.8.1.tar.bz2



Unpack the kernel sources:


tar xjf linux-2.6.8.1.tar.bz2

cd linux-2.6.8.1/



Configure the Kernel


It is normally a good idea to take the configuration of your existing (working!) kernel 2.6 as a starting point for the configuration of your new kernel. Usually the current kernel configuration is saved in a file under /boot, e.g. /boot/config-2.6.3. We will load this configuration and then do the changes we desire.

make menuconfig

Select Load an Alternate Configuration File and enter the location of the configuration file of your current kernel (or upload my kernel configuration to your machine and enter its path):

The configuration of your current kernel will be loaded, and you can now browse through the menu and change the configuration to suit your needs. When you are finished, save your new kernel configuration:

Then run the following commands (please note that make dep is not needed any more for kernel 2.6):

make-kpkg clean
fakeroot make-kpkg --revision=custom.1.0 kernel_image


If the compilation stops with an error, run

make clean

and then re-run the previous commands starting with

make menuconfig

Change the kernel configuration where the error occurs. If no error occurs you will find the new kernel as a Debian package called kernel-image-2.6.8.1_custom.1.0_i386.deb under /usr/src.

cd ../



Install Your New Kernel


dpkg -i kernel-image-2.6.8.1_custom.1.0_i386.deb

Create a ramdisk of your new kernel (otherwise your system will most likely not boot):

cd /boot/
mkinitrd -o /boot/initrd.img-2.6.8.1 2.6.8.1



Edit Grub List


We are almost finished now. Edit the Grub stanza in /boot/grub/menu.list and add the line initrd /boot/initrd.img-2.6.8.1.

title Debian GNU/Linux, kernel 2.6.8.1
root (hd0,0)
kernel /boot/vmlinuz-2.6.8.1 root=/dev/hda1 ro
initrd /boot/initrd.img-2.6.8.1
savedefault

title Debian GNU/Linux, kernel 2.6.8.1 (single-user mode)
root (hd0,0)
kernel /boot/vmlinuz-2.6.8.1 root=/dev/hda1 ro single
initrd /boot/initrd.img-2.6.8.1
savedefault


Reboot Your Machine

reboot

and if everything is ok your machine should come up with the new kernel. You can run

uname -a

to verify that. Good luck!

No comments: