"Who am I? I am but the sum of my experiences..and today I am more than I was yesterday" - Terrabyte
Welcome, I'm assuming that in coming here you've made the decision to have a go at compiling and using a new kernel so I won't go into the numerous reasons to make this decision. Compiling and setting up a kernel for the first time can be a daunting task even for users who are comfortable in everyday Linux use so I hope this guide will make the process a little easier and help get your new kernel up and running as fast as possible. Before I go on I must mention a few things, firstly if you are new to Linux or looking to get started then you are probably in the wrong place. I would recommend going to http://www.linuxiso.org and grabbing one of the distros from there which come with preconfigured kernel source's and nice graphical installers. They contain all you will need and there is a flavour for all users. Secondly, this guide is exactly what it claims to be, "Quick and dirty", (and not in _that_ way you perv :P ). I assume a level of competency with basic Linux commands and the environment. Also I wanted to keep this guide as short as possible so I won't be going into specific parts of the kernel or troubleshooting methods should something go wrong. If you need further assistance (although you shouldn't) check out the references section at the end of this document which explain the process in detail. Now, on with the show.....
- Getting the kernel source
The kernel source can be downloaded from kernel.org. It is best to get one of the major releases (e.g 2.6.15) as opposed to one of the incremental increases between these (e.g. 18.104.22.168). By getting the major release you can patch to any of the incremental releases but you can also patch straight to the next major release (e.g. 2.6.16). This is more difficult if you get one of the incremental releases. Once you have the source move it into /usr/src. Also get the latest patch (at the time of writing this was 22.214.171.124) from kernel.org.
Unzip the kernel source and apply the patch as follows:
- tar jxvf Linux-2.6.15.tar.bz2
- cp -lR Linux-2.6.15 Linux-126.96.36.199
- cd Linux-188.8.131.52
- bzip2 -dc ../patch-184.108.40.206.bz2 | patch -p1 --dry-run
- bzip2 -dc ../patch-220.127.116.11.bz2 | patch -p1
Step (iv) will show the exact same output as step (v) but it doesn't actually touch your kernel source tree. By using the dry-run option it will check to ensure that the kernel patch can be cleanly applied without screwing up your kernel source tree.
- Configuring your new kernel
First you need to determine what type of hardware you have. This can be done using the command 'lspci'
You'll particularly need to know the IDE Chipset, Audio Controller, and the Ethernet Controller. You won't normally need to know your VGA Controller type when compiling the kernel. There are several methods of configuring the kernel with version 2.6
- make config <--similar to 2.4. Most simplistic. Asks you about each option one at a time
- make oldconfig <-- same as above but it uses your current .config file and only asks about new or changed options
- make menuconfig <-- similar to menuconfig in 2.4.
- make xconfig <-- QT based graphical system
- make gconfig <-- Clone of xconfig except using GTK libraries.
We will be using make menuconfig. Its relatively simple to use and doesn't have many requirements. All you need are the ncurses dev files. In my opinion the QT and GTK installers just add unnecessary fluff. On debian a simple apt-get install libncurses5-dev should take care of that.
Now its really just a matter of going through the options an various menus and picking what suits your hardware and set up. If your unsure on anything you can highlight the option your unsure of and press ?. You can chose to compile things directly into the kernel (fill the box beside them with a * by pressing the space bar) or compile them as a module and insert them into the kernel as needed (by filling the box with an M). Certain things that are required to boot the kernel are best to be built in (such as IDE drivers etc) but for other non-critical stuff then its just as good, if not better, to build them as modules. At a later stage if you need to upgrade a driver thats compiled as a module you can just plug it out and insert the new one into the kernel but if its compiled in then a recompile of the kernel will be required.
NOTE: Support for your file system must be built into the kernel not as a module. Select the correct filesystem for the system you are currently running (e.g reiserfs, ext2, ext3 etc)
- Building the new kernel
- sudo make bzImage
Go make a cup of coffee or the beverage of your choice.
- sudo make modules
Again, more drink (Starting to see a pattern? ;) )
- sudo make modules_install
And more drink
If you wanted to minimise interruptions to your drinking time you could do
sudo make bzImage && make modules && make modules_install
You can also combine the make bzImage and make modules by typing 'make'. So the above command would become
make && make modules_install
The above commands can take quiet a while, as in close to an hour. If its a stock kernel from kernel.org (or elsewhere) it will be much faster than any of the distributions as it will have less to compile by default.
The modules will be copied into /lib/modules/KERNELVERSION
- Installing the new kernel
Now its just a matter of copying the newly compiled kernel and System.map into /boot.
For me it looked like this
nnp@mitnick:/usr/src/kernel-source-2.6.8$ sudo mv arch/i386/boot/bzImage /boot/bzImage-2.6.8
nnp@mitnick:/usr/src/kernel-source-2.6.8$ sudo mv System.map /boot/System.map-2.6.8
nnp@mitnick:/usr/src/kernel-source-2.6.8$ ls -al /boot/
drwxr-xr-x 3 root root 456 2006-03-02 21:48 .
drwxr-xr-x 21 root root 624 2006-02-14 11:55 ..
-rw-r--r-- 1 root root 1159283 2006-03-02 21:43 bzImage-2.6.8
-rw-r--r-- 1 root root 44853 2005-05-16 08:46 config-2.4.27-2-386
-rw-r--r-- 1 root root 55399 2005-08-16 14:18 config-2.6.8-2-686
drwxr-xr-x 2 root root 384 2006-02-14 17:02 grub
-rw-r--r-- 1 root root 3780608 2006-02-14 09:06 initrd.img-2.4.27-2-386
-rw-r--r-- 1 root root 4636672 2006-02-14 11:55 initrd.img-2.6.8-2-686
-rw-r--r-- 1 root root 542191 2005-05-16 09:38 System.map-2.4.27-2-386
-rw-r--r-- 1 root root 860742 2006-03-02 21:43 System.map-2.6.8
-rw-r--r-- 1 root root 843060 2005-08-16 16:15 System.map-2.6.8-2-686
-rw-r--r-- 1 root root 816590 2005-05-16 09:38 vmlinuz-2.4.27-2-386
-rw-r--r-- 1 root root 1171142 2005-08-16 16:14 vmlinuz-2.6.8-2-686
- Getting ready to boot
Now that the kernel is in place we just have to edit our boot loaders config file and add the new kernel.
If you are using the grub boot loader (and you probably are) this file is normally in /boot/grub and is called menu.lst. As I'm using Debian I can only guarantee it is there for my particular install. If you're using a different OS then check out its documentation for the correct location. Look at the other entries and copy their structure to add your new kernel to the list. You must be root. Ignore the initrd option as we haven't created one and they aren't normally necessary. For further info on editing your grub config file check out the GRUB manual.
If your boot loader is Lilo then you need to edit /etc/lilo.conf and then as root run /sbin/lilo to write the info to the MBR.