We know that every operating system has a core, which called kernel. Kernel is a vital component in operating system design, since it is the core and it has a lot of function, such as managing input/output, filesystem, loading modules for additional hardware, and many other functions. Well developped kernel will make the system stable and less vulnerable. This is what happened in GNU/Linux kernel development lead by Linus Torvalds (main kernel) and Chris Wright along with Greg Kroah Hartman (-stable team). They maintain the kernel development process in order to make GNU/Linux sistem operating works better, faster, modern, and also up to date. Up until now, there are two major version in kernel development, 2.4.x and 2.6.x. The stable and development scheme is no longer used. Everything that comes up marked as final version is considered stable version.
Usually, if you have installed a distro (combination of kernel with a lot of collection of utilities and application) like Fedora Core, Mandriva, SuSE, Debian, they have included the kernel, but as the kernel development move on, sometimes you have to upgrade your kernel to the latest version, in order to get new facility, new hardware support, and also bug fix on the previous kernel. The process can be easy or difficult, depends on your skill and also the package you are using. If you use your distro's package (RPM, DEB, and TGZ), the process will be lot easier, since it has been prepared by the developer team and the only thing you have to do is install it and configure your boot loader configuration files. Meanwhile, if you tried to install from the original kernel source (called Vanilla), you have to learn few new things first. The process itself cannot be guarranted as 100% safe, so it's not for newbie or production machines, but in this article i will try to give some small tutorial on how to compile the kernel from source based on my experience with some help from some friends of mine. In this article, i will use Slackware as the main distro.
Slackware 12.1 (the latest version of Slackware as i write this article) by default comes with 22.214.171.124 kernel. This kernel is not very out-of date, since the latest stable version is still 126.96.36.199 (this version will be used in this article). If you want to look how to install the kernel which is shipped with Slackware's CD, please look at my other article Installing Kernel on Slackware. This article will be the next step of that article, as it will try to build the kernel from source, not from the binary packages.
First of all, get the vanilla version of the kernel from the official site for GNU/Linux Kernel. Make sure you download the Full kernel, since there are some version shipped in the page. Next, you need your distro's config file. It will be used as a base to configure your future kernel. You can build it manually, but in my personal opinion, it's best to use your distro's config file and update it according with your requirements. It will be less pain and time, since you are sure that the config file is working and similar with your distro's configuration. In this case, i will use Slackware's config file which can be found at Slackware's repository under kernels/huge26.s directory. I usually use the slackware-current version, so the directory tree will be slackware-current/kernels/huge26.s/config (it will be different for each mirrors. I use OSUOSL mirror for example). I always put my config file on my Box.net account, so feel free to download it if you are wondering what kind of configuration i used.
The hotplug binary is not used anymore and all configuration can be done using only udev.rules contained in a new udev packages. Also, try to upgrade your GCC (GNU C Compiler) and GLIBC packages (and some other library for common development) to the latest version in Slackware-Current version before you compile the kernel. It will ensure you that the kernel will be configured with the latest GCC and GLIBC. I'm using GCC 4.2.3 and GLIBC 2.7 currenly, that is used in Slackware-Current (per 16 August 2008).
After the preparation steps has been finished, we can start the kernel installation. First of all, put the kernel into /usr/src directory and extract it using
tar -xjvf linux-188.8.131.52.tar.bz2
It will extract the kernel and make a new directory called linux-184.108.40.206. The process will take some time, as the kernel itself is big enough (around 46 MB with bzip2 compression). If it's finished, it's good idea to make some symlink from /usr/src/linux to point to your new kernel directory. You can delete the previous symlink if there is one and start making a new one with
ln -s /usr/src/linux-220.127.116.11 /usr/src/linux
Next, put your Slackware config file into your kernel directory and rename it .config. After that, go into the directory. Type
cp /boot/config linux-18.104.22.168/.config
Because you already have your config file, you don't have to configure all of the kernel build parameter by yourself. Just let the kernel knows that you are going to use your own config file rather than building it from scratch by typing
When building newer kernel (for example 2.6.26.x and your system is running 2.6.25.x), new features will be asked and you will have to answer those questions. Always read the help provided by pressing "?". I always tried to avoid EXPERIMENTAL features as it's still too buggy. Any driver is recommended to be build as module and not bloating the kernel image itself.
After it's finished, you should edit the config file again, since Slackware config by default was set to use i486 architecture for the processor type. You can use several ways, but if you have graphical screen, i suggest you to use
Other possibility are
In my situation, i changed the processor type into i586 and above, enable the HIGHMEM feature (4 GB), enable the kernel preemptive configuration (suitable for desktop), and add the APM module to make the CPU idle when not used (good for saving battery). You can add or modify the configuration to suit your need. When you are done configuring the kernel, save it and exit.
Next is the compilation process. Start by making the kernel image itself by typing
The process will take some time, so get yourself a cup of coffee and some snacks before you re-check your status. When it's done and without errors, the kernel is placed in arch/x86/boot/bzImage. Copy that file and put it in /boot and rename it into vmlinux-22.214.171.124 by typing
cp arch/x86/boot/bzImage /boot/vmlinuz-126.96.36.199
Next step will be compiling your modules. Do it by typing
When the modules are installed, your next step will be copying System.map and config into your /boot partition
cp System.map /boot/System.map-188.8.131.52
cp .config /boot/config-184.108.40.206
All done with the hard stuff. Now edit /etc/lilo.conf to add an option to boot the new kernel. Make sure that you leave an option available to boot an old working kernel. Then, run "/sbin/lilo" and make sure there where no errors. Reboot, select the new kernel, and see if it worked. If not, reboot and select the kernel you were using before. Here's my lilo.conf :
#Linux bootable partition config begins image = /boot/vmlinuz-220.127.116.11 root = /dev/hdc9 label = Linux-18.104.22.168 read-only # Linux bootable partition config ends
Here is my /boot :
README.initrd -> /usr/doc/mkinitrd-1.3.2/README.initrd System.map -> System.map-22.214.171.124 System.map-126.96.36.199 boot.1600 boot_message.txt config -> config-188.8.131.52 config-184.108.40.206 diag1.img initrd-tree/ initrd.gz map slack.bmp vmlinuz -> vmlinuz-220.127.116.11 vmlinuz-18.104.22.168WARNING : MAKE SURE YOU DON'T MESS UP AND GET RID OF THE WORKING KERNEL. (Taken from Shilo's guidance)
When you reboot your system, try to log in into text mode. This way, you can reinstall some third-party modules, such as NVidia or ATI driver or it won't boot into graphical screen (if you set your run level into 4) when you have logged in using your account.
If you find your kernel is working, Congratulations. But your work isn't finished yet. You have to make sure that every program is working fine with the new kernel. You should spent few hours (or days) to make sure that your kernel is working perfectly on your system. After that, you can delete the old kernel to save some space, or you can start tuning the kernel again so it will meet your ideal performance. Happy tweaking...
Installing kernel from source is not a hard process if you follow the instructions carefully. I would like to give my credit to Patrick J. Volkerding who has made Slackware and Shilo, who gave me a working guidance. Without their help, this article wouldn't be made.
Last Update : 2 July 2009 :: 17:47:27