Objective.
Modify the kernel to streamline performance.

Tasks.
Create custom configuration using menuconfig,
Recompile modules and kernel,
Set modified kernel for use.

Recommendations.
If possible, practice first on a non-critical system. It's easy to screw up a working configuration, harder to repair. If you have the hardware, build a dummy system, have a play and don't panic if you kill it! Because we're only modifying the kernel here, user files and preferences will remain intact so even if the worst comes to the worst and the kernel has to be reloaded from the original installation media, your user profile will be as you left it (however programs and libraries installed since the last installation would probably have to be reinstalled).
As with any installation on any computing platform, it is good practice to ensure important data is backed up in case unforeseen difficulties arise.
Review all instructions on this page before you begin.

Page dependencies (ensure you have access to everything you need before you begin).
Commands issued at the command prompt in this section are done so as superuser or root unless otherwise specified.
Kernel editing in this example will be done using menuconfig which requires ncurses, a programming library used to write text interfaces. Use YaST2 Software Management to install the ncurses and ncurses-devel packages if not already installed. Without it you will receive an error along the lines of: [scripts/kconfig/lxdialog/checklist.o] Error 1 when you run the 'make menuconfig' command.
Kernel Sources will be required. If not already installed, use YaST2 Software Management to install.
The GCC C Compiler and Support Files are required. If not already installed, use YaST2 Software Management to install.
YaST2 installations will require access to installation sources (CD, DVD, network or Internet archives).

Text file editing from the command line.
This guide uses the Nano application for text editing because of its simplicity. Alternative text editors are available. Basic Nano key combinations to remember are CTRL-O to save and CTRL-X to exit.

Page format.
Text in this format indicates command line entry by the user.
Text in this format indicates an error returned by the system.
Text in this format indicates a normal return from the system.
Beware of similar characters such as 1(one), l(lowercase L), 0(zero), O(uppercase 'o'), | (pipe – Shift ' ' usually).
Text enclosed in [square brackets] indicates a build-specific variable such as a version number or user name.

Conditions.
This page was written for SuSE 10.1 and may contain content or instructions that are not relevant to other distributions.
This information is provided for guidance only. Use of these instructions is deemed to be at your own risk.
R3UK Limited welcomes comment on this information but cannot guarantee a reply and provides no technical support. Please use one of the many dedicated Linux forums or IRC channels if you require assistance.
Text colours and fonts used in the formatting of this page relating to command input and output are used for illustration purposes. Actual command line colours and fonts will vary according to individual system preferences.
GUI instructions were written for the KDE desktop environment and may differ for other desktop environments.

Procedure.
The kernel is the heart of the operating system and can be found in /boot as a file called vmlinuz[version]. The command cat /proc/version will show the kernel version and build date of your current system. An out-of-the-box Linux installation will contain parts you don't need and can be customised more to your particular hardware to run more efficiently if some of these unnecessary parts are stripped out. Before starting you should have a good idea of the hardware you are using or you may end up disabling something you wish you hadn't. The useful little command of hwinfo –-short will provide a list of hardware already detected by the operating system.

The next step will modify any existing /usr/src/linux/.config file. If you want to retain your existing .config file then back it up before continuing with cp /usr/src/linux/.config /usr/src/linux/.config.saved

At the command prompt, change directory to /usr/src/linux and issue the ‘make menuconfig’ command.
cd /usr/src/linux
make menuconfig

The kernel configuration utility should now open. To navigate around the tool use the cursor and enter keys to navigate through the menus while ESCape will take you one step back through the menu structure. An asterisk next to a device means support is built directly into the kernel while an M indicates support for the device is loaded in via a module when required.

As an example, I'm going to remove joystick support entirely from my kernel as I'm never going to be plugging a joystick into my laptop. Under the 'Input Device Support' menu is the 'Joysticks' menu. Some items in this menu are built into the kernel while others are provided via modules. I can select or deselect the individual items but in this case I want to remove all joystick support so I will deselect the Joystick menu itself from Device Support. This is done by replacing the asterisk with an ' n '.

Its worth running through the other menus taking out the stuff you know you don't need (e.g. no touchscreen? Remove touchscreen. No Bluetooth? Remove Bluetooth, etc). If in doubt on a particular item, leave it well alone. If you think you may be upgrading your hardware later then make a note of what has been disabled (e.g. if you've disabled Bluetooth and you buy a Bluetooth dongle six months later, you'll need to rebuild your kernel with Bluetooth support re-enabled). Once done, exit from menuconfig saving your changes. This will create a .config file under /usr/src/linux which contains your changes. If you re-enter menuconfig then it will open this file and display the changes already saved. If you want to run menuconfig without the changes (for example if you have made mistakes), delete the .config file and run menuconfig again to see the default options or you can reinstate any .config file saved earlier.

We now need to 'make' our new kernel with the changes we specified. This is done with the following commands (read through them before executing)...

make dep
... checks dependencies are in place although in some distributions this step is no longer necessary.

make clean
... removes old object files.

make modules
... recompiles the modules selected for use in menuconfig. This step takes a while (30-40 minutes on my 1.8GHz P4).

make modules_install
... installs the newly compiled modules into /lib/modules. For insurance, you may, if you wish, use cp -r /lib/modules/[version] /lib/modules/[version].old to take a backup of the existing modules directory before running this command. I have read elsewhere that the original modules directory should be removed before this command is run however if you do this you will cripple your system (USB and PCMCIA will cease to function as will some other devices such as your sound card). Backup the directory as above by all means, but install the newly compiled modules into the original directory.

make bzImage
... starts compiling the kernel with the changes we specified. Note the uppercase ' i ' in this command. Remember, Linux commands are case sensitive. This command will create a compressed kernel image called 'bzImage'. There's no need to uncompress the created file, this will happen automatically when the computer starts up.

A couple of side notes to the above commands. Unrelated commands can be strung together on the same line separated by semicolons, but related commands such as the above group of 'make' commands can all be entered on the same line without the semicolons. We could therefore have used make dep clean modules modules_install bzImage instead of listing the commands individually. Assuming no errors, this instruction would have run through all of the above procedures unattended. If you're new to this sort of thing though, you may want to run the commands separately so you can monitor the outputs and watch for any errors. Another useful thing to know is that hitting CTRL-C during the kernel or module compilation stages stops the process. You can then issue the relevant 'make' command again to restart it.

Once make bzImage has finished, you should find a new compressed kernel image called 'bzImage' under /usr/src/linux/arch/i386/boot. In order to use this kernel we need to move it to the /boot directory and rename it. We can move and rename our image file with one command as follows:
cp /usr/src/linux/arch/i386/boot/bzImage /boot/vmlinuz

Copy the system.map file from /usr/src/linux to /boot and rename it with the kernel version. An example is:
cp /usr/src/linux/System.map /boot/System.map-2.6.16.13-4-default

Create a symbolic link from System.map[version] to System.map.
ln –s /boot/System.map-[version] /boot/System.map

If we switch to the /boot directory and use the ls-l command we should now see a new vmlinuz-[version]-default file and System.map showing up-to-date timestamps.

The new image effectively replaces the old as it is using the old filename, therefore if we reboot, it is the new kernel that will be loaded. Before we finish though, it’s worth taking a look at GRUB, the default SuSE boot loader.

To edit the GRUB boot loader, switch to /boot/grub and edit the menu.lst file with nano or your text editor of choice.
nano menu.lst

My GRUB menu.lst boot loader is shown below.

# Modified by YaST2. Last modification on Sat Aug 26 12:27:09 BST 2006

color white/blue black/light-gray
default 0
timeout 8
gfxmenu (hd0,1)/boot/message

###Don't change this comment - YaST2 identifier: Original name: linux###
title SUSE Linux 10.1
root (hd0,1)
kernel /boot/vmlinuz root=/dev/hda2 vga=0x317 resume=/dev/hda1 splash=silent showopts
initrd /boot/initrd

###Don't change this comment - YaST2 identifier: Original name: failsafe###
title Failsafe -- SUSE Linux 10.1
root (hd0,1)
kernel /boot/vmlinuz root=/dev/hda2 vga=normal showopts ide=nodma apm=off acpi=off noresume nosmp noapic maxcpus=0 edd=off 3
initrd /boot/initrd


Finally comes the acid test. Reboot and select the new kernel from the startup menu. If it works, great! If not, remember you can press F2 during startup to hide the pretty SuSE picture and display startup messages which may give an indication of any problems.