Script for easy compiling the kernel

Steffen Evers (tron@cs.tu-berlin.de)
Fri, 05 Feb 1999 03:09:35 +0000


This is a multi-part message in MIME format.
--------------67EA5E0BDA69170B6F7FF33F
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hello everyone!
I've written a script called mkkrl that does all this steps like
make dep, make clean, make zImage, ... for compiling and installing a
new kernel.

That should be especially useful for someone who just wants to get an
executable of a new kernel and doesn't have to do any debugging.

For details have a look at the script and grep it for '###'.

I hope some people can make use of it, test it, improve it, ...
and send me some comments, bugs, ...

Happy compiling !!!

Steffen Evers
--------------67EA5E0BDA69170B6F7FF33F
Content-Type: text/plain; charset=us-ascii; name="mkkrl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="mkkrl"

#!/bin/sh

# mkkrl - script for compiling a new kernel
#
# Copyright (C) 1999 Steffen Evers (tron@cs.tu-berlin.de)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# 05.02.1999 Version 1.00

######## set variables
MYNAME=`basename $0`
LOGDIR=/var/tmp/$MYNAME
BACKUPDIR=$LOGDIR
KERNELDIR=/usr/src/linux
KERNELIMAGE=zImage
IMAGEDIR=/usr/src/linux/arch/i386/boot
REMOVEMODULES=yes
INSTALL=yes

######## functions
usage() {
echo "Usage: $MYNAME [-s SOURCE][-i IMAGE] [-l LOG][-u][-k BACKUP][-b][-m][-n]"
echo " $MYNAME -h"
}

help() {
echo
echo "$MYNAME Version 1.00"
usage
echo " -s : set kernel source directory to SOURCE"
echo " -i : set image directory to IMAGE"
echo " -l : set directory for log files to LOG"
echo " -u : set directory for backups to LOG"
echo " -k : set directory for backups to BACKUP"
echo " -b : set image type to bzImage (default:zImage)"
echo " -m : remove old modules after backup from /lib/modules"
echo " -n : don't install kernel image and modules, only compile"
echo " -h : print this message"
echo
}

######## scan parameters
while getopts s:i:l:k:bmnuh OPTION
do
case "$OPTION" in
s) KERNELDIR="$OPTARG" ;;
i) IMAGEDIR="$OPTARG" ;;
l) LOGDIR="$OPTARG" ;;
k) BACKUPDIR="$OPTARG" ;;
b) KERNELIMAGE=bzImage ;;
u) BACKUPDIR= ;;
m) REMOVEMODULES=yes ;;
n) INSTALL=no ;;
h) help; exit 0 ;;
*) usage; exit 1 ;;
esac
done

if [ -z $BACKUPDIR ]
then
BACKUPDIR=$LOGDIR
fi

######## introduce what will be done
echo
echo $MYNAME: This will compile and install a linux kernel and its modules
echo

######## get kernel version from Makefile in the source directory
if [ ! -r $KERNELDIR/Makefile ]
then
echo $MYNAME: $KERNELDIR/Makefile doesn\'t exist or is not readable
echo $MYNAME: Check the kernel source path
echo $MYNAME: Aborting
exit 1
fi

for i in VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION
do
declare $i=`cat $KERNELDIR/Makefile | sed -n "1,20s/\b$i *= *\([[:alnum:]]\)/\1/1p"`
done

if [ -z $VERSION -o -z $PATCHLEVEL -o -z $SUBLEVEL ]
then
echo $MYNAME: Couldn\'t determine kernel version from $KERNELDIR/Makefile
echo $MYNAME: Aborting
exit 1
fi

KERNELVERSION=$VERSION.$PATCHLEVEL.$SUBLEVEL$EXTRAVERSION

######## give all parameters that will be used
echo ' Essential output is written to log files in :' $LOGDIR
echo ' Files that will be replaced are backed up in :' $BACKUPDIR
echo ' The kernel source is considered to be in :' $KERNELDIR
echo ' The kernel version in this directory is :' $KERNELVERSION
echo ' The image type will be :' $KERNELIMAGE
echo ' Install kernel image and modules :' $INSTALL
echo ' Remove old modules after backing them up :' $REMOVEMODULES
echo ' After compilation the image will be taken from :' $IMAGEDIR
echo

######## prepare the directories that will be used
if [ ! -e $KERNELDIR ]
then
echo $MYNAME: $KERNELDIR does not exist
echo $MYNAME: Aborting
exit 1
fi

if [ ! -d $KERNELDIR ]
then
echo $MYNAME: $KERNELDIR is not a directory
echo $MYNAME: Aborting
exit 1
fi

if [ $INSTALL = yes ]
then
if [ ! -e $IMAGEDIR ]
then
echo $MYNAME: $IMAGEDIR does not exist
echo $MYNAME: Aborting
exit 1
fi

if [ ! -d $IMAGEDIR ]
then
echo $MYNAME: $IMAGEDIR is not a directory
echo $MYNAME: Aborting
exit 1
fi
fi

if [ $LOGDIR = $BACKUPDIR ]
then
echo $MYNAME: 'Preparing directory for log-files and backups'
else
echo $MYNAME: Preparing directory for backups
if [ -e $BACKUPDIR ]
then
if [ ! -d $BACKUPDIR ]
then
echo $MYNAME: $BACKUPDIR is not a directory
echo $MYNAME: Aborting
exit 1
fi
if [ ! -w $BACKUPDIR ]
then
echo $MYNAME: $BACKUPDIR is not writeable
fi
echo $MYNAME: $BACKUPDIR 'exists, checking if it is empty'
if [ "`ls $BACKUPDIR`" ]
then
echo $MYNAME: $BACKUPDIR is not empty
echo $MYNAME: Aborting
exit 1
fi
else
echo $MYNAME: Backup directory doesn\'t exist, creating $BACKUPDIR
if ! mkdir $BACKUPDIR
then
echo $MYNAME: Couldn\'t create directory $BACKUPDIR
echo $MYNAME: Aborting
exit 1
fi
fi
echo $MYNAME: Preparing directory for log files
fi

if [ -e $LOGDIR ]
then
if [ ! -d $LOGDIR ]
then
echo $MYNAME: $LOGDIR is not a directory
echo $MYNAME: Aborting
exit 1
fi
if [ ! -w $LOGDIR ]
then
echo $MYNAME: $LOGDIR is not writeable
fi
echo $MYNAME: $LOGDIR 'exists, checking if it is empty'
if [ "`ls $LOGDIR`" ]
then
echo $MYNAME: $LOGDIR is not empty
echo $MYNAME: Aborting
exit 1
fi
else
echo $MYNAME: $LOGDIR doesn\'t exist, creating it
if ! mkdir $LOGDIR
then
echo $MYNAME: Couldn\'t create directory $LOGDIR
echo $MYNAME: Aborting
exit 1
fi
fi

######## move to kernel directory
echo $MYNAME: Changing working directory to kernel source root
if ! cd $KERNELDIR
then
echo $MYNAME: Couldn\'t change to $KERNELDIR
echo $MYNAME: Aborting
exit 1
fi

######## make dep
echo $MYNAME: 'Updating dependencies for compiling the kernel (dep.log)'
if make dep > $LOGDIR/dep.log 2>&1
then
echo $MYNAME: Done
else
echo $MYNAME: make dep exit with status $?
echo $MYNAME: See $LOGDIR/dep.log for details
echo $MYNAME: Aborting
exit 1
fi

######## make clean
echo $MYNAME: 'Removing old object files (clean.log)'
if make clean > $LOGDIR/clean.log 2>&1
then
echo $MYNAME: Done
else
echo $MYNAME: make clean exit with status $?
echo $MYNAME: See $LOGDIR/clean.log for details
echo $MYNAME: Aborting
exit 1
fi

######## make image
echo $MYNAME: "Compiling kernel ($KERNELIMAGE.log)"
if make $KERNELIMAGE > $LOGDIR/$KERNELIMAGE.log 2>&1
then
echo $MYNAME: Done
else
echo $MYNAME: make $KERNELIMAGE exit with status $?
echo $MYNAME: See $LOGDIR/$KERNELIMAGE.log for details
if [ $KERNELIMAGE = zImage ]
then
echo $MYNAME: If you get the message \'kernel to big\' use \'bzImage\' '(option -b)'
fi
echo $MYNAME: Aborting
exit 1
fi

######## make modules
echo $MYNAME: 'Compiling modules (modules.log)'
if make modules > $LOGDIR/modules.log 2>&1
then
echo $MYNAME: Done
else
echo $MYNAME: make modules exit with status $?
echo $MYNAME: See $LOGDIR/modules.log for details
echo $MYNAME: Aborting
exit 1
fi

######## abort if install not set
if [ $INSTALL != yes ]
then
echo $MYNAME: Compiling finished. Installation not wished.
echo " To install the kernel:"
echo " 1. make modules_install"
echo " 2. Copy kernel-image to boot directory"
echo " 3. Set the link /vmlinuz to this kernel"
echo " 4. Run lilo or what ever to activate the kernel"
echo $MYNAME: Aborting
exit 0
fi

######## backup old modules
if [ -e /lib/modules/$KERNELVERSION ]
then
echo $MYNAME: Copying old kernel modules to backup directory
if ! cp -a /lib/modules/$KERNELVERSION $BACKUPDIR/modules-$KERNELVERSION
then
echo $MYNAME: Couldn\'t copy /lib/modules/$KERNELVERSION to $BACKUPDIR/modules-$KERNELVERSION
echo $MYNAME: Aborting
exit 1
fi
if [ $REMOVEMODULES = yes ]
then
echo $MYNAME: Removing old kernel modules from /lib/modules
rm -f -r /lib/modules/$KERNELVERSION
fi
fi

######## install new modules
echo $MYNAME: 'Installing new modules (modules_install.log)'
if make modules_install > $LOGDIR/modules_install.log 2>&1
then
echo $MYNAME: Done
else
echo $MYNAME: make modules_install exit with status $?
echo $MYNAME: See $LOGDIR/modules_install.log for details
if [ -e /lib/modules/$KERNELVERSION ]
then
echo $MYNAME: Copying already installed modules in backup directory
if ! cp -a /lib/modules/$KERNELVERSION $BACKUPDIR/modules-$KERNELVERSION.new
then
echo $MYNAME: Couldn\'t /lib/modules/$KERNELVERSION to $BACKUPDIR/modules-$KERNELVERSION.new
fi
echo $MYNAME: Removing new modules from /lib/modules
rm -f -r /lib/modules/$KERNELVERSION
fi
fi
if [ -e $BACKUPDIR/modules-$KERNELVERSION ]
then
echo $MYNAME: Putting old kernel modules back in place
if ! cp -a $BACKUPDIR/modules-$KERNELVERSION /lib/modules/$KERNELVERSION
then
echo $MYNAME: Couldn\'t copy $BACKUPDIR/modules-$KERNELVERSION to /lib/modules/$KERNELVERSION
echo $MYNAME: IMPORTANT: Make sure that the modules of the current kernel are
echo "$MYNAME: installed in /lib/modules/$KERNELVERSION !!!"
fi
fi
echo $MYNAME: Aborting
exit 1
fi

######## backup old kernel image
if [ -e /boot/vmlinuz-$KERNELVERSION ]
then
echo $MYNAME: Backuping old kernel image in backup directory
if ! mv /boot/vmlinuz-$KERNELVERSION $BACKUPDIR/vmlinuz-$KERNELVERSION
then
echo $MYNAME: Couldn\'t move /boot/vmlinuz-$KERNELVERSION to $BACKUPDIR/vmlinuz-$KERNELVERSION
echo $MYNAME: Aborting
exit 1
fi
fi

######## install new kernel image
echo $MYNAME: Copying new kernel image to boot directory
if ! cp -a $IMAGEDIR/$KERNELIMAGE /boot/vmlinuz-$KERNELVERSION
then
echo $MYNAME: Couldn\'t copy $IMAGEDIR/$KERNELIMAGE to /boot/vmlinuz-$KERNELVERSION
echo $MYNAME: Aborting
exit 1
fi

######## relinking /vmlinuz
if [ -e /vmlinuz ]
then
echo $MYNAME: Copying /vmlinuz in backup directory
if ! cp -a /vmlinuz $BACKUPDIR
then
echo $MYNAME: Couldn\'t copy /vmlinuz to $BACKUPDIR
echo $MYNAME: Aborting
fi
echo $MYNAME: Removing /vmlinuz
rm -f /vmlinuz
fi
echo $MYNAME: Creating link /vmlinuz pointing to compiled kernel
if ! ln -s boot/vmlinuz-$KERNELVERSION /vmlinuz
then
echo $MYNAME: Couldn\'t link /vmlinuz to boot/vmlinuz-$KERNELVERSION
echo $MYNAME: Aborting
exit 1
fi

######## print advice
echo $MYNAME: Remember running lilo if you use it

--------------67EA5E0BDA69170B6F7FF33F--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/