PDA

View Full Version : HOWTO :: Kernel Recompilation (Manual)


royong
20-04-2006, 00:51
Disclaimer :: This article has been primed to focus on the needs to carry out kernel recompilation on a Linux machine so as to add / remove modules to the standard setup. While I take precaution to avoid any unnecessary errata, the reader is advised to perform his / her own backups. I accept no warranties, expressed or implied, with regards to any malfunction, damage, loss, deletion, removal etc. of any form, nor shall I be liable for any damages. This HOWTO has been tested on machines running Red Hat 7.2 / 7.3 / 8.0 - but as usual you are expected to practice due diligence.

Log into the server and as ROOT perform the following :-

# rpm -qa
Ensure that the following RPMs are installed

(a) kernel-source-2.4.18-14

(b) libacl-devel-2.0.11-2

(c) libattr-devel-2.0.8-3

(d) tcl-8.3.3-74

(e) tk-8.3.3-74

If they aren't, please get them installed before proceeding further.

# vi /usr/src/linux-2.4/MakeFile
Edit the EXTRAVERSION entry. Change the definition for EXTRAVERSION=versionnumber to something that uniquely identifies your custom kernel. Anything goes. Just be sure to remember what you have entered. For our case, we shall use EXTRAVERSION=RHcustom

# make mrproper
This ensures that your files are in a consistent and clean state

# make oldconfig
This uses the standard Red Hat configuration that is provided in the /usr/src/linux-2.4/configs/ directory. Once this command completes, we can then run a configuration utility to configure or custom the kernel to your liking. Use any ONE of the following configuration tools.

# make config (This is a the standard configuration tool - can be run via SSH)

# make menuconfig (This is a menu based configuration tool that uses NCURSES)

# make xconfig (This is a GUI based configuration tool that requires X-Windows)

Carry out any customization as you may require. Save and quit the configuration tool.

# make dep
This will set up all your dependencies correctly. This tales the setting present in /usr/src/linux-2.4/.config and pushes them down into the correct source code subdirectory

# make bzImage
This creates a gzip compressed kernel image file This step is time consuming. So, take a coffee break while this runs. Depending on your machine's hardware configuration and the customization done to your kernel, this could take anywhere from 10 to 20 minutes. Just be patient, the system is recompiling hundred thousand lines of code so give it some time. At the end of this command, you will see this error message :

warning : kernel is too big for standalone boot from floppy
This simply means that you will not be able to set your customized kernel as part of a boot or rescue floppy disk as it exceeds the capacity of the floppy. Nothing to worry about. We are safe to proceed further.

# make modules
This helps to build all the modules that is required for the customized kernel. This step is extremely time consuming. Anything from 30 to 60 minutes is considered standard.

With the completion of make modules we are now ready to move it to the /boot before we can actually use it.

# cp /usr/src/linux-2.4/arch/i386/boot/bzImage /boot/vmlinuz-2.4.19-RHcustom
# make modules_install
This installs all the newly made modules to correspond with the kernel release and EXTRAVERSION setting of your custom kernel. If this name already exists, it will be overwritten. As such, always remember to set a unique EXTRAVERSION value for each custom kernel.

# mkinitrd /boot/initrd-2.4.19-RHcustom.img 2.4.19-RHcustom
This installs a initial RAM disk on the /boot file system. Remembering that the value of RHcustom has been pre-defined in the original settings of the MakeFile. As such, if your variable is different, please adjust accordingly.

# cp /usr/src/linux-2.4/system.map /boot/System.map-2.4.19-RHcustom
This copies the new kernel's symbol table to the /boot partition. Plough on, we are almost done.

# vi /etc/grub.conf
Looking at our GRUB loader configuration file, you should already have an entry that is pointing to your old kernel, which points to the appropriate locations for the kernel and initial RAM disk. Here's an excerpt of what you should possibly see :

Title Red Hat Linux (2.4.19-6)

root (hd0,0)

kernel /vmlinuz-2.4.19-6 ro root=LABEL=/

initrd /initrd-2.4.19-6.img
Now we will need to create another entry that will be pointing to your custom kernel. So, the revised /etc/grub.conf should look something like the following :

Title Red Hat Linux (2.4.19-6)

root (hd0,0)

kernel /vmlinuz-2.4.19-6 ro root=LABEL=/

initrd /initrd-2.4.19-6.img

Title Red Hat Linux (2.4.19-RHcustom)

root (hd0,0)

kernel /vmlinuz-2.4.19-RHcustom ro root=LABEL=/

initrd /initrd-2.4.19-RHcustom.img
That's it. Save the amended /etc/grub.conf file and you are ready to reboot your machine. Upon boot up, you should see another entry in your GRUB loader menu. Selecting on the Red Hat Linux (2.4.19-RHcustom) entry would initialize the system to boot via your custom kernel. Barring any errors, your system should boot up without a hitch and there you have it. Your every own custom kernel for your machine. Enjoy !

*Note : To change the default boot selection in the GRUB menu, we will need to change the value of the default variable in the /etc/grub.conf file. If default=0, the default kernel loaded will be the first entry while a default=1 value will load the second entry.