Polls

Topics

How to: Compile Linux kernel 2.6

Posted by Vivek on Thursday September 29, 05 @2:23 am

Compiling custom kernel has its own advantages and disadvantages. However, new Linux user / admin find it difficult to compile Linux kernel. Compiling kernel needs to understand few things and then just type couple of commands. This step by step howto covers compiling Linux kernel version 2.6.xx under Debian GNU Linux. However, instructions remains the same for any other distribution except for apt-get command.

Step # 1 Get Latest Linux kernel code

Visit 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-2.6.25.tar.bz2 represents 2.6.25 kernel version. Use wget command to download kernel source code:
$ cd /tmp
$ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-x.y.z.tar.bz2

Note: Replace x.y.z with actual version number.

Step # 2 Extract tar (.tar.bz3) file

Type the following command:
# tar -xjvf linux-2.6.25.tar.bz2 -C /usr/src
# cd /usr/src

Step # 3 Configure kernel

Before 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:

For 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.

Step # 4 Compile kernel

Start compiling to create a compressed kernel image, enter:
$ make
Start compiling to kernel modules:
$ make modules

Install kernel modules (become a root user, use su command):
$ su -
# make modules_install

Step # 5 Install kernel

So 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 image

Type the following command at a shell prompt:
# cd /boot
# mkinitrd -o initrd.img-2.6.25 2.6.25

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.lst

Open file using vi:
# vi /boot/grub/menu.lst

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

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:
# update-grub
Neat. Huh?

Step # 8 : Reboot computer and boot into your new kernel

Just issue reboot command:
# reboot
For more information see:

Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or full RSS feed to get all updates. You can Email this page to a friend.

You may also be interested in...

Discussion on This Article:

  1. Anonymous Says:

    According to the kernel documentation, the kernel should be compiled using gcc 2.95.x, with x >= 3. “apt-get install gcc” under debian gives you a recent gcc (version > 4).

  2. nixcraft Says:

    It works with gcc version >= 4.0.
    gcc –version
    gcc (GCC) 4.0.3 20060212 (prerelease) (Debian 4.0.2-9)

    uname -a
    Linux debian 2.6.15.4 #1 PREEMPT Fri Feb 17 20:46:04 IST 2006 i686 GNU/Linux

    I have compiled above kernel using gcc 4.0.2-9. INSTALL file may be not updated.

  3. Anonymous Says:

    Thanks a lot Gabber Anna,
    It’s works for me :-))

  4. nixcraft Says:

    LOL
    Note sure who are you?
    But you bring back some old memories…

    Take care buddy :)

  5. Learn Hacking Says:

    any guess about boot loader?

  6. debianusr Says:

    After building the kernel and updating grub I’ve rebooted the new kernel successfully. Now I am wondering if this process includes updating the kernel header files in /usr/include/. If not, what is the best way to do that and should any new directories be added to ld.so.conf so I can update glibc?

  7. vivek Says:

    If you also upgraded kernel-devel and headers package you should get updates. No need to upgrade ld.so.conf or cache

  8. Animesh Says:

    Info
    —–

    Kernel 2.6.23 has issues with kernel headers. If you have distro’s like fedora it gonna give up some wierd fixdep.c error messages.

    Some forums say you need to have 2.4 headers for compiling it. Kernel header is a huge mess scattered around and well serious debates have gone down the drain…

    http://kerneltrap.org/node/6536

  9. Pradeep Says:

    Does this kernel support RHEL4 update 5

    I am using kernel 2.6.9-55.EL can i upgade the

  10. dushyant Says:

    How much time does it take approximately?

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , , , , , , , , ~ Last updated on: April 17, 2008

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.