Wednesday, August 02, 2006

How to make changes in Linux Kernel ?

Shape up and trim down your Linux Kernel

The real beauty behind Linux is that it is highly customisable in its every part. You can blush on, shape up and trim down Linux Kernel as per your specific need and optimise it for your individual system and hardware. As a user, you cannot sniff upon Kernel of other commercial operating system such as Windows Kernel and you have to accept it as it is. Whereas, Linux gives you total freedom to shake it, shape it and even hack it to suit your best need. Here is the method described below for you to learn how it is being done.

What is a Kernel?

A Kernel is a program that is loaded at start up time to provide interface between different software and hardware and perform tasks such as reading and writing to disks, managing memory and networks etc. In purely technical term, Linux is only the kernel and number of other programs such as text editors, Window managers, File manager etc., makes up the distribution like RedHat or Mandrake. There are several Linux distribution exists, but the Kernel is common to all of them.

Like other programs, Linux Kernel is always in developer’s hand to get updated frequently for more functionality, more support, stability and bug fixes etc. Periodically, new versions of Linux Kernel are released. Currently, the latest version of Kernel has release No. 2.4.XX which indicates the major number, the minor number and the revision number.

Need for Linux Kernel configuration

When you install a Linux distribution- say, Linux Mandrake that had distributed previously through i.t. CD, the Linux Kernel is automatically installed. This Kernel is so compiled that majority of standard system and hardware are supported and if your system have no unusual configuration, then it will work fine. But it needs recompilation when you have some new device that is not supported in your existing Kernel. Similarly, standard distributions are configured for more devices than you actually have, and in result, Kernel takes more memory than necessary for your system and thus you need new, trimmed down Kernel. When a security hole is found or a bug appears, a patch for Linux Kernel released immediately and you have to apply that patch to your Linux Kernel by recompiling it with the patch. Finally, you have installed Linux in your machine and living happily till the other day when a major, newest and stable Kernel is released; then you have to install and build a new Kernel.

Kernel Sources

Normally, every Linux Distribution contains Kernel source for recompilation at user’s end. Newer versions of Kernel are released over Internet at various sites such as or etc. The Kernel source is distributed either as compressed tar file or in RedHat’s rpm format, ready for installation. Some time, for a major Kernel release, patches are released as immediate measure to patch security bugs etc. within days when they are found. These patches are very small in size as compared to full Linux Kernel source and can easily be downloaded from Internet. Installing the Kernel source available in rpm (RedHat package manager) is fairly easy. Simply login as root, start Xwindows, fire up utilities like Kpakage, browse to the Kernel source file, click open and then click install. It will install in /usr/src/linux directory (see fig.1 & 2). If you have chosen ‘everything’ at the time of installing Linux through a standard Linux distribution such as i.t. CD Linux Mandrake, then it is highly probable that your Linux Kernel source is already there in /usr/src directory. Now you have Linux Kernel Source in your hand, get ready to build a Linux Kernel that specifically suits to your machine.

Be warned that recompiling a new Kernel can be potentially dangerous. You must back up all your data, get start up disks and rescue disks handy if your silly mistakes may make your system unbootable with a new, broken Kernel (everyone does it at times, so do not loose heart in such situation). Do not remove your old Kernel. You may need it when your new Kernel will refuse you to deliver things. Do not use Development Kernel (normally indicated through an odd revision number) in your production system. It is a better idea to back up your existing Kernel and Module and configure your machine to start with old, working Kernel as an option.

Configuring Kernel

You need to configure your Kernel Source prior to compiling. This can be done in various ways. One is through command – make menuconfig this is suitable if you have not installed Xwindows in your system or if you feel comfortable in command line configuration dialogues. The other command is – make xconfig this is Xwindows based utility and is recommended for most user. Another command is- make oldconfig which is suitable if you want to retain your old configuration and simply want to upgrade to a new Kernel. Since GUI based administration is relatively easy to configure and remember, go to the /usr/src directory, fire up make xconfig and get ready to configure your Kernel (see fig.3).

Prior to configuring your Kernel, make sure that essential driver should be selected as Y (such as your file system) else your system may not boot. Similarly, unnecessary Driver in kernel will make it bigger and need more memory and more processing power. Be conscious in selecting your configuration else you may find errors. If you compile your Kernel with Processor type as Pentium then it will make your Kernel to give up and not boot if you have 486 or lower system.

Options for Linux Kernel Configurations

If your Xwindows is up and running, make xconfig command will run provided you have installed make package. You also need gcc compiler later for Kernel Compilation. But do not worry, if you have selected Kernel Development as an option during your Linux installation and have not disturbed the default package dependency option, then these and other utility required for kernel compilation will be there. Else, you will be prompted as- ‘command not found’ during this process.

As you can see in fig.3, the Linux Kernel configuration window contains numerous tabs. The look and feel of this window may differ depending on your version of configuration package that you have installed. You can click any button on it and another window containing sub menu will appear for you to choose your options. The first option is code maturity level option. Click this and a new sub menu will appear (see fig.4). You will find here only Y and N options which you can select since the Module option is not available. Selecting Y will give you freedom to install incomplete and development code and drivers. If you select N then all such options will be greyed and will not be available for compilation. It is safer to say N if you do not plan to use things still under development stage. Note that the Y option will make that particular driver always up and running, the M option will run that particular driver when need arise, and the N option will not be installed hence you may not be able to run those drivers.

Processor type and feature

The next option you find in main menu is processor type and feature. Here, you have to select your appropriate processor type, be it 486, Pentium or Other. You can see that in left side of every sub menu, there are buttons named Help, which are available with options. If you are not sure what this option is meant for, then you can click this Help button to find detailed help about the selected option. Help for some of the option may not be available and the language of Help may look harsh to you, but then you are doing serious business of Kernel configuration here and you must be serious enough as the help language suggest. In this sub menu, you will find Math Emulation as an option. You can safely select N since all newer processor comes with Math coprocessor built in. If you have more than one processor in your system, then you can opt Y for Symmetric multi-processing support. Here again, if you are not sure and want to know more about the selected options, then feel free to click Help button (see fig.6 &7) and read the help content. At times you may also find entries indicating that detailed documentation regarding the option in question is available at some other location that may be further referred in case of any doubt. (see fig.10, where Documentation/sysrq.txt has been mentioned for further reading for the selected option)

Block devices

Block devices sub menu (see fig.8) gives you a number of options to select that extends right from chipsets of your motherboard to floppy disk, hard disks and other devices. Go to every option and check whether you need it and whether your machine or network has that particular hardware installed. But you must select Y for floppy, CDROM, IDE devices etc. since there is no way to access these devices without these drivers installed in your Kernel. You may find numerous other newer options as the Kernel evolves and new and new devices are supported and added. In Linux Kernel, some old devices are supported as well and you may find options there. If you are quite sure that your machine is relatively new and you don’t have any old device installed in your machine then you may safely select N for those options. These are there for mere backward compatibility (such as XT Hard disk support, which nobody uses these days).

SCSI support

If you don’t have any SCSI device installed in your system then you may select N for SCSI Support (see fig.9). When this option is selected as N then all other options below this will be greyed and you can’t change any option further, since they are related and are like sub options of SCSI Support main option. When you say Y for the SCSI Support, then you can set individually all the options whether you have SCSI Tape, CD-ROM or Disk. Similarly, you may find options for Joystick, ISDN, Radio, InfraRed device support and numerous other devices, and if you have none of these, then you say N for these (see fig.3). Be particular in Networking and Network device support options, else your system may become an isolated, orphan if any thing is set wrong here.

Kernel Hacking

The help on this option (see fig.10) warn you that- don’t say Y unless you really know what this option does. So there you are. You must get more information about the subject as the Help button described you to get from. However, if you rate yourself serious, repeat, serious programmer type, and related to kernel development, testing etc., than you may set this option as Y, but then your Kernel will become less stable. In short, during Development phase, this option force and ensure the system to test all possible path of execution get exercised and tested so that bugs and holes if any may be detected, reported and resolved.

Video for Linux and Sound options

As you can see in fig. 3, there are options available for practically every part of computing devices that probably you may have. All those options are for your specific Card or chipset and you have to say Y, N or M as the case may be. If you want your device occasionally, then you may safely say M for the drivers for these devices to installed as Module. When a driver is installed as module, it will run only when the need arise and shut down or go in sleep mode when not required and thus save your Kernel memory. Devices like Sound Card are normally opted as M in Linux Kernel configuration. You know that there are numerous Video Card and Sound Card in the peripheral market. So far, Linux was trailing behind in support for these devises but now it has catch up with the race and you may find support for latest drivers in the Kernel configuration. So go to entire option list and select the option for your device. In all probability, you may find an option for your newest Sound Card, Video Card and other device as well.

Build the Configured Kernel

If you have configured all the available options, and know and understand what you have done in your Kernel configuration, then click save and exit button in main menu (see fig.3). Your configuration has now been saved in a file and will be utilised during Kernel compilation.

Now give command make dep (see fig.11). This command will make the dependency tree for Kernel Compilation. You will see some text generating in the terminal automatically during this process. You may encounter some error messages during this process. If this is the case, then you have to write down the error message. The support personnel may need this later. When everything is fine and you do not get any error message, you will be back to command prompt without any error message. Now give command make zImage . Your newly configured Kernel will start compiling. It may take some time depending upon your system’s processor speed and its memory and selected options. It may take a few minutes for Pentium Class machine having sufficient memory to a few hours if you have older 486-class machine with less memory. As the Kernel Compiles, you will see all the commands and results of commands scroll down your computer’s screen. You don’t need to understand the compilation process, but your background of C programming and compiling program source may help you in case of any error during compilation. When the compilation is over, give command- make modules this command will compile all the drivers that had been selected as module during configuration. Let us hope that these compilations complete without any error message and now you are ready for further actions (see fig.12 which shows end of compilation without any error). Now you have build yourself a fresh, trimmed down Kernel named zImage, which is available in the directory /usr/src/linux/arch/i386/boot/.

Install new Kernel

You can install your new Kernel by either editing /etc/lilo.conf file (see fig.13) or by running command linuxconf (see fig. 14). Prior to that, you have to copy your new Kernel to /boot and give an appropriate, new name to recognize it from other, old Kernel. You have to install your Modules too. For that, rename (you can delete it later) your existing module which is there in /lib/modules directory. Now go to the directory /usr/src/linux and give command make modules_install . This command will install your new module in /lib/modules directory. Finally, edit /etc/lilo.conf or run linuxconf as had stated earlier to add the new Kernel image file. Save the changes and run command /sbin/lilo. It will prompt you that it had added your new Kernel. Now reboot your system and delightfully see the new Kernel, which is being loading.

No comments:

More Articles...

Translate in your own language

Want to translate this article in your own language? Just click the Flag below