royong
08-06-2006, 18:38
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 CentOS 3.x and CentOS 4.x - but as usual you are expected to practice due diligence.
Log into the server and as ROOT perform the following :-
The following ensures that the required packages are installed on the system
# yum install rpm-build ncurses-devel gcc-c++
Next, we obtain the source kernel from kernel.org
# cd /root
# wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.16.20.tar.gz
Untar the kernel source into the /usr/src diretory using the following
# tar xzvf linux-2.6.16.20.tar.gz -C /usr/src/
If required, you can 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=[existingversionnumber] - i.e. No change to the file.
# vi /usr/src/linux-2.6.16.20/Makefile
To ensure that your files are in a consistent and clean state, we run the following
# cd /usr/src/linux-2.6.16.20
# make clean
# make mrproper
Copy the config file from your existing kernel to the new kernel source
# cp /boot/config-2.6.9-34.ELsmp /usr/src/linux-2.6.16.20/config
# make oldconfig
Once the above 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.
Choice 1 :: This is a the standard configuration tool - can be run via SSH
# make config
Choice 2 :: This is a menu based configuration tool that uses NCURSES # make menuconfig
Choice 3 :: This is a GUI based configuration tool that requires X-Windows # make xconfig
Carry out any customization as you may require. Save and quit the configuration tool.
PS - Choice 2 is my personal preference
Set up all your dependencies
# make dep
Now we need to create 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. This invokes the command, sends it into the background and then we take an active view into the nphup.out file.
# nohup make bzImage &
# tail -f nohup.out
Time 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. This makes the modules in the background and sends output to 3 different files, nohup.out, modules.err and modules.out.
# nohup make modules 1> modules.out 2> modules.err &
Run the following to check if the make process is still running
# ps auwx | grep make
Once completed, take a look at the 3 output files and see if there are any errors. Remember :: Warnings are ok - Errors are NOT!
# less nohup.out
# less modules.err
# less modules.out
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 that you create.
# make modules_install
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.6.16.20/config /boot/config-2.6.16.20
Copying of the bzImage file to /boot
# cp /usr/src/linux-2.6.16.20/arch/i386/boot/bzImage /boot/vmlinuz-2.6.16.20
Copying of the new kernel's symbol table to the /boot partition. Plough on, we are almost done.
# cp /usr/src/linux-2.6.16.20/System.map /boot/System.map-2.6.16.20
Installing a initial RAM disk on the /boot file system. Remembering that the value of your EXTRAVERSION has been pre-defined in the original settings of the MakeFile. As such, if your variable is different, please adjust accordingly.
# mkinitrd /boot/initrd-2.6.16.20.img 2.6.16.20
Finally, making changes to the GRUB boot loader configuration file. First up, 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 :
# vi /boot/grub/grub.conf
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS-4 i386 (2.6.9-34.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.6.9-34.ELsmp ro root=LABEL=/
initrd /initrd-2.6.9-34.ELsmp.img
title CentOS-4 i386-up (2.6.9-34.EL)
root (hd0,0)
kernel /vmlinuz-2.6.9-34.EL ro root=LABEL=/
initrd /initrd-2.6.9-34.EL.img
Now we will need to create another entry that will be pointing to your custom kernel. So, the revised /boot/grub/grub.conf should look something like the following :
default=1
fallback=2
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS-4 i386 (2.6.16.20)
root (hd0,0)
kernel /vmlinuz-2.6.16.20 ro root=LABEL=/
initrd /initrd-2.6.16.20.img
title CentOS-4 i386 (2.6.9-34.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.6.9-34.ELsmp ro root=LABEL=/
initrd /initrd-2.6.9-34.ELsmp.img
title CentOS-4 i386-up (2.6.9-34.EL)
root (hd0,0)
kernel /vmlinuz-2.6.9-34.EL ro root=LABEL=/
initrd /initrd-2.6.9-34.EL.img
Notice that I added default=1 and fallback=2 - this is just in case, if your system unable to boot up to the new kernel, then the system will automatically reboot back to its default/old kernel. So in order for us to boot up into our new kernel for testing, we will need to tell GRUB to bypass the default setting for 1 time. We do the following
# grub shell
grub> savedefault --default=0 --once
grub> quit
# reboot
Remember, once your system reboots, it will be trying to boot into the new kernel. Please remember to use commands like lsmod or dmesg or cat /var/log/boot.log to check for any errors. Additionally, leave the system to run on this new kernel for some time before resetting GRUB to point to this new kernel as the default kernel. Set the new kernel as the default kernel, only when you are comfortable with the new kernel and all have been tested to be working fine.
*Note : To change the default boot selection in the GRUB menu, we will need to change the value of the default variable in the /boot/grub/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.
Hope this helps ...
Please feel free to contact me should there be any queries. Thank you.
Log into the server and as ROOT perform the following :-
The following ensures that the required packages are installed on the system
# yum install rpm-build ncurses-devel gcc-c++
Next, we obtain the source kernel from kernel.org
# cd /root
# wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.16.20.tar.gz
Untar the kernel source into the /usr/src diretory using the following
# tar xzvf linux-2.6.16.20.tar.gz -C /usr/src/
If required, you can 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=[existingversionnumber] - i.e. No change to the file.
# vi /usr/src/linux-2.6.16.20/Makefile
To ensure that your files are in a consistent and clean state, we run the following
# cd /usr/src/linux-2.6.16.20
# make clean
# make mrproper
Copy the config file from your existing kernel to the new kernel source
# cp /boot/config-2.6.9-34.ELsmp /usr/src/linux-2.6.16.20/config
# make oldconfig
Once the above 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.
Choice 1 :: This is a the standard configuration tool - can be run via SSH
# make config
Choice 2 :: This is a menu based configuration tool that uses NCURSES # make menuconfig
Choice 3 :: This is a GUI based configuration tool that requires X-Windows # make xconfig
Carry out any customization as you may require. Save and quit the configuration tool.
PS - Choice 2 is my personal preference
Set up all your dependencies
# make dep
Now we need to create 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. This invokes the command, sends it into the background and then we take an active view into the nphup.out file.
# nohup make bzImage &
# tail -f nohup.out
Time 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. This makes the modules in the background and sends output to 3 different files, nohup.out, modules.err and modules.out.
# nohup make modules 1> modules.out 2> modules.err &
Run the following to check if the make process is still running
# ps auwx | grep make
Once completed, take a look at the 3 output files and see if there are any errors. Remember :: Warnings are ok - Errors are NOT!
# less nohup.out
# less modules.err
# less modules.out
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 that you create.
# make modules_install
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.6.16.20/config /boot/config-2.6.16.20
Copying of the bzImage file to /boot
# cp /usr/src/linux-2.6.16.20/arch/i386/boot/bzImage /boot/vmlinuz-2.6.16.20
Copying of the new kernel's symbol table to the /boot partition. Plough on, we are almost done.
# cp /usr/src/linux-2.6.16.20/System.map /boot/System.map-2.6.16.20
Installing a initial RAM disk on the /boot file system. Remembering that the value of your EXTRAVERSION has been pre-defined in the original settings of the MakeFile. As such, if your variable is different, please adjust accordingly.
# mkinitrd /boot/initrd-2.6.16.20.img 2.6.16.20
Finally, making changes to the GRUB boot loader configuration file. First up, 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 :
# vi /boot/grub/grub.conf
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS-4 i386 (2.6.9-34.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.6.9-34.ELsmp ro root=LABEL=/
initrd /initrd-2.6.9-34.ELsmp.img
title CentOS-4 i386-up (2.6.9-34.EL)
root (hd0,0)
kernel /vmlinuz-2.6.9-34.EL ro root=LABEL=/
initrd /initrd-2.6.9-34.EL.img
Now we will need to create another entry that will be pointing to your custom kernel. So, the revised /boot/grub/grub.conf should look something like the following :
default=1
fallback=2
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS-4 i386 (2.6.16.20)
root (hd0,0)
kernel /vmlinuz-2.6.16.20 ro root=LABEL=/
initrd /initrd-2.6.16.20.img
title CentOS-4 i386 (2.6.9-34.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.6.9-34.ELsmp ro root=LABEL=/
initrd /initrd-2.6.9-34.ELsmp.img
title CentOS-4 i386-up (2.6.9-34.EL)
root (hd0,0)
kernel /vmlinuz-2.6.9-34.EL ro root=LABEL=/
initrd /initrd-2.6.9-34.EL.img
Notice that I added default=1 and fallback=2 - this is just in case, if your system unable to boot up to the new kernel, then the system will automatically reboot back to its default/old kernel. So in order for us to boot up into our new kernel for testing, we will need to tell GRUB to bypass the default setting for 1 time. We do the following
# grub shell
grub> savedefault --default=0 --once
grub> quit
# reboot
Remember, once your system reboots, it will be trying to boot into the new kernel. Please remember to use commands like lsmod or dmesg or cat /var/log/boot.log to check for any errors. Additionally, leave the system to run on this new kernel for some time before resetting GRUB to point to this new kernel as the default kernel. Set the new kernel as the default kernel, only when you are comfortable with the new kernel and all have been tested to be working fine.
*Note : To change the default boot selection in the GRUB menu, we will need to change the value of the default variable in the /boot/grub/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.
Hope this helps ...
Please feel free to contact me should there be any queries. Thank you.