#!/bin/sh # mkkernel # v1.7 # Tunes the kernel parameters listed in the file "./settings" # This file must have the format PARAMETER VALUE # eg : # MAXUP 2000 # shell, softscreen, etc. echo " DRS/NX SPARC Kernel Tuning Utility" echo " === S G Parker and D A Dallas ===" echo USAGE="Usage : `basename $0` [-f ] [-e] [-l]" EXACT="NO" LIST="NO" SETTINGSFILE=settings while getopts 'elf:?' c do case $c in e) EXACT="YES" ;; f) SETTINGSFILE=$OPTARG;; l) LIST="YES";; \?) echo $USAGE exit 2;; esac done trap 'echo "`basename $0` : Interrupted" ; exit 1' 1 2 15 if [ "`id|cut -d'(' -f2|cut -d')' -f1`" -ne "root" ] then echo "You must be super-user to run this script." exit 1 fi echo "Checking $SETTINGSFILE ..." if [ ! -r $SETTINGSFILE ] then echo "ERROR: Cannot read settings file $SETTINGSFILE" exit 1 fi rm /tmp/settings > /dev/null 2>&1 while i=`line` # Remove comments and do # blank lines, convert j=`echo $i|awk '{ print $1 }' | cut -c1` # all to upper case if [ "$j" != "#" ] && [ "$j" != "" ] then echo $i | tr '[a-z]' '[A-Z]' >> /tmp/settings fi done < $SETTINGSFILE SETTINGSFILE=/tmp/settings echo "Checking `uname -n` architecture ..." ARCH="INTEL" # Default to Intel if [ "`uname -p`" = "sparc" ] then case "`uname -v`" in ?MPlus.*) ARCH="MPLUS" ;; *) BASE='/etc/master.d' # SPARC non-MPlus ARCH="SPARC" # settings. ;; esac fi if [ "$ARCH" != "SPARC" ] then echo "This script is for DRS/NX SPARC machines only." echo "`uname -n` architecture is $ARCH" exit 1 fi echo "`uname -n` architecture is $ARCH" # Confirm to user if [ "$LIST" = "YES" ] then echo "`uname -n`: Current kernel parameters" ls -l /stand/`kernel` while i=`line` do PARAM=`echo $i | awk '{ print $1 }'` VALUE=`echo $i | awk '{ print $2 }'` filename=`grep "^${PARAM}" ${BASE}/* | head -1 | cut -d: -f1` if [ "$filename" = "" ] then echo "`basename $0`: Skipping nonexistant parameter '$PARAM'" else PRESENT=`grep "^${PARAM}" ${filename} | head -1| tr '=' ' ' | awk '{ print $2 }'` echo "$PARAM $PRESENT \c" > /tmp/out.param if [ "$VALUE" -gt "$PRESENT" ] then echo " (> to $VALUE)" >> /tmp/out.param elif [ "$VALUE" -lt "$PRESENT" ] then echo " (< to $VALUE)" >> /tmp/out.param else echo " (= `basename $SETTINGSFILE`)" >> /tmp/out.param fi cat /tmp/out.param fi done < $SETTINGSFILE exit 0 fi mkdir /tmp/sgp > /dev/null 2>&1 # Create backups mkdir /tmp/sgp/master.d > /dev/null 2>&1 echo "Backing up kernel files ..." cp -r ${BASE}/* /tmp/sgp/master.d rm /tmp/files.edited > /dev/null 2>&1 # Make it tidy while i=`line` do PARAM=`echo $i | awk '{ print $1 }'` VALUE=`echo $i | awk '{ print $2 }'` filename=`grep "^$PARAM" ${BASE}/* | cut -d: -f1 | head -1` ls -l /boot|grep -i "`basename $filename`" > /dev/null 2>&1 if [ $? -ne "0" ] then echo "ERROR: File '$filename' is not a valid tuning file" echo "The file(s) containing parmeter $PARAM are :" grep "^$PARAM" ${BASE}/* | cut -d: -f1 exit 1 fi if [ -z "$filename" ] then echo "`basename $0`: Skipping nonexistant parameter '$PARAM'" else # this is a big "else" ... current_value=`grep "^$PARAM" $filename | awk '{ print $3 }'` if [ "$current_value" -lt "$VALUE" ] then TUNEME="YES" else TUNEME="NO" fi if [ "$EXACT" = "YES" ] then TUNEME="YES" fi if [ "$TUNEME" = "YES" ] then # fix the file echo "Tuning $PARAM from $current_value to $VALUE" linenumber=`grep -n "^$PARAM" $filename | cut -d: -f1` thisline=`expr $linenumber - 1` # all lines before PARAM nextline=`expr $linenumber + 1` # all lines after PARAM head -$thisline $filename > /tmp/steve.tunefile if [ $? -eq "1" ] then echo "ERROR: Cannot write to /tmp directory" exit 1 fi echo "$PARAM = $VALUE" >> /tmp/steve.tunefile tail +$nextline $filename >> /tmp/steve.tunefile grep $filename /tmp/files.edited > /dev/null 2>&1 if [ $? -ne "0" ] then basename $filename >> /tmp/files.edited # Log the fact that we've fi # edited this file. mv /tmp/steve.tunefile $filename # Place the edited file if [ $? -ne "0" ] # in the right place. then echo "ERROR: Cannot move /tmp/steve.tunefile to $filename" echo "The desired values are in /tmp/steve.tunefile" exit 1 fi fi # whether the file needs editing fi # the "else" part of whether the parameter exists done < $SETTINGSFILE if [ -s /tmp/files.edited ] then echo "Rebuilding kernel ..." cat /tmp/files.edited|tr '[a-z]' '[A-Z]' > /tmp/files.mkboot cd /boot for filename in `cat /tmp/files.mkboot` do mkboot $filename done mkboot -k KERNEL rm /tmp/files.mkboot > /dev/null 2>&1 cd / cunix -o unix.new mv /stand/unix /stand/unix.save || echo "unable to move /stand/unix to /stand/unix.save" mv unix.new /stand/unix || echo "unable to move /unix.new to /stand/unix" echo "The kernel has been tuned and rebuilt. Please reboot the machine" echo " to start using this new kernel." echo echo "/tmp/sgp/* contains backups of the previous kernel files." else echo "No files required editing. The kernel is already tuned to at least" echo " the values listed in $SETTINGSFILE" fi rm /tmp/files.edited > /dev/null 2>&1