Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
Site Navigation
Linux Forums
Linux Articles
Product Showcase
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds
Free Publications

So you've been using Linux for a while now and have decided to take the next step.
Whether you are looking for a performance increase, added hardware support or even just to enhance your geek cred, compiling your own kernel need not be a horrifying experience. Compiling a kernel has historically been a very involved and, at times, frustratingly hair pulling experience for new Linux users. All that has changed however with new tools making it easier than ever before to roll your own. In this article I will take you through the whole process, step by step, from downloading to booting your new kernel.

Obtaining your new Kernel

Many distributions either install the source for the current kernel or make it available via the package manager, some distributions even make it possible to install a new kernel via the package manager. The downside to this is that it isn't going to be the latest kernel and that you aren't going to get the same level of customization as you do when compiling your own. Therefore we need to go straight to the source (excuse the pun) and download our kernel from www.kernel.org. I would recommend downloading the 'Latest Stable Version' by clicking on the 'F' link beside the release date. This will take some time to download on slower connections, feel free to continue on to the 'Preparing Your System' section while you wait for your new kernel to download.

Preparing Your System

The main prerequisite to compiling your own kernel is (not surprisingly) a compiler, if a compiler is not installed on your system then use your distributions package management tools (Apt, Yum, Synaptic, Emerge, etc...) to install the most recent version of gcc (the GNU compiler). You will also need to install the bzip2 package using your package manager. Debian users can install the build-essential package to ensure that they have all the tools required to build things. NCurses is also required for those using menuconfig, however we will be using xconfig in this article which is a bit friendlier and for that NCurses isn't needed. You will also need to use mkinitramfs, which will be available with most package managers in the form of mkinitramfs-tools, or similar and is used to create a temporary file-system in Ram to boot the kernel from. If your package manager doesn't provide these tools they can be downloaded from the following locations:

gcc - http://gcc.gnu.org/

bzip2 - http://www.bzip.org/

mkinitramfs - http://sourceforge.net/projects/mkinitramfs/

Unpacking Your Kernel

Once your kernel is downloaded you need to move it to your /usr/src/ directory and unpack it. You then need to create a link from your actual kernel source directory to the default kernel source location /usr/src/linux/. Follow the commands below, replacing linux-2.6.20-1 with the version you have downloaded and /home/fred/ with the location that you have downloaded the kernel to.

mv /home/fred/linux-2.6.20-1.tar.bz2 /usr/src/

tar -jxvf linux-2.6.20-1.tar.bz2

ln -s /usr/src/linux-2.6.20-1/ /usr/src/linux

Configuring Your Kernel

The configuration file for your kernel has over 2000 options, most of which mean absolutely nothing to most people, therefore we don't want to have to set each one individually. The easy way around this is to copy the configuration file for your current kernel and modify that. The config file for your current kernel is in the /boot/ directory, If you were using a 2.6.17 kernel your config file would be /boot/config-2.6.17. When you are configuring a new kernel it creates a .config file in the /usr/src/linux/ directory, if one already exists it loads the settings from that and saves changes back to it. Therefore, you need to copy the config file from your /boot/ directory to /usr/src/linux/.config. To do so run the command below, replacing 2.6.17 with your current kernel version.

cp /boot/config-2.6.17 /usr/src/linux/.config

Now change to the /usr/src/linux/ directory and run the command make xconfig.

cd /usr/src/linux/

make xconfig

This will bring up the configuration menu with all the defaults from your current kernel already set. A tick in a box indicates that the driver will be compiled in to the kernel and loaded at every boot (each tick slows down your kernel a fraction), a dot in a box indicates that the driver will be compiled as a module which will only be loaded when you request it to and a blank box indicates that the driver will not be available at all. If you are compiling solely to enable a piece of hardware then skip to the 'Device Drivers' section, locate the appropriate sub-directory and enable the option for your device, then skip to the next section. If however you are here to trim excess fat and gain precious speed then read on. The list below contains a list of options, with short descriptions, which can commonly be removed without harming your system. If you have a piece of hardware which isn't supported under your current kernel, it may be supported under the new kernel, just find the corresponding menu and enable it. I make no guarantees that removing one of these devices won't render your new kernel unusable on your system, but if this does happen then you can always re-enable the option and recompile.

Processor Type

In the Processor Type and Features section under 'Processor Family' select the option that matches your CPU.

Bus Options

Disable ISA and MCA unless you have a very old PC (more than six years old) that you know has ISA or MCA slots.

Disable PCCard(PCMCIA/Cardbus) support unless you are using a laptop.

Disable PCI Hotplug Support as it is not available on common hardware.

Device Drivers

Disable all SCSI low-level drivers unless you have special SCSI hardware (mostly used for servers and Mac hardware.

Disable all Fusion MPT device support unless you know you have this SCSI card.

Disable ISDN support unless you are in a part of the world that still uses ISDN for Internet.

Disable Linux telephony support unless you have a special card to connect a regular phone to your PC for VOIP applications.

Enable Advanced Linux Sound Architecture if it is not already enabled. If you know what kind of Sound-card you have you can also disable any other drivers under the 'Generic Devices', 'PCI Devices' and 'USB Devices' sub-menus.

Disable Open Sound System

Disable Infiniband Support unless you know you have special infiniband hardware.

File Systems

Under 'Miscellaneous Filesystems', enable Compressed Rom File Support(cramfs) and disable all others unless you have a specific need to access a special file-system type.

Under 'Partition Types' disable all except PC BIOS (enable all sub-menus) and Windows Logical Disk Manager Support

Now that you have finished selecting your options click on the 'Save' icon (the floppy disk) and exit the utility.

Compiling Your Kernel and Modules

Once the configuration is saved, the next step is to compile the kernel. To compile the kernel itself run 'make' from within the /usr/src/linux/ directory. This will take a long time, on old systems it will take a very long time and your system will be unusable for other tasks while it compiles.

cd /usr/src/linux/


Next we build and install the modules.

make modules_install

Installing Your Kernel

Now that we have a fully customized and compiled kernel, we need to tell the system where it is and what to do with it. First we will install it in the appropriate place and create the necessary links to it. Then we will generate a ramdisk which the system will use at boot time to load the kernel. Then we will update your boot-loader to recognize the new kernel. If all goes according to plan we will then be able to boot the new kernel. As usual replace 2.6.20-1 with the actual version of your new kernel.

Install the kernel in /boot/ and create links.

cd /usr/src/linux/

make install

Generate a Ramdisk

cd /boot/

mkinitramfs -o initrd.img-2.6.20-1 2.6.20-1

Update Grub or Lilo (depending on which you have, usually Grub).






Hopefully you still have all your hair and you now have a brand spanking shiny new racey kernel. Reboot your PC and select your new kernel from the boot menu. If for some reason it doesn't boot, your old kernel will still be available and you can try again. For those of you with an adventurous streak, now is the time to go back in to xconfig and try and refine your selections even further.

Rate This Article: poor excellent
Comments about this article
mkinitramfs -o initrd.img-2.6.20-1 2.6.2
writen by: Ivelin on 2007-12-19 04:55:39
There is no such command in Slackware... there is mkinitrd
RE: mkinitramfs -o initrd.img-2.6.20-1 2.6.2 written by Ivelin:
make xconfig
writen by: jnev on 2007-12-22 21:34:47
when I run the command 'make xconfig' I get an error saying make: *** No rule to make target 'xconfig'. Stop I'm running ubuntu 7.10 if it matters... running it as root makes no difference.
RE: make xconfig written by jnev:
writen by: cyberyak on 2007-12-24 12:16:43
RE: written by cyberyak:
writen by: daredevifury on 2007-12-29 08:12:30
Everything went fine until...actually i dont know...when i make install the new kernel, no initrd file is created for it at /boot/ ...no error messages are shown...it ends off by detecting grub installed and saying i shoud change meu'lst references to the new vzlinux file....any hints?
RE: Help! written by daredevifury:
mkinitramfs Error
writen by: TestUser on 2008-04-23 02:54:52
Everthing works fine till I reach the second last command of "#mkinitramfs -o initrd.img-2.6.25 2.6.25". It returns me following error: which: no udevcontrol in (/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin) cp: missing destination file Try `cp --help' for more information. ------------------ Error has occured! Even after this command failure, an entry for the new kernel has been automatically added in the grub.conf file and I have the option of selection between the old kernel and the new kernel. The old one boots fine, but new one after decompression gives kernel panic error. I am anxiously waiting for your reply.
RE: mkinitramfs Error written by TestUser:
locating the relevant parts
writen by: shroomy bee on 2008-07-02 10:01:05
If the distro has no /src/ in it's /usr/ folder - where should you have a look for the kernel? & if there is no config file in /boot - is there another likely place that would be? There's a symbolic link to 'kcore' that says it links to the /proc/ folder, but there's no kcore in there. Or maybe a better question instead of that lot would be - what type (build, distro) of linux is it the tutorial there definitely works for, without having to change any of the instructions?
RE: locating the relevant parts written by shroomy bee:
kernel panic
writen by: Anon on 2008-07-07 14:07:08
used [b]mkinitramfs -o initrd.img-2.6.25-10[/b] as command as it complaint about not finding /lib/modules/2.6.25-10 (there only was maybe this led to the panic=(
RE: kernel panic written by Anon:
writen by: shroomy_bee on 2008-10-27 09:58:54
RE: re: written by shroomy_bee:
writen by: buycheapaocgold on 2008-11-30 20:57:18
RE: buycheapwowgold written by buycheapaocgold:
cheap wow gold
writen by: vcsale on 2008-12-24 00:13:12
RE: cheap wow gold written by vcsale:
cheap wow gold
writen by: vcgamegold on 2008-12-24 20:52:23
RE: cheap wow gold written by vcgamegold:
cheap wow gold
writen by: vcgamegold on 2008-12-24 20:58:53
RE: cheap wow gold written by vcgamegold:
good news
writen by: Ekim on 2009-04-20 22:49:31
Viruses can be [URL=http://www.laptopspartstore.com/products/637871.html]Gateway PA-1650-01 AC Adapter[/URL] [URL=http://www.laptopspartstore.com/products/638467.html]Liteon PA-1650-01 AC Adapter[/URL] [URL=http://www.laptopspartstore.com/Productlist.html?CatID=200217260]Toshiba Laptop AC Adapter[/URL] [URL=http://www.laptopspartstore.com/products/637871.html]Toshiba PA3467U-1ACA AC Adapter[/URL] [URL=http://www.laptopspartstore.com/products/638657.html]Original Gateway PA-1650-01 AC Adapter[/URL] [URL=http://www.laptopspartstore.com/products/638759.html]Toshiba PA3469U-1ACA AC Adapter[/URL] [URL=http://www.laptopspartstore.com/products/635548.html]Acer PA-1650-02 AC Adapter[/URL]Many user friendly features include a large screen viewfinder, auto-focus and LED flash. Stored video files can be played back in a variety of formats.very quick to gain access to PCs. [URL=http://www.laptopspartstore.com/]Laptop parts[/URL] [URL=http://www.laptopspartstore.com/Productlist.html?CatID=200217247]Laptop Acer AC Adapter[/URL] [URL=http://www.laptopspartstore.com/Productlist.html?CatID=200217278]Gateway Laptop keyboard[/URL] One of the most common ways that PCs get infected is by downloading content from a site that hosts malicious material. [URL=http://www.laptopspartstore.com/Productlist.html?CatID=200217284]Toshiba Laptop keyboard[/URL] [URL=http://www.laptopspartstore.com/Productlist.html?CatID=200217250]Dell Laptop AC Adapter[/URL] To keep such problems at bay it's always best to have some sort of automated software to decrease the chances of your computer getting infected or if it is already infected remove such an infection. [URL=http://www.laptopspartstore.com/Productlist.html?CatID=200217256]Liteon Laptop AC Adapter[/URL] [URL=http://www.laptopspartstore.com/Productlist.html?CatID=200217207]Laptop LCD AC Adapter[/URL] [URL=http://www.laptopspartstore.com/products/635550.html]Acer Aspire 1200 AC Adapter[/URL] [URL=http://www.laptopspartstore.com/products/635550.html]Liteon PA-1131-08 AC Adapter[/URL] [URL=http://www.laptopspartstore.com/products/635550.html]Delta PA-1650-02 AC Adapter[/URL] Another common way is through spam and junk emails, don't be fooled by fake email addresses either.
RE: good news written by Ekim:
writen by: cici on 2009-04-20 22:50:56
thanks, good.http://www.laptopspartstore.com/products/637871.html http://www.laptopspartstore.com/Productlist.html?CatID=200217260 http://www.laptopspartstore.com/products/638469.html http://www.laptopspartstore.com/products/638657.html http://www.laptopspartstore.com/products/638759.html http://www.laptopspartstore.com/products/635548.html
RE: thanks written by cici:
Very nice
writen by: Peace76 on 2010-08-22 08:53:22
Thank you for this lesson. Very helpful!
RE: Very nice written by Peace76:
Thank you
writen by: bskumar7080 on 2011-02-25 06:14:04
It is very useful for someone who is compling the linux for first time
RE: Thank you written by bskumar7080:
writen by: bskumar7080 on 2011-02-26 03:57:19
I compiled a kernel and after compilation i am not able to boot with new kernel. i am getting following errors

Gave up waiting for root device
common problems
-Root args
check root delay
check root
missing modules(cat /proc/modules ls /dev)

Alert : /dev/disk/by-uuid / 975f57c9-c735-47do-93bf-0779fce652b7 does not exist
dropping by shell

how to correct this
RE: Error written by bskumar7080:

Comment title: * please do not put your response text here