KERNEL FUN & GAMES


What is the kernel, and why would I want to change it anyway?

That is a perfectly legitimate question, and one I would have asked myself in the early stages of learning Linux.

The kernel is the interface between the Linux Operating System and your computer hardware. It contains, and allows you to specify the loading of, all the hardware drivers. If it all works correctly, your software (applications) will be able to function as intended. Remember Windoze, Plug 'n' Pray, and all those messages about not being able to find suitable drivers in the specified location? Well, this is the same thing for Linux, but thankfully presented in a more controllable fashion. And you control it!

The second part of the question (why change the kernel?) is also simply answered. When you start up (boot) your system, the initialization processes "look" at all the hardware you are trying to address, and make intelligent guesses as to the correct drivers and options to use. Maybe the guesses are inappropriate (as can often be the case with new hardware and laptop configurations). To get your hardware working correctly, it is sometimes necessary to "tweak" the kernel configuration options. This is not the easiest thing in the world to do, as you will see later in the current section...

What follows can be extremely hazardous to the health of your shiny new laptop. It may even damage your own sanity... Please follow the instructions in this section very carefully, and if they go wrong, don't blame me!

Why do I need to read all this, when there are official Linux Kernel Howtos available?

Red Hat 8.0 ships with a custom kernel, including support for the ext3 journaling file system and USB devices. Correct operation depends on a RAM disk (/dev/initrd) being initialized (e.g. loaded) by the boot loader before the kernel is started. Misconfiguration of any of these items will on the Toshiba laptop leave you with a nightmare situation: a computer that is unable to read from some or all of the following - hard disk, USB floppy disk, IDE-SCSI CD-ROM... Worse still, you will not be able to connect to external devices via serial, PCMCIA or ethernet ports.

Unfortunately, these aspects of modern laptop "design" are not well covered in the many FAQs and HOW-TOs relating to kernel modification. Nor are the quirks of Red Hat 8.0! That is why it is REALLY important to make a recovery CD as described below, and to back up all your data before starting any of this.

Making a recovery disk...

Please be sure to create an emergency boot CD, if you do not already have one. (A conventional boot floppy will not work with RH8.0 on this PC). There are various ways of creating a bootable CD, but the easiest method I have found is to use the "disaster recovery" utility mkcdrec:

  1. Make a note of your hard disk partition mount points. For example, on my PC, /dev/hda1 is mounted as /boot, and /dev/hda2 is mounted as /.
  2. Close your present session and login as root (not "su root" or "ssh root@localhost").
  3. Download a copy of mkcdrec from this site and install from rpm file, e.g. rpm -ivh mkcdrec-v0.7.1-1.i386.rpm
  4. cd /var/opt/mkcdrec and make test : you should see two error messages, one about a link being corrected (ignore) and another about your SCSI CD device address.
  5. Edit the file "Config.sh" so that SCSIDEVICE = "0,0,0" and WRITERSPEED = "8". Also (very important or none of this will work) ROOT_FS=ext3.
  6. Run make test again and all tests should pass. For more information, please read file:/var/opt/mkcdrec/doc/index.html
  7. Insert a blank CDR into to the drive, and simply type make . This will give you a menu: for a basic recovery disk without file backup, select option 1.
  8. Once the boot CD is successfully created (be patient...) you can test it as follows: (a) shutdown the computer, (b) switch on and press <Ctrl> <Esc> until you get a setup menu, (c) change the boot device order so that CDROM is first in line, (d) press <End> and Y. The system should now boot from the CD you created, and a range of recovery scripts are available in /etc/rescue. Please do not try to run any of these until you have read and understood the mkcdrec documentation!
  9. Check that you can access your hard disk partitions. First, you have to mount them. Using the example given above (step 1):
    mount -t ext3 /dev/hda2 /mnt/local then mount -t ext3 /dev/hda1 /mnt/local/boot.
    Change directory to /mnt/local then /mnt/local/boot, and you should be able to access all your files (including grub/lilo configuration and other useful bits!). Don't forget to
    umount -l /dev/hda2 and umount -l /dev/hda1
    so you protect all your saved data.
  10. If you are happy that the boot CD is working, shutdown and change the computer's setup options so that it boots from HDD again.
  11. Finally, before making any changes to the kernel, revert your video driver in XF86Config to 16-bit VESA. This will avoid any possibility of an X-server crash when you re-boot. You may have to re-install the NVidia drivers later. See this page.


Starting from a known point...

All of the following instructions assume that you are logged in as root. Bear in mind it is possible to do a lot of damage if you enter a command incorrectly, so please take your time.

You must have the Red Hat kernel-source package installed. Check by doing:

$ rpm -q -a | grep kernel-source
and you should see "kernel-source-2.4.18-x", where 2.4.18-x is the same version number as the one you get from uname -r. If you do not have kernel-source installed, please download the rpm file from Red Hat and install it before going any further.

The Red Hat Linux 8.0 kernel source tree is referenced by /usr/src/linux-2.4 : this is a symbolic link to the actual kernel directory which is /usr/src/linux-2.4.18-14. The suffix "-14" is the "EXTRAVERSION" of the kernel, indicating that it has been customized by Red Hat from the official 2.4.18 kernel. It is a good idea (indeed, I would say it's essential) to name your own custom versions of the kernel in a similar way. For example, 2.4.18-14test1 would be a good name for your first test version. You can change the "EXTRAVERSION" or customization reference of the kernel by editing a line near the beginning of /usr/src/linux-2.4.18-14/Makefile. In this example, you would change "EXTRAVERSION = -14" to "EXTRAVERSION = -14test1".

Note: If you have not previously installed the NVidia display drivers as detailed elsewhere in this guide, the default EXTRAVERSION will be "-14custom". Just change the "-14custom" part to your own chosen label, like "-14test1".

Staying in the directory /usr/src/linux-2.4.18-14, look for a file named .config and make a backup copy of it somewhere else. Put it in your $HOME directory, if you like. Before you start the new build, it is important that the kernel tree is in a known state. Execute the shell command make mrproper. After this has finished cleaning everything up, you now have two choices:

  1. Use the .config file you had already, and modify it. (Perhaps you want to keep some previous changes to it?). In that case, copy the backup .config you just made to /usr/src/linux-2.4.18-14/.config
  2. Revert to the Red Hat Linux 8.0 default configuration. This is the safer option. To do it,
    $ cp configs/kernel-2.4.18-i686.config .config
    and remember, for it to work, you must be in the directory /usr/src/linux-2.4.18-14 and there should be a symlink from /usr/src/linux-2.4 >> /usr/src/linux-2.4.18-14

How to change the configuration -

There are various tools for doing this, but the easiest in my opinion is the graphics based interface, "xconfig". To start it, type: make xconfig

Then choose the desired kernel options. There is an excellent site which gives advice on correctly setting options for the Toshiba Satellite Pro 6100 - follow this link. Also, take account of any specific configuration requirements that may have been mentioned on the current page, or elsewhere on my site. When you have finished, select the option "Save and exit".

Xconfig will tell you to check the top level Makefile (/usr/src/linux-2.4.18-14/Makefile), so please do it now, and make sure (again) that the EXTRAVERSION is set to what you think it should be...! If you keep it at EXTRAVERSION = -14, the following steps will OVERWRITE your default linux kernel, with possibly catastrophic results.

Everything OK so far? Now comes the really tedious bit - and please do not sit watching all the compilation commands or you will definitely go mad. Find something else to do for the next 2 hours, while keeping half an eye open for compilation errors...

  1. make dep #sets up all the dependencies
  2. make clean #prepares source tree for the build, cleaning out superfluous drivers
  3. make bzImage #makes a compressed boot image
  4. make modules #builds all the modules you requested
  5. make modules_install #installs the modules into /lib/modules/(kernelversion)/kernel/drivers/
  6. make install #copies the boot image (vmlinuz-kernelversion) and ramdisk initialization image (initrd-kernelversion.img) into your /boot directory and sets up the System Map

If there are any problems during the above processes, all I can suggest is that you start again from the beginning, and if that fails, do a "Google" search on the error string you are getting. Someone else may have run into the same problem.

Check that you have the relevant vmlinuz, initrd and System Map files in your /boot directory. For example, if your EXTRAVERSION name is -14test1, you should see files with that suffix included in their name.

Now configure your boot loader. I use Grub, for which the relevant configuration file is /boot/grub/grub.conf. Here is an example:

default 0
# Note: default 0 points the boot loader to the first kernel option (default) below.  When the splash screen comes up, you have 10 seconds to choose the other option(s)
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/hda2
#          initrd /initrd-version.img
#boot=/dev/hda
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
password --md5 *********
title Red Hat Linux default kernel (2.4.18-14)
        root (hd0,0)
        kernel /vmlinuz-2.4.18-14 ro root=LABEL=/ hdc=ide-scsi
        initrd /initrd-2.4.18-14.img
title Red Hat Linux (test config 2.4.18-14test1)
        root (hd0,0)
        kernel /vmlinuz-2.4.18-14test1 ro root=LABEL=/ hdc=ide-scsi
        initrd /initrd-2.4.18-14test1.img

I don't use Lilo as a boot loader for various reasons, but if you prefer Lilo, look at the lilo.conf or lilo.conf.anaconda file (I think it is in the /etc folder) and change as appropriate. You are not allowed long "labels" (equivalent to "title" in Grub) and must not include spaces in them. See examples in this section. Remember to run lilo before rebooting, or you may end up with an unbootable system.

The moment of truth...

Shut down your computer, say a quick prayer, and re-start.
Good luck!


Troubleshooting...

How to apply kernel patches...

Previous Contents Next