How to: Compile Linux kernel 2.6.XX

Source: Internet
Author: User

By nixcraft

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 should t for apt-get command.

Step #1 Get Latest Linux kernel code

Visit http://kernel.org/and download the latest source code. file Name wocould 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:

  • $ 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.

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:

  • System. map-2.6.25
  • Config-2.6.25
  • Vmlinuz-2.6.25
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:

  • Our kernel ing Linux Kernel article and Compiling Linux kernel module only.
  • Official README file has more information on kernel and software requirement to compile it. This file is kernel source directory tree.
  • Documentation/directory has interesting kernel documentation for you in kernel source tree.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.