I am taking this opportunity to re-post this article for purposes of good archiving as with all my other post. I look for a candidate where I can equally enjoy and have the luxury of messing up the system if something goes wrong it won't be a big deal. The target machine was a debian lenny 5.0 which I just downloaded (11-28-2010). Installed the base and configured networking to set the stage. Read on.
How to: Compile Linux kernel 2.6
Step # 1 Get Latest Linux kernel codeVisit http://kernel.org/ and download the latest source code. File name would be linux-x.y.z.tar.bz2, where x.y.z is actual version number. For example file inux-18.104.22.168.tar.bz2 represents 22.214.171.124 kernel version. Use wget command to download kernel source code:
$ cd /tmp
$ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-126.96.36.199.tar.bz2
Note: Replace x.y.z with actual version number (in my case its the actual current kernel on the site).
Step # 2 Extract tar (.tar.bz2) fileType the following command:
# tar -xjvf linux-188.8.131.52.tar.bz2 -C /usr/src
# cd /usr/src
Step # 3 Configure kernelBefore you configure kernel make sure you have development tools (gcc compilers and related tools) are installed on your system. If gcc compiler and tools are not installed then use apt-get command under Debian Linux to install development tools.
# apt-get install gcc
Now you can start kernel configuration by typing any one of the command:
- $ make menuconfig - Text based color menus, radiolists & dialogs. This option also useful on remote server if you wanna compile kernel remotely.
- $ make xconfig - X windows (Qt) based configuration tool, works best under KDE desktop
- $ make gconfig - X windows (Gtk) based configuration tool, works best under Gnome Dekstop.
Step # 4 Compile kernelFor example make menuconfig command launches following screen:
$ make menuconfig
You have to select different options as per your need. Each configuration option has HELP button associated with it so select help button to get help.
Start compiling to create a compressed kernel image, enter:
Start compiling to kernel modules:
$ make modules
Install kernel modules (become a root user, use su command):
$ su -
# make modules_install
Step # 5 Install kernelSo far we have compiled kernel and installed kernel modules. It is time to install kernel itself.
# make install
It will install three files into /boot directory as well as modification to your kernel grub configuration file:
Step # 6: Create an initrd imageType the following command at a shell prompt:
# cd /boot
# mkinitrd -o initrd.img-184.108.40.206 220.127.116.11
* In my case I used mkinitramfs -o initrd.img-2.6.25 (which ever version number of kernel you downloaded)
initrd images contains device driver which needed to load rest of the operating system later on. Not all computer requires initrd, but it is safe to create one.
Step # 7 Modify Grub configuration file - /boot/grub/menu.lstOpen file using vi:
# vi /boot/grub/menu.lst
title Debian GNU/Linux, kernel 18.104.22.168 Default root (hd0,0) kernel /boot/vmlinuz-22.214.171.124 root=/dev/hdb1 ro initrd /boot/initrd.img-126.96.36.199
Remember to setup correct root=/dev/hdXX device. Save and close the file. If you think editing and writing all lines by hand is too much for you, try out update-grub command to update the lines for each kernel in /boot/grub/menu.lst file. Just type the command:
... Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
Searching for splash image ... none found, skipping ...
Found kernel: /vmlinuz-188.8.131.52
Found kernel: /vmlinuz-2.6.26-2-686
Updating /boot/grub/menu.lst ... done
Step # 8 : Reboot computer and boot into your new kernelJust issue reboot command:
So depending on how you setup your menuconfig in the first part would dictate on how long the compile and the installation of the modules for the new kernel will take. In my case its almost one day. Good luck.
- If for example you experienced an error during the initial "make" chances are you have several packages that is missing one such package is the libncurses5-dev (if you are using debian based system) package.
- Make sure you have enough disc space on the directory you will be building the sources, in my recent experience, I needed at least 6Gb of free space under /usr/src to get it done.