Compiling and Installing a Custom Kernel - Administration
Today, continue on your path to RHCE certification. Learn about creating a new kernel the easy way, kernel sources, recompiling a kernel, and the cron and at systems. Take notes, because there's a test at the end. This comes from chapter five of Red Hat Certified Engineer Linux Study Guide (Exam RH302), fourth edition, by Michael Jang. (McGraw-Hill/Osborne, 2004, ISBN: 0-07-225365-7).
After setting up all the options you want from one of the Kernel configuration programs, make sure to save your changes. The changes are saved in the appropriate .config file. Next, you can compile your kernel. Compiling a new kernel can be a long and tedious process. The following is a list of things you should do to successfully compile your kernelóinorder:
If you havenít already done so, create a custom boot floppy disk with the following command. Test the floppy thatís created.
# mkbootdisk `uname -r`
Run the cd /usr/src/linux-2.4 command to reach the proper directory. Youíll need to run your commands to modify and compile the kernel in this directory. This assumes that youíve installed the appropriate kernel-source RPM. In RHEL 3, this directory is linked to the directory with the source code, /usr/src/linux-2.4.21-4.EL.
Open /usr/src/linux-2.4/Makefile in a text editor. In RHEL 3, the EXTRAVERSION variable is already set to identify a custom kernel. If necessary, change the value of this variable to uniquely identify your kernel. Record the value of this variable.
Save your current kernel configuration file. Itís stored in the /boot directory. For RHEL 3, itís the /boot/config-2.4.21-4.EL file. Have it ready with a rescue floppy in case disaster strikes. Copy it to the /usr/src/linux-2.4/.config file.
Alternatively, you can start from a standard configuration file in the /usr /src/linux-2.4/configs/ directory. You can also run the make oldconfig command.
Run the make mrproper command to ensure your source files are in a consistent and clean state.
Now you can customize your kernel with one of the following three utilities: the make config command runs the text-based configuration script; the make menuconfig command runs a low-level graphical configuration script; and the make xconfig command starts the X Window System configuration tool.
Make any changes as required by your hardware and/or the RHCE exam. Before you exit from the kernel configuration utility, make sure to save your changes!
The make dep command will set up all your dependencies correctly. This takes the settings from /usr/src/linux-2.4/.config and pushes them down into the correct source code subdirectory. This will take some time, as there are nearly 1,500 possible kernel settings on a RHEL 3 system!
ON THE JOB! The make dep process took about 20 minutes on my computer with a 1.2GHz CPU.
Run the make clean command to prepare the source code directories to build your new kernel.
The make bzImage command compiles the kernel and creates a gzip compressed kernel image file.
ON THE JOB!The make bzImage process took about 20 minutes on my computer with a 1.2GHz CPU.
Now you need to build your modules (you did include kernel module support, didnít you?). Use make modules to build all your modules.
ON THE JOB! The make modules process took about 50 minutes on my computer with a 1.2GHz CPU.
Now you need to install your newly made modules, which will install all your loadable modules into a new subdirectory of the /lib/modules/kernelversion directory. The kernelversionshould correspond to the EXTRAVERSION variable in your Makefile. Use make modules_install to install your modules.
With our kernel now built, we need to move it to /boot before we can boot from it. Run the make install command to copy the new kernel and create a new Initial RAM Disk file (initrd) in the /boot directory. It also updates the default GRUB boot loader.
ON THE JOB!The make install command copies your new kernel from the /usr/src/linux-2.4 /arch/i386/boot to the /boot directory. It also uses the mkinitrd command to create a new Initial RAM disk in the /boot directory.
Verify the changes to the /boot directory.
Building a kernel is an involved process, but it follows a standard pattern. It is very important that you become familiar with kernel construction procedures and troubleshooting. Refer to the following Scenario & Solution for some common problems encountered and their recommended solutions.
Scenario & Solution
You looked under /usr/src/ but did not see the Linux kernel source code. What did you do wrong?
You did not install the kernel source code. Install the kernel source and related RPMs or use the Red Hat Package Management utility to install the Kernel Development package group.
You configured the kernel as a monolithic kernel but when you run make bzImage, it fails, saying the kernel is too big. What should you do?
You must reconfigure your kernel to use modules. There are limits on the size of a compressed kernel, so you should always build a modular kernel.
You can't find your new kernel.
Did you create an appropriate EXTRAVERSION cariable in your Makefile? Did you use this cariable throughout this process? If not, then you may not be able to correctly locate the kernel or its modules.
This is part one from the fifth chapter of Red Hat Certified Engineer Linux Study Guide (Exam RH302), fourth edition, by Michael Jang. (McGraw-Hill/Osborne, 2004, ISBN: 0-07-225365-7). Check it out at your favorite bookstore today. Buy this book now.