Next Previous Contents

14. Final Linux Kernel compiling and installation

14.1 Manually compiling the kernel

Time to compile the kernel. You can do it manually via the following commands or use the "built-it" script given below.


        "cd /usr/src/kernel/linux"
        "make clean"
        "make dep"
        "make bzImage"

and allow for the kernel to compile (~3mins on a P-II 233)

- Now, compile and install the necessary system modules:


        "cd /usr/src/kernel/linux"
        "make modules"
        "make modules_install"

- Once the kernel has compiled, do the following command line (replacing "XYZ" with an identifing name like "2035-masq":

Slackware:


                "cp /usr/src/kernel/linux/arch/i386/boot/bzImage /XYZ"

Redhat:


                "cp /usr/src/kernel/linux/arch/i386/boot/bzImage /boot/XYZ"

14.2 Automating kernel compiling via the "build-it" script

If you would like to automate this process in the future, create this script in /usr/src/kernel and run it once you have configured your new kernel.

NOTE: You will want to create the directory /usr/src/kernel/config to store your configured kernel setups. This is a good way to find out what is and isn't enabled in a given kernel.

/usr/src/kernel/build-it

<build-it START>


!/bin/sh
#
# Version: 11/10/01
#
# Part of the copyrighted and trademarked TrinityOS document.
# <url url="http://www.ecst.csuchico.edu/~dranch">
#
# Written and Maintained by David A. Ranch
# dranch at trinnet dot net
#
# Updates:
#
# 07/09/03 - Added checks to stop the process if the kernel doesn't compile
#          - Added the use of path variables
#          - Added additional echo statements for cleaner output
# 11/10/01 - added the use of mrproper to solve rare kernel module issues
# 11/09/01 - made making "dep" serial as doing via parallel had issues
#          - Holy cow.. forgot to parallelize the making of the kernel
# 10/04/01 - Moved the kernel sources and this script to /usr/src/kernel
# 01/17/00 - Changed the date to use %d over %e and remove 
#            any spacesn the date format.
#          - Changed the layout a little and added some beeps at the end
#

# Multi-process option (enable this even for uni-processor machines..
# seriously)
J=-j4

#Location of the kernel sources
SRC=/usr/src/kernel

# --- Script Body

cd $SRC/linux

#Make sure the $SRC/config directory exists.
cp $SRC/linux/.config $SRC/config/kernel.`date +'%b%d'`

# Deal with rare but troublesome kernel module symbol issues
mv .config ..

echo -e "\n\n**********************************************"
echo -e "**                                          **"
echo -e "**       Pre-Phase 1: make mrproper         **"
echo -e "**                                          **"
echo -e "**********************************************\n\n"
make mrproper



echo -e "\n\n**********************************************"
echo -e "**                                          **"
echo -e "**       Pre-Phase 2: make oldconfig        **"
echo -e "**                                          **"
echo -e "**********************************************\n\n"
mv ../.config .
make oldconfig


echo -e "\n\n**********************************************"
echo -e "**                                          **"
echo -e "**       Pre-Phase 3: make clean            **"
echo -e "**                                          **"
echo -e "**********************************************\n\n"
# Clean up from any previous builds
make $J clean


# Start to time the build time
date > $SRC/kernel-compile-time.`date +'%b%d'`

#Do not parallelize the DEP phase as it can fail
echo -e "\n\n**********************************************"
echo -e "**                                          **"
echo -e "**       Phase 1/5: make dep                **"
echo -e "**                                          **"
echo -e "**********************************************\n\n"

make dep



# Parallize everything else
echo -e "\n\n**********************************************"
echo -e "**                                          **"
echo -e "**       Phase 2/5: make bzImage            **"
echo -e "**                                          **"
echo -e "**********************************************\n\n"
make $J bzImage

#Did it really compile properly?
if [ ! -f $SRC/linux/arch/i386/boot/bzImage ]; then
   #Send a few beeps
   echo ""
   sleep 1
   echo ""
   sleep 1
   echo ""

   echo -e "\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
   echo -e "!!                                          !!"
   echo -e "!! ERROR:                                   !!"
   echo -e "!!                                          !!"
   echo -e "!!  Kernel did not properly compile.        !!"
   echo -e "!!  (bzImage file is missing).  ABORTING.   !!"
   echo -e "!!                                          !!"
   echo -e "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n"

   #Aborting without cleanup will save a required ojects, etc.
   exit 1
fi

#The kernel binary is present, move on


echo -e "\n\n**********************************************"
echo -e "**                                          **"
echo -e "**       Phase 3/5: make modules            **"
echo -e "**                                          **"
echo -e "**********************************************\n\n"
make $J modules


echo -e "\n\n**********************************************"
echo -e "**                                          **"
echo -e "**       Phase 4/5: make modules_install    **"
echo -e "**                                          **"
echo -e "**********************************************\n\n"
make $J modules_install


echo -e "\n\n**********************************************"
echo -e "**                                          **"
echo -e "**       Phase 5/5: Move binaries over      **"
echo -e "**                                          **"
echo -e "**********************************************\n\n"

cp $SRC/linux/arch/i386/boot/bzImage /boot/bzImage
cp $SRC/linux/System.map /boot/System.map.new
date >> $SRC/kernel-compile-time.`date +'%b%d'`

echo -e "\n\nCompile Done."
echo -e "\nRename /boot/bzImage to a proper name, edit /etc/lilo.conf,"
echo -e "rename /boot/System.map.new to a proper name, symlink this new"
echo -e "map file to /boot/System.map, and finally and finally re-run "
echo -e "lilo.  Make sure lilo runs cleanly"

#Due to SGML conversions, the ASCII "bell" code might become 
# corrupt.  To fix this, edit this file with say Vim, delete the
# "^G" characters and resplace them with the following in INSERT 
# mode (the control-q tells Vi to add the following character as
# binary and not ascii:
#
#   Control-Q  Control-G
#
echo ^G
sleep 1
echo ^G
sleep 1
echo ^G

<build-it STOP>

Don't forget.. "chmod 700 /usr/src/kernel/build-it"

To run the script, run it as "./built-it"


Next Previous Contents