FreeOS.com logo

FreeOS Most Popular
* Most Read stories
* Commented Stories
* Active Categories
* Non Linux Section
* User Submitters
* Top Polls
* Top Authors
* Top Reviews
* Top Rated
* Top Search Terms

Top Articles
* Writing a Linux device driver
* The Linux filesystem explained
* Samba NT Domain Controller
* Setting up Squid as your caching HTTP/FTP proxy
* Web server tutorial - Part 1

FreeOS Highlights
* Howtos (72)
* Reviews (20)
* Opinions (18)
* Interviews (8)
* News (3)

My FreeOS

Nick:
Pass:
Register

Forgot your password?

Contact Us
Contact Us

       

Project: Linux triangle Howtos triangle

How to roll your own Linux

By Varun Singh <Varun_Singh@jasubhai.com>
Posted: ( 2001-07-03 04:46:28 EST by ramnath )

Recompile the Linux kernel to add functionality and squeeze out the best from the system. And you don't even have to be a programmer to do this.

ZDNet LogoTime was when after writing their own device driver program, boys fancied they had grown up into men. Till Linus Torvalds came along and made them feel rather puny. Torvalds set out to write an entire kernel and the results, if one were to go by the cult following Linux still commands, were quite spectacular!

So what's a kernel? Here's how the Linux Kernel How-To describes it:

"The Unix kernel acts as a mediator for your programs and your hardware. First, it does (or arranges for) the memory management for all of the running programs (processes), and makes sure that they all get a fair (or unfair, if you please) share of the processor's cycles. In addition, it provides a nice, fairly portable interface for programs to talk to your hardware."

A kernel is simply the piece of code that builds the base on which a whole OS can be designed. Applications must go through the kernel to perform tasks and use processing power, memory, devices and disk access. This makes the kernel the most important part of a Unix system.

Linux became the most popular of the Unix systems because it was open-sourced. Everyone could get the Linux source code and use, modify and customize it--to be recompiled to suit individual needs. And these were all for free! So, hordes of people pitched in to develop the Linux kernel, helping the OS incorporate many new features and device drivers. The Linux kernel now supports thousands of devices. And the number is increasing every day.

With support for so many devices, the kernel's performance is bound to take a beating. If not properly implemented, the kernel can add to the size of the code and end up consuming more memory in loading unnecessary drivers.

That's how the idea of kernel modules came from. Kernel modules are small attachments to the base kernel which allow it to incorporate support for many devices, without programming them straight into the kernel. This helps the kernel remain compact and still be customizable to support many devices.

The default kernels bundled with many Linux distributions are neither optimized, nor do they support SCSI emulation that's needed for CD writing while using a non-SCSI CD Writer. Instead, they include support for many common devices and interfaces that aren't used in all systems--parallel ports, various sound cards, unused file systems and devices, PCMCIA ports, network cards and so on.

You can always recompile the Linux kernel for a particular system and hence add functionality, or tweak it to get optimal performance. The fun part is that you don't need to be a programmer to do this: there are automated configuration scripts to help you out.

Three kinds of configuration scripts are available:

The standard sequential 'make config' that asks you hundreds of questions about almost every kernel option that can be tweaked;
The 'make menuconfig' that gives you a menu-based interface to the same options;
The 'make xconfig' that gives you a graphical interface--quite like the menu-driven 'make menuconfig' in the X Window System.

But, before you set about exploring the exciting world of kernel modules, make sure you have some necessary things with you. The first is the kernel source code, itself. Almost all Linux distributions come with kernel source code packages. You can install them using either the GnoRPM or KDE Package managers, or manually, with the standard RPM tool. Just switch to the directory where the kernel source RPMs exist and do an 'rpm -ivh kernel-source*.rpm'. This should install the kernel source code in the /usr/src/linux-x.x.xx directory, where x.x.xx is the version of the kernel source.

Change to the /usr/src/linux-x.x.xx directory and run 'make menuconfig'. This makes it easier to understand what each option means before you use them. If you're running X, just type 'make xconfig' and you'll get a GUI-based system to do the same work, while, in the 'menuconfig' mode, you can just type '?' to access specific comments and help about a particular option. Make sure you read what a particular service can deliver before you plan to disable it. The same can be done in 'xconfig' mode by using the 'Help' button.

To ensure the kernel re-mains small in size, load most options as kernel modules rather than compiling them straight into the kernel. Do this in the 'menuconfig' mode. A* in front of the option means it's selected; an M means it's to be loaded as a module; and a blank means the option is not selected. In the 'xconfig' mode, this is indicated by y (="yes"), m (="module") and n (="no").

If you want to configure Linux for a server, you may want to eliminate support for things like sound cards, PCMCIA slots, unused file systems (everything except file systems like EXT2, DOS, ISO9660, Joliet and VFAT which are needed most of the time), IrDA support, Video for Linux, joysticks and amateur radio support. This makes the kernel much smaller in size, without the risk of missing out on some devices.

If you feel you know what your system needs and fancy adventure, go into your computer's network configuration to remove the extra network card drivers and tweak the TCP/IP options. That will make a difference, however small, in the kernel size and performance. You can, of course, always select the processor type of your machine for compiling a kernel optimized for that particular processor class.

Once you've made the selections, save your configuration to an alternate file for using it later, if needed. If using 'menuconfig', just select Exit and it will ask you to save the configuration. Say Yes, and it saves the configuration to the 'makefile'. If you're using 'xconfig', just choose Save and exit.

Now ensure that you're in the /usr/src/linux-x.x.xx and give the command 'make dep'. This command ensures that all files needed for compiling the kernel are in their proper place. Once this process is finished, type 'make bzImage' (note the 'I' is in the upper case). This begins the kernel-compile process. In earlier kernel versions, the command was 'make zImage'--an option still available--which shows an error message saying the kernel image is too large because it can't handle the large-size code.

The kernel takes time to compile. Be patient! Once the process is complete and you don't see any errors, you'll have a file called 'bzImage' in the /usr/src/linux-x.x.xx/arch/i386/boot/ directory. This is your new kernel.

Now copy this file into the /boot directory and rename it to 'vmlinuz-test'. Then open /etc/lilo.conf in your favorite text editor. It will already have an entry used to boot your existing kernel that looks something like this:
image=/boot/vmlinuz-x.x.xx-xx
label=linux
read-only
root=/dev/hda1

Clone this entry, as it stands, just below the last line in the file, and replace the 'image=/boot/vmlinuz-x.x.xx-xx' with 'image=/ boot/vmlinuz-test'. Now change the 'label=linux' to 'label=lintest'. Save the file and exit the editor.

Now type 'lilo' at the command prompt. This whole process adds your newly compiled kernel to the boot list of lilo, the Linux loader, without removing your existing Linux kernel. This ensures that even if the newly compiled kernel doesn't work as expected, you can still boot your machine with the older kernel.

Now reboot your machine. And, the next time 'lilo' prompts to load an OS, just type 'lintest' to make a new kernel boot-up. If this doesn't work, don't panic. Just reboot your machine and use the default Linux kernel you used to boot it in the first instance and you'll be back where you started.

If, however, this succeeds, and everything functions just fine, swap the 'label= lintest' line in the fresh entry you made with the default entry's name (in this case, the name will be 'label= linux' in the /etc/lilo.conf). Then change the default entry of the old Linux kernel to 'label=linback' and run 'lilo'.

This way, you make the new kernel your default kernel and preserve your older kernel in the boot menu -- just in case you ever need it.

Other articles by Varun Singh

Current Rating: [ 8.07 / 10 ] Number of Times Rated: [ 101 ]

More Howtos
* Kernel Compilation & Avoiding ‘Unresolved Symbol’
* Configuring CVS and CVSUP on Linux
* Knoppix installation tips
* Maximum Mount
* A WebServer Guide -- Help Using Apache

Contents
Articles
  Howtos
  Interviews
  News
  Opinions
  Reviews
Comparison
Links
  Articles
  Howtos
  Interviews
  Opinions
  Reviews
  Websites
News

Linux
About Linux

Print It!
Printer Friendly Version