Jump to content

KC-01: How do I compile a kernel?


Recommended Posts

Browse: [About the FAQ forum] [Table of Contents] [FAQs] [Contribute] [KC: Kernel Compilation]

 

KC-01: How do I compile a kernel?

 

The following instructions apply to every kernel sources (tarball, SRPM, ...) after unpackaging them. If you want to learn how to compile directly (rpmbuild) a kernel SRPM, go to KC-01: How do I compile a SRPM kernel?

 

A. Unpacking and configuring your kernel:

  • Download the kernel sources from www.kernel.org, any kernel.org mirror, or any Mandrake mirror.
     
     
  • Unpack the sources in /usr/src/; depending on how the sources are packaged do:
    • *.tgz or *.tar.gz:
      /usr/src/# tar xvfz linux-VERSION.tar.gz
      
      /usr/src/# mv linux linux-VERSION && ln -s linux-VERSION linux


       

    • *.bz2:
      /usr/src/# tar xvfj linux-VERSION.tar.gz
      
      /usr/src/# mv linux linux-VERSION && ln -s linux-VERSION linux


       

    • *.src.rpm:
      ~# rpm -ivh kernel-VERSION.src.rpm


    Cd into the linux directory.

     

     

    Clean all the rubbish only if you are trying to to compile high patched sources.

    make mrproper

    Notice that doing "make mrproper" you'll delete the .config file which stores the default configuration for the particular sources you are compiling, and that you'll have to start from scratch in the following step (kernel configuration). So it will be a good idea to make a backup copy of that file and restore it after the "make mrproper".

     

     

    Edit if you wish the Makefile (<TODO>)

     

     

    Now you'll need to configure the kernel; there are four ways to do this:

    • make xconfig - Is the most intuitive as is X based.
       
    • make menuconfig - Text menus
       
    • make config - Command line. One question after another.
       
    • make oldconfig
      So run your prefered configurator and select the options you need (ie your processor type):
      make XXXconfig


    B. Kernel and Modules Compilation

At this point you have your kernel compiled and stored as arch/i386/boot/bzImage.

 

Notice that if you have already done the "make mrproper" step, you can probably and safely avoid the "make clear" rule (also this step probably can be avoided if you compile the vanilla kernel for the first time).

  • If you are compiling a modular kernel (the usual), then there is one step ahead: the modules compilation (At this stage is mandatory that you become root).
    make modules modules_install

    Note: you can do a faster module compilation by adding the -jN flag to make (where N is an integer: ie -j5 means "compile 5 things at once")

C. Installing the new Kernel

cp /usr/src/linux/arch/i386/boot/bzImage /boot/vmlinuz-VERSION
cp /usr/src/linux/System.map /boot/System.map-VERSION
cp /usr/src/linux/.config /boot/config-VERSION

It is always useful to store a copy of the kernel configuration.
 
 
In some cases you'll need to create an initrd image in order to be able to load the modules the system needs on boot before the root file system can be mounted:
mkinitrd /boot/initrd-KERNEL-VERSION.img KERNEL-VERSION


 
 

Edit your bootloader and append a new entry for the new kernel (do not replace your old kernel entries until you have tested enough the new kernel). I'll show how a lilo.conf entry should be:
image=/boot/vmlinuz-VERSION

label=new_testing

root=/dev/hda2 # or where ever is your root partition 

initrd=/boot/initrd-VERSION.img # in case you need it

append="devfs=mount hdc=ide-scsi" # or which ever flags you need

read-only


 
 

RUN LILO (don't forget):
/sbin/lilo


And that's all!

Further refereneces:

http://www.tldp.org/HOWTO/Kernel-HOWTO.html[/size]

Edited by LiquidZoo
Link to comment
Share on other sites

 Share

×
×
  • Create New...