Tina
This HOWTO describes how to compile and install the Linux kernel on Debian systems. The method described in this HOWTO is just one of several approaches one can use and does not claim neither to be the best nor the most effective way to compile the kernel. Although the described method should be safe it's always a good idea to make a backup of important data before doing major changes to the system. This HOWTO is licensed under the terms of the GNU Free Documentation License. It has been written in the hope that it will be useful to the community but it comes with no warranty; use it at your own risk.
Debian GNU/ Linux has a lot of advantages, one of them being the precompiled kernels. This enable users to easily install new kernels without the need to compile. However, sometimes it's necessary to compile a custom kernel and it can seem like a rather daunting task for beginners. But compiling your own kernel is actually not that hard and it is a useful skill to master.
Preparation:
First you'll need to install the necessary tools. You might have some or all of these already installed on your system:
- Code: Select all
# apt-get install kernel-package ncurses-dev bzip2 module-init-tools initrd-tools procps
Getting the kernel source:
There are basically two ways to get the kernel source.
From Debian repositories
From kernel.org
From the Debian repositories:
The preferred method of acquiring the kernel source is from the Debian repositories simply by installing it through apt-get:
- Code: Select all
# apt-get install kernel-source-x.x.x
A note on Debian kernel naming: The 2.4 and 2.6 kernels in Sarge are named 'kernel-source' whereas 2.6 kernels Etch and onwards are named 'linux-source'. So in order to install the source for kernel 2.4.27 you would do:
- Code: Select all
# apt-get install kernel-source-2.4.27
But if you want the source for kernel 2.6.15 you would do:
- Code: Select all
# apt-get install linux-source-2.6.15
The source will then be placed in your /usr/src directory as a bz2 archive. So if you installed the 2.6.15 kernel source you will see:
/usr/src/linux-source-2.6.15.tar.bz2
From kernel.org:
The standard kernel is released on http://www.kernel.org/. Kernel.org holds all kernels that has been released plus all patches. If you require the absolute bleeding edge kernel this is the place to get it. Navigate to the kernel you wish to install and download the bz2 archive. For example the kernel 2.6.15.1 will be downloaded from the URL:
http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.15.1.tar.bz2
If you downloaded the bz2 archive to your home directory or some temporary folder move it, as root, to /usr/src/
Unpack and configure the kernel:
Now you have the compressed kernel source in your /usr/src/ directory and it's time to unpack it. From now on I'll use the 2.6.15 as my sample kernel through out this howto. You will of course have to substitute that for your kernel.
Change to /usr/src/ (cd /usr/src)
Do
- Code: Select all
# ls -la
to verify that the file is indeed where it should be. You should get something like:
-rw-r--r-- 1 root root 39315716 2006-03-06 12:32 linux-source-2.6.15.tar.bz2
So let us unpack our kernel source by entering:
- Code: Select all
# tar xjf linux-source-2.6.15.tar.bz2
This may take a few seconds and when it's done, change to the newly created directory:
- Code: Select all
# cd linux-source-2.6.15
Now we will configure our new kernel. You have basically two different interfaces to choose from; one text based and one X GUI. (There are a few other ways but for most people the two mentioned here is regarded as the most suitable and 'easy')
Use
- Code: Select all
# make menuconfig
for the text based interface or
- Code: Select all
# make xconfig
for a X GUI.
Edit: xconfig require a QT library. If you get an error you probably don't have it installed. Install it with
- Code: Select all
# apt-get install libqt3-mt-dev
Both do the same job so it's just a matter of taste.
This will bring up the kernel configuration screen.
If you already have a working configuration you only want to tweak a bit you can load it by scrolling down to “Load an alternative configuration file” and enter the path (normally /boot/config.x.x.x).
Now you can scroll up and down, changing the settings you want to change. There is a vast amount of things to include in the kernel but that is outside the scope of this howto. There are however lots of information about the Linux kernel both on the web and in books.
Compile and install the new kernel
When you are done configuring the kernel you can use esc to exit. Answer yes to save the new configuration. To start compiling the kernel issue the following commands:
Note: make dep for 2.4.x kernels only!
- Code: Select all
# make dep
- Code: Select all
# make-kpkg clean
# make-kpkg kernel_image
(Alternatively you can add a revision flag that will show with uname -r. If you want the revision flag set you issue the command
- Code: Select all
# make-kpkg --revision=custom.0.1 kernel_image
The revision flag can be whatever you want, just no 'funny' characters and no spaces)
Now you should see a lot of text flickering by on your screen. This is the compile in progress. Please note that compiling the kernel takes quite some time depending on your system (approx 30-60 minutes give or take) so be patient. And if everything goes well you are rewarded with a nice .deb file in your /usr/src/ that will look something like:
/usr/src/kernel-image-2.6.15_i386.deb
Install the kernel:
- Code: Select all
# dpkg -i kernel-image-2.6.15_i386.deb
The kernel will be installed and added to the GRUB bootloader. Now you are basically done unless your system require initrd RAM disk:
- Code: Select all
# cd /boot/
# mkinitrd -o /boot/initrd.img-2.6.15 2.6.15
Open /boot/grub/menu.lst in your favorite editor and add the initrd to the new entry added by the kernel installer:
- Code: Select all
title Debian GNU/Linux, kernel 2.6.15-1-486 (on /dev/hda1)
root (hd0,0)
kernel /boot/vmlinuz-2.6.15-1-486 root=/dev/hda1 ro
initrd /boot/initrd.img-2.6.15-1-486
savedefault
boot
Reboot and select your new kernel.
Remember that your old kernel is preserved so if your new kernel for some reason don't work you can always boot your old kernel and investigate what went wrong.
Enjoy!
Tina
Edit: Adapted to new Etch release.
