#!/bin/bash # # Blueprint to build a linux kernel. # # The kernel is the heart of the operating system and provides access # to system resources like CPU, memory and disks. # # Source is from ftp://ftp.kernel.org/pub/linux/kernel/2.6/ # # # This script is public domain software and may be freely copied. # # This script 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. # # # Define the package name, source directory, build directory and # staging directory paths. Prefixes to directories may be overridden # by setting shell variables SRC, BUILD and STAGING. For example, # doing "export SRC=/root/foo" before calling this script will override # the default /usr/src and set SRC_DIR to /root/foo/$PKG_NAME instead. # PKG_NAME=$(basename $0) SRC_DIR=${SRC:-/usr/src}/$PKG_NAME BUILD_DIR=${BUILD:-/var/tmp/build}/$PKG_NAME STAGING_DIR=${STAGING:-/var/tmp/staging}/$PKG_NAME # Change the staging directory name to include the word 'headers' since # that is what will end up going there. The actual kernel and modules # are packaged separately by the Linux kernel's Makefile. STAGING_DIR="$STAGING_DIR-headers" # # Check that the source directory really exits and bail out if not. if ! [ -d $SRC_DIR ]; then echo "$PKG_NAME: Cannot find source code directory $SRC_DIR." exit 1 fi # # Do not overwrite existing build directory. #if [ -d $BUILD_DIR ]; then # echo "$PKG_NAME: Build directory $BUILD_DIR already exists." # exit 2 #else # mkdir -p $BUILD_DIR #fi # # Do not overwrite existing staging directory. if [ -d $STAGING_DIR ]; then echo "$PKG_NAME: Staging directory $STAGING_DIR already exists." exit 4 else mkdir -p $STAGING_DIR fi # # Configure the kernel. cd /usr/src/linux if [ -f /proc/config.gz ]; then echo "A config file for the current kernel was found (/proc/config.gz)." echo "Would you like to use this as a starting point for configuration [y/N]?" read REPLY if [ "$REPLY" = "Y" ] || [ "$REPLY" = "y" ]; then cp .config .config.old zcat /proc/config.gz > .config fi fi make menuconfig # Check return status and bail out if it's non-zero. if [ $? -gt 0 ]; then echo "Kernel configuration failed!" exit 8 fi # Build the package. make # Check return code and bail if it looks bad. if [ $? -gt 0 ]; then echo "Kernel build failed!" exit 16 fi # Create a tar-gzip package for the kernel and modules using the make # target 'targz-pkg'. Also install kernel headers into the staging area. make targz-pkg && make INSTALL_HDR_PATH=$STAGING_DIR/usr headers_install # Check return code and bail if it looks bad. if [ $? -gt 0 ]; then echo "Kernel build failed!" exit 32 fi # Copy the kernel package to the staging area as a separate package. cp $SRC_DIR/$PKG_NAME.tar.gz $STAGING_DIR/../$PKG_NAME.i586.tar.gz # Create the kernel headers package if ! [ "$PKG_COMMAND" = "" ]; then export $PKG_NAME $STAGING_DIR $PKG_COMMAND else cd $STAGING_DIR tar -zcf ../$PKG_NAME-headers.tar.gz * fi # end of kernel blueprint