:: [linux] Compiling the redhat kernel. (Updated Version) ::
HOME


[Date Prev][Date Next][Date Index]

[linux] Compiling the redhat kernel. (Updated Version)


Here are the steps to compile a kernel on Rh 9.0.
Most of this information has been taken from RedHatSite and a HOWTO on TLDP site. I have put my own comments below,
which will help newbies to compile linux kernels without fear.
 
1. The Redhat 9.0 system comes with a 2.4.20 kernel and the kernel source is installed by default.
You can find out which kernel you are running using the command
#>uname -r
 
2. To check if the kernel source (and source version)is installed on your system or not  type
#>rpm -qi kernel-source.
The above command should give u the following output.
 
Name        : kernel-source                Relocations: (not relocateable)
Version     : 2.4.20                            Vendor: Red Hat, Inc.
Release     : 9                             Build Date: Wed Apr  2 12:42:58 2003
Install Date: Tue Apr 29 12:17:53 2003      Build Host: porky.devel.redhat.com
Group       : Development/System            Source RPM: kernel-2.4.20-9.src.rpm
Size        : 169410724                        License: GPL
Signature   : DSA/SHA1, Mon Apr  7 10:11:18 2003, Key ID 219180cddb42a60e
Packager    : Red Hat, Inc. <
http://bugzilla.redhat.com/bugzilla>
Summary     : The source code for the Linux kernel.
Description :
The kernel-source package contains the source code files for the Linux
kernel. These source files are needed to build custom/third party device
drivers. The source files can also be used to build a custom kernel that is
better tuned to your particular hardware, if you are so inclined (and you
know what you're doing).
 
 
3. In RedHat the kernel source is installed in /usr/src/linux-kernelversion. In our case it is
/usr/src/linux-2.4.20-9. However a link /usr/src/linux-2.4 is also created in the same directory that
points to the current kernel source.
 
NOTE: If you do not want to use the kernel source provided by redhat, jut download a fresh copy from here.
Then untar/unzip the source in /usr/src directory. Most such sources untar to /usr/src/linux-kernelversion.
I had to do this to patch a fresh kernel for running my Creative Webcam (Model # PD1001.). For this, I downloaded
the diff file from here. I then applied this patch to the freshly untarred kernel with the command:
/usr/src #>patch -p0 < epcam-0.6.diff 
and everything got patched.  
 
 
4. The current running kernel and the kernel source are two different things.. So don't worry that your system will
crash down if you do something wrong. Just go ahead and do the following and u should be pretty safe.
 
5. It is important that u make a boot diskette. This can be done using the command.
#>/sbin/mkbootdisk `uname -r`
 
6. Now go the kernel directory and do make mrproper as below: BUT NOTE: make mrproper will remove any previous configurations u might have done. All such configurations are placed in the /usr/src/linux2.4/.config file. If there is no such file (and most probably there wont be), u don't have to worry, but if you would like to continue with previous configuration just save the .config to .config.save and later copy it.
REDhat also provides some example configs in /usr/src/linux2.4/configs/. You can check what configuration is used
for your current kernel by checking /boot/.. My /boot directory shows config-2.4.20-9. So i guess i can copy this file to
my /usr/src/linux2.4/.config and i will have the same configuration as my current running kernel.
here are the commands.
 
 
#>cd /usr/src/linux-2.4
/usr/src/linux-2.4 #>make clean
/usr/src/linux-2.4 #>make mrproper
 
/usr/src/linux-2.4 #>cp configs/kernel-2.4.20-i586.config .config
OR
/usr/src/linux-2.4 #>cp /boot/config-2.4.20-9 .config
OR
/usr/src/linux-2.4 #>cp config.save .config
OR
DON"T DO ANYTHING IF YOU WANT TO HAVE A FRESH CONFIGURATION
 
7. Now to start the configuration use
 
/usr/src/linux-2.4 #> make xconfig (If you are in X environment)
OR
/usr/src/linux-2.4 #> make menuconfig (if you are on console)
 
You can now select the kernel configuration u want. You should already know what Modules are and make maximum use of it.
 
 
8.  Now use Make dep
/usr/src/linux-2.4 #> make dep
 
9. Now comes the interesting part. You should give a customized name to your kernel. Just edit the makefile and change
the EXTRAVERSION parameter. I have shown my Makefile (just the top lines) below:
/usr/src/linux-2.4 #> cat Makefile | more
 
VERSION = 2
PATCHLEVEL = 4
SUBLEVEL = 20
EXTRAVERSION = -9
custom
 
by defualt the Redhat people name the new kernel as 2.4.20-9custom. I like to call it something else. So i replace the
"custom" by my initials "sk1" as show below
 
VERSION = 2
PATCHLEVEL = 4
SUBLEVEL = 20
EXTRAVERSION = -9
sk1
 
 
10. Now make the bzimage. This will compile the kernel and place it in /usr/src/linux-2.4.20/arch/i386/boot/bzImage
/usr/src/linux-2.4 #> make bzImage
 
11. Build all the modules using (This is taking a hell lot of time on my machine).
/usr/src/linux-2.4 #> make modules
 
12. install the modules with make modules_install. Note that all the modules will be installed in
/lib/modules/2.4.20-9sk1. Just check this directory to see that this is done.
/usr/src/linux-2.4 #> make modules_install
/usr/src/linux-2.4 #> ls /lib/modules/2.4.20-9sk1
 
 
13. Use make install to copy the new kernel and its associated files to its proper place. Some people might tell you
that "Such is not recommended". But I think it does not matter. "make install" will copy
"usr/src/linux-2.4/arch/i386/boot/bzImage" which is the kernel to /boot/vmlinuz-2.4.20-9sk1.
It also changes the existing "vmlinuz" link to point to /boot/vmlinuz-2.4.20-9sk1.
it also creates "initrd-2.4.20-9sk1.img" which is usefull is you have SCSI drives. check if this is there.. if this
file is not there, just create it manually using the command
 
/usr/src/linux-2.4 #> make install
 
CHECK THE /boot directory to see if there is an initrd-2.4.20-9sk1.img file. If it is not there use
#>/sbin/mkinitrd /boot/initrd-2.4.20-9sk1.img 2.4.20-9sk1
it also chnages the grub boot loader.. An example grub loader, before modification is shown below
*******************************************************************************
# 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
default=0
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title Red Hat Linux (2.4.20-9)
        root (hd0,0)
        kernel /vmlinuz-2.4.20-9 ro root=LABEL=/ hdc=ide-scsi
        initrd /initrd-2.4.20-9.img
title Red Hat Linux (2.4.20-8)
        root (hd0,0)
        kernel /vmlinuz-2.4.20-8 ro root=LABEL=/ hdc=ide-scsi
        initrd /initrd-2.4.20-8.img
*******************************************************************************
and here is the same grub.conf after modification
*******************************************************************************
# 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
default=1 <==== first entry is counted as "0", second is "1" etc.
timeout=10 <==== This sets the timeout for the user to select the kernel version at boottime
splashimage=(hd0,0)/grub/splash.xpm.gz <=== This looks like the grub splashscreen
title Red Hat Linux (2.4.20-9sk1) <=== This is our new kernel

        root (hd0,0)
        kernel /vmlinuz-2.4.20-9sk1 ro root=LABEL=/ hdc=ide-scsi
        initrd /initrd-2.4.20-9sk1.img

title Red Hat Linux (2.4.20-9)
        root (hd0,0)
        kernel /vmlinuz-2.4.20-9 ro root=LABEL=/ hdc=ide-scsi
        initrd /initrd-2.4.20-9.img
title Red Hat Linux (2.4.20-8)
        root (hd0,0)
        kernel /vmlinuz-2.4.20-8 ro root=LABEL=/ hdc=ide-scsi
        initrd /initrd-2.4.20-8.img
*******************************************************************************
14. Now reboot the system and see if your kernel is there or not.
15. Mine worked very well. Even if you select the new kernel and it does not work,
just let it remain in the system (assuming you have enough space). Else you
might just have to modify the /boot directory a bit. I will wrote about this
when i face it.
Now when you need to make a new kernel, just change the EXTRAVERSION and follow all the steps.
16. Once you get used to compiling, you can type the following commands all in one line
/usr/src/linux-2.4 #> make bzImage; make modules; make modules_install; make install
 
Then u can go home and sleep and come back later to reboot into a new kernel.
 
 
Let me know if you find any step wrong.
Regards
Shashank
http://mia.ece.uic.edu/~papers