Compiling, Configuring and Installing a fully-working Customized Linux Kernel


Kernel Corner


TranslationInfo:[Author and translation history]

original in en Subhasish Ghosh


My name is Subhasish Ghosh, I'm 20 years old, and currently living in India. I am a computer-systems engineering student as well as a Computer Professional. I currently hold 6 Microsoft Certified Professional(MCP) Certifications, and also a Microsoft Certified Professional Certified on NT 4.0 Track. I have been working with Linux for a long time, especially Red Hat Linux. I am currently preparing for the Red Hat Linux Certified Engineer(RHCE) certification Exam and plan to work primarily with the Linux operating system in the future.


Hi everyone, this article provides you with an extremely detailed and step-by-step process describing how to Compile, Configure and then Install a Customized Red Hat Linux Kernel. As we all know, a Customized Kernel is required for many reasons, and I wouldn't want to go into the gory details of those. I will only show how to Compile, Configure and Install a Custom Kernel. Though the steps mentioned below are primarily targeted for the Red Hat Linux users, but the same process applies to the users of other Linux Distributions also, of course, with a few minor modifications as when required.

ArticleIllustration:[This is the title picture for your article]




This is an instruction for compiling the Linux Kernel in 27 steps. I have performed all the steps mentioned below on a computer system with the following configurations: Compaq Presario 4010 Series computer system, 15.5 GB Hard Disk Space, 96 MB RAM, 400 MHz Intel Celeron Processor, Red Hat Linux 7.0 Distribution Release underlying Kernel: 2.2.16-22
Our aim would be to obtain a fully working Customized Kernel after all the steps mentioned below have been completed, for example, I have a Customized Kernel named "2.2.16-22ghosh" running on my system (cause my name is Subhasish Ghosh, you could have anything else, in fact a couple of them running together). So, happy hunting and compiling the Linux Kernel.

The steps

Step 1: Login as "root" and then perform these steps.

Step 2: At the command prompt, type in: rpm -q kernel-headers kernel-source make dev86

Step 3: If these RPMs are already installed, then proceed to step 4. Otherwise, mount the Red Hat Linux 7.0 CD-ROM and then perform a rpm -Uvh for installing these RPMs.

Step 4: If you have a fully working X Window System, then type in startx at the command-prompt. In case you don't have an X Window System configured, I personally would suggest you to have it done before proceeding cause it would be extremely beneficial. If X Window System is NOT configured, then type in make config or make menuconfig at the command-prompt. Please note that I have assumed that you have an X Window System running on your system, and for that reason, just type in startx.

Step 5: Then once within the GNOME environment, open the GNOME Terminal and type in: cd /usr/src/linux and press enter.

Step 6: Then from within /usr/src/linux, type in make xconfig.

Step 7: The GUI version of make config would come up on the screen. It provides you with various options that you have for obtaining a Customized Kernel.

Step 8: Now, I would suggest you to leave for the moment most of the options just as they are.

The default configuration is quite heavy. On the other hand it is probably one that will work on most computers. My suggestion is that you first complete all the steps to learn how this process works. After that you can then familiarize your self with your computer hardware and it's features such that you have enough "expert knowledge" and can tune your kernel to get a small and optimum kernel. A good place to learn more about the internals of your computer are files in /proc such as /proc/pci, /proc/interrupts, /proc/modules etc ...

For the moment don't try to fiddle around. For the purpose of this experiment just make sure you make the following changes:

1.Processor Type and Features: Choose the correct Processor depending on whether you are working on a Pentium 2, 3, or Intel Celeron like me. For example, I did the following: Processor Family: PPro/686MX, Maximum Physical Memory: 1 GB, Math Emulation: Yes, MTRR: Yes, SMP: Yes.

2.Open the Filesystems dialog and then make the following changes to it: For example I did: DOS FAT fs support: Yes(y), MSDOS fs support: Yes(y), UMSDOS: m, VFAT(Windows 95) support: Yes(y), NTFS filesystem support (read-only): Yes(y), NTFS read-write support(DANGEROUS): No(n). After you have made these changes, please make sure you haven't changed the others in the process. All these above-mentioned changes are quite harmless and won't cause any harm to your existing Linux Kernel.

3.Save and Exit from the Main dialog.

Step 9: Then, perform a ls -al from within the path: /usr/src/linux.

Step 10: I am sure you can see a file called: "Makefile". It is an extremely important file for this entire Compilation process. So, make sure you create a backup of this file, by using: cp Makefile Makefile.bak

Step 11: Now, do: (from within /usr/src/linux) vi Makefile.

Step 12: Go to line EXTRAVERSION and change it to something like this, for example I changed EXTRAVERSION=-22, to EXTRAVERSION="-22ghosh". You are free to name it anyway you wish.

Step 13: Save and exit the file.

Step 14: All the following steps should be done from within: /usr/src/linux. Type in: make dep clean, and press enter.

Step 15: Then type in: make bzImage modules. This would take some time, go and have a drink while it compiles all the necessary files. I usually take a nap during this time, cause I do all this stuff in the middle of the night.

Step 16: After this step is over, a "bzImage" file would be created in the directory /usr/src/linux/arch/i386/boot, just go to this directory and check whether a file called "bzImage" has been produced or not. IF AND ONLY IF all the compilation steps have been executed correctly and all the options that we have had chosen in make xconfig are correct, this file would be produced. If you can find this file, which I am sure you would, well, you can start enjoying already, cause you have won 75% of the battle. If you can't see this file, I am sorry, but you must have had made a mistake somewhere, just take a break and carry out all the steps again from the start. I am sure you would succeed.

Step 17: Type in (from within /usr/src/linux): cp ./arch/i386/boot/bzImage /boot/vmlinuz-2.2.16-22ghosh and press enter.

Step 18: Then type in: cp /boot/
Although not mandatory, I would suggest you to save the kernel configuration file (/usr/src/linux/.config) such that you have a reference to build later kernels without configuring everything again. The graphical configuration window (make xconfig) offers a possibility to load a configuration file. To save the configuration file type:
cp /usr/src/linux/.config /boot/Config-2.2.16-22ghosh

Step 19: Then type in: make modules_install and press enter. You would see all the modules being installed in a new customized directory.

Step 20: Then type in: mkinitrd /boot/initrd-2.2.16-22ghosh.img 2.2.16-22ghosh

Step 21: Then, type in: vi /etc/lilo.conf and then add the following entry:



Step 22: Save and exit. Please note that you can change the entries in the lilo.conf file as you desire, and the root should be the root in your system, in my machine, it's at /dev/hdc5. So, insert the info from your own system. The command
df | grep '/$'
will tell you where your root file system is. Note the single quotes around the expression behind grep.

Step 23: Type in: /sbin/lilo -v -v

Step 24: Read all the info on the screen. If there are no errors, well, the job's all done. Congratulations!!!!

Step 25: Reboot the system by typing in: /sbin/reboot or /sbin/shutdown -r now.

Step 26: In the start-up screen, press Tab (or Control-X, if you have the LILO start-up screen), and you can see the entry: "GhoshKernel" along with the other pre-existing entries.

Step 27: Type in: GhoshKernel and press enter. The fully working Customized Kernel will be seen booting on your system. So, you have a fully working Customized Kernel working on your system.

The result

Observe the boot process, the messages on the screen and check for errors. Later on you as well check the messages from the file /var/log/boot.log and the command dmesg. If there are no errors, well, the kernel works fine for your hardware. Very good!!

After logging in again type in: uname -a and press Enter. You can see the following entry on the screen: 2.2.16-22ghosh followed by the compile date and some other information. That proves that you are running a Customized Kernel. That's all. Also remember, that you can have as many number of Kernel versions as you like. In case this doesn't work out or you guys (and gals) face problems, make sure you do e-mail me at for questions and suggestions. I would really like to hear from you and help you and I hope this article helps everyone out there who wants to run a fully working Customized Kernel. Take care all.
Subhasish Ghosh