How to recompile the linux kernel

Reasons to recompile your Linux kernel

  1. You’ve bought some new hardware and want support for it in Linux.
  2. You want to access features of Linux that have been turned off.
  3. Something is fishy in your operating system.
  4. You want to show off to all your friends and brag about how you are a (false) Linux guru.
  5. You have nothing better to do.
  6. You really want to.

Compiling the Linux kernel isn’t all that difficult, really. The
longest time goes in configuring it.

I will divide this guide into three parts:

  • Preconfiguration
  • Configuration
  • Post Configuration

I have used kernel version 2.6.6. This guide is specific to 2.6.6
though other kernels in 2.6.x would be quite similar. The Linux
distribution used is PCQLinux 2004 (a Fedora Core based

distribution) with
Grub as the boot manager.

The procedure to be followed for other kernels would be the same.

I have also assumed that the computer in question is a dual boot home
PC. This document is not really suitable for advanced users. The
configuration process depends a lot on the hardware you are using.

My setup is:

  • AMD 64 3200+
  • 512 MB DDR 400 RAM
  • Nvidia nforce3 150 based motherboard.
  • Onboard sound Realtek ALC 658 (which, unfortunately is not supported by Linux)
  • ATI Radeon 9600 pro.

1. Preconfiguration

Visit and download the latest stable kernel (at the time of writing it was 2.6.6).

Change user to root: su

Copy the downloaded kernel to /usr/src

Uncompress the kernel

  • bunzip2 linux-2.6.6.tar.bz2 if you have the bzipped format
  • guzip linux-2.6.6.tar.gz if you have downloaded the gzipped format
  • tar –zxvf linux-2.6.6.tar

Change to the

Linux directory: cd linux-2.6.6

Make mrproper to remove any old configuration files or object files: i.make mrproper

If you want to use an older configuration file then copy it over .config. If you want a reference configuration file then you can use
the config file in the appropriate subdirectory of ~/linux-2.6.6/arch.

Issue one of four commands

  • make oldconfig (asks you to add new options as yes/no/module –not recommended)
  • make menuconfig (uses a terminal not unlike your bios screen)
  • make xconfig (uses GUI)
  • make config (first edit .config then run this command – very advanced users only)

Personally I will go with "make menuconfig". It is simple in its design and
easy to understand considering that there are well over a thousand
options distributed under various sub-headings.

2. Configuration

This is the most difficult part of the process.

Options can be excluded, built in or included as modules. Modules are
not added to the kernel, but are kept as separate units. This saves
memory space, but has to be loaded separately. Only some options can be
compiled as modules.

Here is a rundown of the various options and how to configure them
(remember depending upon your hardware and previous choices you may get
different choices presented to you). Have fun!

Code Maturity Level Options

1. Prompt for development and/or incomplete code/drivers
Purpose: You have the option of using experimental drivers etc.
Suggestion – exclude. However, if you are sure of what you are
you can include it. This is only for developers or people who have
excellent idea of their hardware configuration. May be required to
provide support for new features.

General setup

1. Support for paging of anonymous memory
Purpose: Allows the kernel to have more virtual memory than RAM using swap files or swap devices.
Suggestion – built in.

2. System V IPC
Purpose: This is a feature from the Unix background that Linux has come from. Required for many programs.
Suggestion – built in.

3. BSD Process Accounting
Purpose: Allows user level programs to specify that process accounting information can be stored.
Suggestion – built in.

4. Sysctl support
Purpose: Allows modification of certain kernel parameters on the fly.
Suggestion – built in. In case of rescue disks it can be left out.

5. Auditing Support
Purpose: Required by various kernel subsystems such as SELinux.
Suggestion – built in. It probably won’t hurt.

6. Enable System Call Auditing Support
Purpose: Appears only if the last option was selected.
Suggestion – built in.

7. Kernel Log Buffer Size
Purpose: Specified as a power of two.
Suggestion – 14 for most systems. I have put in 16 since I have an x86_64 system. (32 bit uniprocessor systems use 14).

8. Support for hot pluggable devices
Purpose: Required for USB, PCMCIA etc.
Suggestion – built in.

9. Kernel .config support
Purpose: Stores the .config file, compiler version used for
compilation, etc. in the kernel. Can be left out for most purposes.
Useful only to developers.
Suggestion – exclude.

10. Configure standard kernel options
Purpose: Lets you specify configuration of standard kernel features.
THIS IS ONLY FOR ADVANCED USERS. If you do enable it then enable all
the options that are then presented to you.
Suggestion – exclude. (I have built it in anyway).

Loadable Module Support

1. Enable loadable module support
Purpose: Allows you to build a modular kernel. If you don’t want to use
modular kernels exclude it. Generally it is a good idea to keep it as
you can then build a smaller (and faster) kernel this way.
Suggestion – built in.

2. Module Unloading
Purpose: Enables module unloading facility. All modules may not be able
to make use of this feature (though that will not cause any errors).
Suggestion – built in.

3. Automatic Kernel Module Loading
Purpose: Allows certain parts of the kernel to automatically load
kernel modules using modprobe. It’s probably a good idea to include this
unless you are sure of what you are doing.
Suggestion – built in.

Processor type and features

1. Subarchitecture type – Select PC Compatible (unless you are running non x86 systems)
2. Processor Family – Your processor should be automatically detected,
but do scroll down the list to make sure that it has been selected
correctly. In particular AMD64 is always detected as K7 rather than K8.
Make sure that you choose the correct case (you can probably choose a
lower level but never select a configuration higher than your own.)
Failure to make an improper choice can lead at best to a loss of
features and at worst a kernel that fails spectacularly.

3. Generic x86 support
Purpose: Includes Optimizations for processors other than the
one selected. This is required only if you wish to distribute the
kernel you have compiled to machines of some other architecture.
Suggestion – exclude.

4. HPET timer support
Purpose: Uses the new HPET timer for the kernel’s internal timing
rather than the venerable 8254 (Anyone who has done a microprocessor
techniques course will tell you that the 8254 was made way back in the
late 70s and is still in use). It is safe to include this feature as it
is only enabled if the platform supports it.
Suggestion – built in.

5. Symmetric Multiprocessing support
Purpose: Required to take advantage of multiple processors in high end systems (nothing to do with clusters here).
Suggestion – Home users should exclude this. Include it only if you are lucky enough to be running an SMP.

6. Preemptible Kernel
Purpose: Allows low priority processes to be preempted even while in
kernel mode. (For further explanation read up about the linux process
management from a good book)
Suggestion – built in for desktop systems, RTS or embedded.

7. Local APIC support on uniprocessors
Purpose: Allows uniprocessors with a local APIC to use this APIC. It
can be safely enabled with no slowdown even if it is not present (some
of you may have seen an option in the bios dealing with this).
Suggestion – built in.

8. IO-APIC support
Purpose: this option appears only if you have selected the last one.
Suggestion – Similar to the last option and can be built in.

9. Machine Check Exception
Purpose: Returns errors to the kernel if the processor detects an error (overheating etc)
Suggestion – built in is a safe option for everyone.

10. Check for non-fatal errors on AMD Athlon/Duron Intel Pentium
Purpose: Similar to above, but returns errors specific to these processors.
Suggestion – module.

11. Check for P4 thermal throttling interrupt
Purpose: Prints a message whenever the P4 enters thermal throttling.
Suggestion – user’s choice.

12. Toshiba Laptop Support
Purpose: Useful only on Toshiba Laptops having Toshiba bios.
Suggestion – exclude unless your system satisfies the above criterion.

13. Dell Laptop Support
Purpose: Useful only on the Dell Inspiron 8000.
Suggestion – exclude unless your system satisfies the above criterion.

14. /dev/cpu/microcode – IA32 CPU microcode support.
Purpose: Allows you to update the microcode on 32 bit Intel machines.
Suggestion – exclude. This option has no meaning for AMD users and is not commonly used even by Intel users.

15. /dev/cpu/*/msr – Model specific register support
Purpose: Enables privileged processes access to MSRs.
Suggestion – module.

16. /dev/cpu/*/cpuid – CPU information supports
Suggestion – module.

17. High memory support
Suggestion – If you have not more than 1GB RAM then say “off”.
1- 4 GB then select 4GB. Upto 64 GB then select 64 GB. (Only on Intel
systems supporting PAE!) This option does not appear to have any
meaning for 64 bit systems.

18. Allocate 3rd level page tables form high memory.
Purpose: Setting this option will put user space page tables in
high memory. This avoids the waste of low memory space in systems
having large amount of RAM.
Suggestion – This option appears only if you have selected the previous
option. (Unlikely at present but will change in the future).

19. Math Emulation
Purpose: Emulates a math coprocessor on systems which do not have one.
Suggestion – exclude, unless you are running a 386 or 486SX (unlikely).

20. MTRR support
Purpose: Memory Type Range Registers may be used to control access to AGP and PCI buses. Improves performance of video cards.
Suggestion – built in.

21. Boot from EFI support
Purpose: This option has a meaning only on IA64 systems.
Suggestion – exclude.

Power Management Options

This section is highly system dependent. I would advise going through
each option carefully. Many of the options are only for mobile systems
or those running on mobile Pentium or athlon processors.

Bus Options

1. PCI Support
Purpose: Required if the system bus is PCI (as it is on almost all systems from P1 upwards).
Suggestion – built in.

2. PCI Access Mode – any.

3. Vector Based Interrupt Indexing
Purpose: This is a new feature intended to replace IRQs.
Suggestion – It is probably a good idea to exclude this for now.

4. Legacy proc/pci interface
Purpose: Legacy support. Newer tools are now in use (ie lspci).
Suggestion – exclude.

5. PCI device name interface
Purpose: The kernel contains a database of all known PCI
devices. This can be removed using this feature. Disabling this feature
the device names by device IDs. It also reduces kernel size by 80 KB.
Suggestion – built in. If you are creating a boot disk then it can be excluded.

6. ISA Support
Purpose: Required only if you have ISA slots in your system.
Suggestion – Most modern systems do not have ISA slots (the
Intel 875
may be an exception). It can therefore be excluded in such systems. If
your system does have ISA slots then include this as well as all
subsequent options that appear on enabling it (except VESA Local Bus

7. MCA Support
Purpose: Required on systems having Microchannel architecture.
Suggestion – This is supported only on a few systems from IBM. For most systems it should be excluded.

8. NatSemi SCx200 support
Suggestion – Required only if you have the National Semiconductor SCx200 processor. Exclude for most systems.

9. PCMCIA/ Cardbus Support
Purpose: This sub menu includes several options. It is necessary only on laptops.
Suggestion – exclude on desktop systems. On laptops it should be built
in (module is also possible but is not really recommended as it is
frequently used on a laptop). If included then 4 subsequent options
appear of which “Cardbus Yenta compatible bridge” should be built in
while others are excluded. Executable File Formats

10. Kernel Support for ELF binaries
Purpose: Required for using Binaries compiled in the ELF format. As the
conversion to ELF was started in 1995, this option can be considered
Suggestion – built in.

11. Kernel support for a.out and ECOFF binaries
Purpose: Required to run certain old binaries which were in the a.out
format which is now dead (this has nothing to do with the fact that the
default name of all files compiled by gcc is a.out, that was just a
convention which is still followed). Needed only if you have really old
binaries lying around.
Suggestion – exclude. If absolutely necessary then include it as a module.

12. Kernel support for Miscellaneous binaries
Purpose: Required to execute wrapper driven binaries. This is used in Java, .NET and LISP.
Suggestion – built in as Java is quite common and .NET on Mono is taking off.

Device Drivers

This is one of the weirdest parts of the configuration, and
unfortunately, one which I can’t help you with. There are hundreds if
not thousands of options, all of them system dependent. I will give you
a few tips though.

Do not mess around with removing SCSI support. It is required even if
you do not have SCSI hardware or capability. However within SCSI some
options can be excluded.

Do not disable networking, it is required even by some non-network programs.

Token Ring and FDDI can generally be excluded. In Ethernet you need
only select the network card that you have, all others can be disabled.
Most of you will not have 10000 Mbps ethernet so that can be excluded.
The same applies for WiFi, Amateur Radio, RAID, IrDA, ISDN, Telephony
support (to use ordinary phones for VOIP) etc.

Lookout for your chipset driver for AGP support in character devices
and make sure to include it (all others can then be excluded).
Specifically, there is support for i865 and nforce 1 and 2, SIS and
VIA, apart from several others (if you have nforce3 you can try nforce2

If you have a Radeon then include its driver under Direct Rendering
Manager of Character Devices. Configure Graphics support carefully. It
can cause problems otherwise. USB support should also be configured
carefully. Most people now have USB 2.0, so it along with USB 1.1
should be selected.

Remember this section is largely about common sense. If you don’t have
need for a particular feature then in most cases it is safe to switch
it off. This however, does not apply to the networking and SCSI side.
Be careful there.

File Systems

This is another large section, so I’ll just mention whether you should include an option or not.

  • Second Extended fs support – built in (IMPORTANT).
  • EXT2 extended attributes – exclude.
  • EXT3 journaling file system support -built in (IMPORTANT).
  • EXT3 extended attributes – exclude. (extended attributes must be included if you want to use SELinux or the like)
  • JBD debugging support – exclude.
  • Reiserfs support – exclude.
  • JFS support – exclude.
  • XFS support – exclude.
  • Minix filesystem support – exclude.
  • ROM filesystem support – exclude. (Some people might need these, but if
    you are such a person, you will know how to configure them)
  • Quota support – exclude. Only needed if you want to set limits on user
    disk usage. Again, an advanced option, not present on most home PCs or
    single user desktops.
  • Kernel automounter support – exclude.
  • Kernel automounter support v4 – exclude. Needed only on large networks.

CD/DVD ROM filesystems – use built in for all the options in the submenu.

DOS/FAT/NT Filesystems —>

  • DOS Fat fs support – built in.
  • MSDOS fs support – exclude (usually, except in cases where linux is mounted from a DOS partition).
  • VFAT fs support – built in.
  • NTFS support – built in.
  • NTFS debugging support – exclude.
  • NTFS write support – built in.

(The above options should actually be included as modules, but I would
recommend not doing so the first time. With experience you will learn
which features should generally be compiled as modules and then these
can be configured accordingly).

Pseudo Filesystems–>

  • /proc file system support – built in.
  • sysfs file system support – built in.
  • /dev/pts extended attributes – exclude. Again, you will know if you need it.
  • Virtual memory file system support – built in.
  • HugeTLB filesystem support – exclude. Not sure what this does.

Miscellaneous filesystems–>

All the options in the submenu can generally be excluded. They are not commonly used on Linux/Windows dual boot systems.

Network filesystems support–>

Again, all these options can usually be excluded. They are required only
on networked computers. If you are on a networked system then your
administrator should be able to tell you which filesystems are
required. Accordingly support can be compiled in.

Partition types–>

Only two options are to be included:

  1. Advanced partition selection.
  2. PC BIOS support.

If you use dynamic disks in Windows 2000 or later, then you should also include Windows Logical Disk Manager support.

Native Language Support–>

The default selections can be left as
they are. If you want you can choose which to include and which to
exclude (These are not really system critical).

Kernel Hacking–>

All the options in this menu are advanced features. It is best to exclude them from the kernel.

Security Options

1. Enable different Security models
Purpose: This allows you to use security models other than the default linux security model.
Suggestion – exclude. You may want to include this however if you are interested in using SELinux (security enhanced).

Cryptographic Options

It is safe to include all these options as modules. Don’t build them
in; otherwise your kernel size will increase dramatically. Compiling
these options into the kernel is recommended only if you use them very
frequently (eg. All your documents are encrypted using one of these

Library Routines
Both options can be included safely.

After you are finished, save the file and proceed to the Post Configuration section given below.

3. Post Configuration

In the interest of not scaring the hell out of you, I will tell you the
post configuration section first. First, check the dependencies
(whether you have all the tools you need). Information on that can be
found in ./Documents/changes.txt file. If you have a distribution running any
2.6.x kernel it should be fine.

After running one of the make *config methods and saving the .config
file you have to make the kernel (actual compilation process).

The command is: make.

Beware: the above command can take a little while. On my computer it took 6 or 7 minutes. It may take up to 15 minutes
or more on slower computers. Don’t worry if it throws up warning
messages. These are to do with the Linux source code and there is
nothing you can do about them (unless say you are a linux kernel

After the compilation is over you have to make the bzImage by issuing the command: make bzImage (case sensitive).

Make the modules: make modules

Copy the image to /boot directory: cp /usr/src/linux-2.6.6/arch/i386/boot/bzImage /boot/vmlinuz-2.6.6

Install the modules by issuing the command: make modules_install

Copy the system map to /boot directory by issuing the command: cp /usr/src/linux-2.6.6/

Change back to the /usr/src directory.

Create a symbolic link to the new directory
Ln –s linux-2.6.6 linux-2.6 (not always necessary)

Change to the /boot/grub directory: cd /boot/grub

Edit grub.conf and include the following lines:
title Kingkrool’s Linux kernel 2.6.6
root (hdx, y)
kernel /boot/vmlinuz-2.6.6 ro root=/dev/hdpn hdc=ide-scsi

The first line is the title to appear in the Grub screen. The second
line gives the drive on which grub is installed. x and y
must be replaced with the appropriate values. For example, for the
logical drive on the first physical drive x = 0, y = 1. This is not
fixed though. The best way would be to boot into Linux (using the old
kernel) and use the hardware browser (in System tools of RH /FC
distribution). Depending on your installation there will be two or
linux partitions. If there are three the smallest will be the boot
partition, the largest partition is root and third is swap. If there
are two then the larger one is boot+root and second is swap.

If the label given is /dev/hdb3 then x = 1, y = 2.

The third line gives the kernel location. If you have a dedicated boot
partition then /boot is not necessary in the path, otherwise the full
path is required (ie all paths are relative to /boot). In root=dev/hdpn
p and n are from above

If the drive was listed as /dev/hda8 then p = a n = 8 (copy as is).
hdc=ide-scsi (required for scsi emulation needed for CDRW etc, but
2.6.6 now can do without this if you have configured it properly)

The simplest way to configure the kernel is to copy the existing code
for any Linux kernel and just make a few modifications to the kernel
image path.

If you have compiled support for the filesystem of the root partition
as a module then you will have to add the following line at the end
(4th line)

initrd (/boot)/initrd-2.6.6.img
(/boot) is used only if boot and root partitions are the same.

The file intrd-2.6.6.img has to be made by issuing the command
/sbin/mkinitrd /boot/intird-2.6.6.img 2.6.6 (I have never done this)

Save the file and exit. Reboot your computer and you are ready to use the new kernel!

Remember to leave the old kernel entries intact, that way if you have problems you can always go back to the old kernel.


Please enter your comment!
Please enter your name here