User Guides How to recompile the Linux Kernel

(Not an official HowTo)

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. After that your home free.

I will divide this tutorial into three parts:
1. Preconfiguration
2. Configuration
3. Post Configuration

I have used kernel version 2.6.6. This tutorial 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 distro) with Grub as the boot manager.
The procedure to be followed for other kernels will 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

1. Visit www.kernel.org and download the latest stable kernel (at the time of writing it was 2.6.6).
2. Change user to root : su
3. Copy the downloaded kernel to /usr/src
4. Uncompress the kernel
5. bunzip2 linux-2.6.6.tar.bz2 if you have the bzipped format
6. gunzip linux-2.6.6.tar.gz if you have downloaded the gzipped format
7. tar –xvf linux-2.6.6.tar
8. Change to the linux directory: cd linux-2.6.6
9. Make mrproper to remove any old configuration files or object files.
i. make mrproper
10. If you want to use an older configuration file then copy it over to .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.
11. 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 go with make menuconfig. It simple in its design and easy to understand considering that there are well over a thousand options distributed under various subheadings.
 
3. Post Configuration
In interests of not scaring the hell out of you, I will tell you the post configuration section first. Firstly 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 distro running any 2.6.x kernel it should be fine.

1. After running one of the make *config methods and saving the .config file you have to make the kernel (actual compilation process).
2. The command is : make.
3. Beware : the above command can take a little while. On my steroid bolstered 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 developer).
4. After the compilation is over you have to make the bzImage by issuing the command: make bzImage (case sensitive).
5. Make the modules: make modules
6. Copy the image to /boot directory: cp /usr/src/linux-2.6.6/arch/i386/boot/bzImage /boot/vmlinuz-2.6.6
7. Install the modules by issuing the command: make modules_install .
8. Copy the system map to /boot directory by issuing the command: cp /usr/src/linux-2.6.6/System.map /boot/System.map-2.6.6
(NOTE: needed only for 3rd party boot managers. Thanks, Abhay)
9. Change back to the /usr/src directory.
10. Create a symbolic link to the new directory
ln –s linux-2.6.6 linux-2.6 (not always necessary)
11. Change to the /boot/grub directory : cd /boot/grub
12. 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
(NOTE: hdc=ide-scsi is no longer needed in 2.6.x for CD recording)

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. Eg. For the second 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 distros). Depending on your installation there will be two or three 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.
 
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 run down 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
*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 doing you can include it. This is only for developers or people who have ean excellent idea of their hardware configuration. May be required to provide support for new features.

General setup
*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.

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

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

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

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

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

*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).

*Support for hot pluggable devices
Purpose: Required for USB, PCMCIA etc.
Suggestion – built in.
*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 develpers.
Suggestion – exclude.

*Configure standard kernel options
Purpose: Lets you specify configuration of standrrd 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

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

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

*Automatic Kernel Module Loading
Purpose: Allows certain parts of the kernel to automatically load kernel modules using modprobe. Its probably a good idea to include this unless you are sure of what you are doing.
Suggestion – built in.
Processor type and features

*Subarchitecture type – Select PC Compatible (unless you are running non x86 systems)

*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 sur 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.

*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 another architecture.
Suggestion – exclude.

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

*Symmetric Multiprocessing support
Purpose: Required to take advantage of multiplt 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.

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

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

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

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

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

*Check for P4 thermal throttling interrupt
Purpose: Prints a message whenever the P4 enters thermal throttling.
Suggestion – user's choice.
*Toshiba Laptop Support
Purpose: Useful only on Toshiba Laptops having a Toshiba bios.
Suggestion – exclude unless your system satisfies the above criterion.

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

*/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.

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

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

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

*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).

*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).

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

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

Addendum: Enable SMP support for HT processors.
Power Mangement 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 runing on mobile pentium or athlon processors.
Bus Options
*PCI Support
Purpose: Required if the system bus is PCI (as it is on almost all systems from P1 upwards).
Suggestion – built in.

*PCI Access Mode – any.

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

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

*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 replaces the device names by device IDs. It also reduces kernel size by 80KB.
Suggestion – built in. If you are creating a boot disk then it can be excluded.

*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 therfore 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 priming).

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

*NatSemi SCx200 support
Suggestion – Required only if you have the National Semiconductir
SCx200 procesor. Exclude for most systems.

*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

*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 critical.
Suggestion – built in.

*Kernel supposrt 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 binries lying around.
Suggestion – exclude. If absolutely necessary then include it as a module.

*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 thousnads 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 n/w 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 driver).

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 journalling 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 suport – 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 ae 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 froom the kernel.

Security Options
*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 algorithms).

Library Routines
Both options can be included safely.

After you are finished save the file and proceed to the Post Configuration section given earlier.
 
Later Additions:
You may want to compile ReiserFS in. It is by all accounts a beauty of a File System (go to www.namesys.com for more details) and is used extensively in Mandrake, SUSE etc (basically everybody but RedHat)
 
All the info is available in the kernel configuration tools. I just translated it into a more understandable language. The idea was to encourage u guys to try it, by making it seem a bit easier.
 
Back
Top