Compiling and Installing a custom kernel

Updating a kernel is not a difficult task, although you should backup your working kernel just in case. The basic steps are to build the new kernel and modules then update your boot manager configuration (GRUB or lilo). However if you make a mistake you can simply boot from your old kernel.

There are a number of reason why you would want to rebuild a kernel I have created a table displaying time against each task, this was based on a Compaq PIII 650Mhz machine (see below), I only added a couple of non-essential modules, so bear in mind it may take longer depending on the number of modules you are adding.

Step Number
Approx time
10 secs
30 secs
30 secs
10 secs
30 secs
2 mins
4 mins
12 mins
50 mins
30 secs
1 min
  1. Change to the working directory
    #cd /usr/src/linux-2.4

  2. Edit the Makefile and change the EXTRA VER SION definition which will uniquely identify your Kernel

  3. Run the following command to ensure your source files are in a consistent and clean state
    #make mrproper

  4. Save your old configuration file, if one has already been created.
    #cp .config /var/tmp/.config.ddmmyy

  5. If you want to start from the standard configuration, use the following command, if not skip on to next step.
    #make oldconfig

  6. Customise the .config by using your favourite kernel configurator
    #make xconfig

  7. You will need to set up all your dependencies correctly.
    #make dep

  8. Now create the gzip compressed kernel image file
    #make bzImage

  9. Now build your modules
    #make modules

  10. The kernel is built all you need to do is move the kernel into place (/boot).
    #cp /usr/src/linux-2.4/arch/i386/boot/bzImage   /boot/vmlinux-2.4.20PFVcustom

  11. Finally you need to install your newly made modules
    #make modules_install

Post-build Procedures
We now need to build support for an initial RAM disk and to copy the remaining files to the /boot directory. You need only to do this if you are using the GRUB boot manager.

  1. Make a initial RAM disk
    #mkinitrd /boot/initrd-2.4.20-PFVcustom.img 2.4.20-PFVcustom

  2. Copy the kernel’s symbol table to the /boot partition
    #cp /usr/src/linux-2.4/ /boot/

  3. Backup a copy of the .config file onto the /boot partition
    #cp /usr/src/linux-2.4/.config /boot/.config-2.4.20-PFVcustom

Updating boot manager

We can now update the boot manager to include your new kernel as an option. So you will be adding a stanza to either /etc/grub.conf or /etc/lilo.conf. This allows you to choose which kernel you wish to boot from, if your new kernel does not work you can simply boot from your old working kernel.

Updating GRUB you add the following to /etc/grub.conf

  Title Red Hat Linux (2.4.20-PFVcustom)
root (hd0,0)
kernel /vmlinuz-2.4.20-PFVcustom ro root=LABEL=/
initrd /initrd-2.4.20-PFVcustom.img

Since you do not need to load /etc/grub.conf into the MBR, no further action is required.

Updating lilo you add the following to /etc/lilo.conf

root=/dev/hda1            (Note this should point to your /boot partition)

Save the file then run /sbin/lilo –v , you will get the output that confirms the MBR has been overwritten.

When you reboot either enter the default label linux or the new label newlinux

Rescue Diskette

Now that you have created, installed and tested your new kernel it might be wise to create a new boot/rescue diskette.

# /sbin/mkbootdisk 2.4.20-PFVcustom