Benutzer-Werkzeuge

Webseiten-Werkzeuge


scytheman:zeugs:scripte:kernel_2.6_compile_script.sh

↑ zurück

kernel 2.6 compile script.sh

Beschreibung

Dieses Script führt einen automatisch durch die verschiedenen Schritte, die zum Konfigurieren und Kompilieren eines Kernels notwendig sind. Darüber hinaus gibt es auch die Möglichkeit, einen bereits installierten Kernel zu löschen.

Anmerkung: Mittlerweile gibt es eine von Grund auf neugeschriebene Version dieses Scripts. Diese basiert nicht mehr auf dialog und ist dadurch weitaus portabler. Darüber hinaus enthält sie diverse Verbesserungen und wird gegenüber der hier angebotenen Version dringend empfohlen.

Benötigt

  • dialog
  • alles, was zum Kompilieren und Konfigurieren eines Kernels benötigt wird wie gcc, make, libncurses5-dev

Code

#!/bin/sh
 
# kernel-compile script
 
scversion="v0.6.1"
 
clear
 
echo "If you get some strange errors while trying to execute this script make sure \"dialog\" is installed!"
 
dialog --clear --title "manual" --backtitle "kernel-compile script $scversion" --msgbox "This is the kernel-compile script $version created by ScyTheMan.
 
This script helps you to compile your own kernel.
It is possible to decide whether to configure the kernel, build the kernel and/or build the modules as well as editing the configuration file of lilo (maybe grub support will be added in the future).
 
Note that this script is created for compiling 2.6 kernels only!" 14 75
 
echo "kernel-compile script $scversion for 2.6 kernels"
echo
echo "by scytheman"
echo
 
# checking for distro
if ! test -e "/etc/debian_version"; then
 dialog --clear --title "manual" --backtitle "kernel-compile script $scversion" --msgbox "Warning! You are not running debian.
This script has only be testet with debian, thus on other distros it may not work properly or may cause harm to your system!" 10 75
fi
 
# checking for root
if ! [ `whoami` == "root" ]; then
 dialog --clear --title "manual" --backtitle "kernel-compile script $scversion" --msgbox "You need to be root to execute this script!" 7 50
 exit
fi
 
dialog --clear --title "choice" --backtitle "kernel-compile script $scversion" --checklist "What do you want to do today?" 8 75 2 \
"configure" "configure and compile 2.6 kernel" off \
"remove" "remove 2.6 kernel" off 2> /tmp/tmp.dialog
choice=`cat /tmp/tmp.dialog`
 
#############################################
#
# B O O T L O A D E R    C H E C K :
#
#############################################
# check for bootloader GRUB
if test -e "/boot/grub/menu.lst"; then
 echo "/boot/grub/menu.lst found ..."
 bl_grub=yes
fi
 
# check for bootloader LILO
if test -e "/etc/lilo.conf"; then
 echo "/etc/lilo.conf found ..."
 bl_lilo=yes
fi
 
if [ "$bl_grub" == "yes" ] && [ "$bl_lilo" == "yes" ]; then
 dialog --clear --title "bootloader" --backtitle "kernel-compile script $scversion" --checklist "I found two bootloader on your system, GRUB and LILO.
Which of them do you use?" 9 60 2 \
"grub" "GRUB, of course!" off \
"lilo" "Sir! LILO sir!" off 2> /tmp/tmp.dialog
 bootloader=`cat /tmp/tmp.dialog`
 echo $bootloader
elif [ "$bl_grub" == "yes" ]; then
 bootloader="\"grub\""
elif [ "$bl_grub" == "no" ]; then
 bootloader="\"lilo\""
fi
 
if [ "$bootloader" == "\"grub\"" ]; then
 bl_path="/boot/grub/menu.lst"
 echo "using GRUB as bootloader ..."
else
 bl_path="/etc/lilo.conf"
 echo "using LILO as bootloader ..."
fi
 
#############################################
#
# K E R N E L    C O N F I G U R A T I O N :
#
#############################################
if [ $choice == "\"configure\"" ]; then# <- selected choice is saved within ""
dialog --clear --nocancel --title "version of the kernel" --backtitle "kernel-compile script $scversion" --inputbox "version of the kernel (for example '2.6.8'):" 10 50 2.6. 2> /tmp/tmp.dialog # inputbox for kernel version, input string saved in /tmp/tmp.dialog
version=`cat /tmp/tmp.dialog` # assign kernel version to $version
dialog --clear --nocancel --title "name of the kernel" --backtitle "kernel-compile script $scversion" --inputbox "name of the kernel (normally it's the best to use the version of the kernel):" 10 50 $version 2> /tmp/tmp.dialog
name=`cat /tmp/tmp.dialog`
 
# checking for correct kernelsourcedir
if test -e /usr/src/linux-$version; then               # kernel.org like kernelsourcedir
 kerneldir=/usr/src/linux-
elif test -e /usr/src/kernel-source-$version; then     # debian like kernelsourcedir
 kerneldir=/usr/src/kernel-source-
else                                                   # for other kerneldirs (maybe of other distros which i doesn't know)
 dialog --clear --nocancel --title "kernelsourcedir" --backtitle "kernel-compile script $scversion" --inputbox "Warning!
Neither /usr/src/linux-$version (kernel.org like) nor /usr/src/kernel-source-$version (debian like) seems to be the correct kernelsourcedir.
The script is unable to determine the correct dir, thus you have to enter it manually.
kernelsourcedir without the kernelversion (for example '/usr/src/kernel-source-'):" 14 75 /usr/src/ 2> /tmp/tmp.dialog
kerneldir=`cat /tmp/tmp.dialog`
fi
 
echo "..........................................................................."
echo -n "changing directory to $kerneldir"
echo $version
echo "..........................................................................."
cd $kerneldir$version
 
dialog --clear --title "kernel configuration" --backtitle "kernel-compile script $scversion" --yesno "Now you have the chance to configure your kernel. Otherwise the .config in the kernelsourcedir will be used.
Do you want to run the kernel configuration?" 8 75
if [ $? = 0 ]; then
 echo "..........................................................................."
 echo "running config"
 echo "..........................................................................."
 make menuconfig
fi
 
echo "..........................................................................."
echo "cleaning directory"
echo "..........................................................................."
make clean
 
dialog --clear --title "building kernel" --backtitle "kernel-compile script $scversion" --yesno "Now you can decide whether to build the kernel or not. If you've changed only some modules at the kernelconfiguration you do not need to build the whole kernel again.
Do you want to build the kernel?" 8 75
if [ $? = 0 ]; then
 q_kern="yes"# needed later
 echo "..........................................................................."
 echo "building kernel"
 echo "..........................................................................."
 make bzImage
fi
 
dialog --clear --title "building modules" --backtitle "kernel-compile script $scversion" --yesno "Now you can decide whether to build the modules or not. If you've changed only some build-in stuff at the kernelconfiguration you do not need to build the modules again, but this may lead to errors.
Do you want to build the modules?" 8 75
if [ $? = 0 ]; then
 echo "..........................................................................."
 echo "making modules"
 echo "..........................................................................."
 make modules
 
 echo "..........................................................................."
 echo "installing modules"
 echo "..........................................................................."
 make modules_install
fi
 
if [ "$q_kern" == "yes" ]; then     # copying kernel stuff only needed when new kernel has been build
 echo "..........................................................................."
 echo -n "copying arch/i386/boot/bzImage to /boot/bzImage-"
 echo $name
 echo "..........................................................................."
 cp arch/i386/boot/bzImage /boot/bzImage-$name
 
 echo "..........................................................................."
 echo -n "copying System.map to /boot/System.map-"
 echo $version
 echo "..........................................................................."
 cp System.map /boot/System.map-$name
 
 echo "..........................................................................."
 echo "changing directory to /boot"
 echo "..........................................................................."
 cd /boot
 
 echo "..........................................................................."
 echo "deleting System.map"
 echo "..........................................................................."
 rm System.map
 
 echo "..........................................................................."
 echo -n "creating new symbolic link from /boot/System.map-"
 echo -n $name
 echo " to /boot/System.map"
 echo "..........................................................................."
 ln -s /boot/System.map-$name /boot/System.map
fi
 
echo "..........................................................................."
echo "cleaning directory"
echo "..........................................................................."
make clean
 
if [ "$q_kern" == "yes" ]; then     # editing and running bootloader config only needed when new kernel has been build
 dialog --clear --title "editing bootloader config" --backtitle "kernel-compile script $scversion" --yesno "Now you can decide whether you want to edit your bootloader config or not.
This is only necessary if you've compiled a completly new kernel which isn't already added in your config.
Do you want to edit your config?" 9 75
 if [ $? = 0 ]; then
  echo "..........................................................................."
  echo "editing bootloader config"
  echo "..........................................................................."
  editor $bl_path
 fi
 
 # if we are using lilo we have to run it after compiling a new kernel
 if [ "$bootloader" == "\"lilo\"" ]; then
  echo "..........................................................................."
  echo "running lilo"
  echo "..........................................................................."
  lilo
 fi
fi
 
#############################################
#
# K E R N E L    R E M O V E :
#
#############################################
else
 dialog --clear --nocancel --title "name of the kernel" --backtitle "kernel-compile script $scversion" --inputbox "Now you have to give me the name of the kernel you want to remove.
Note: This is NOT the kernel version! (but mostly the names are the same).
If you are not sure which name the kernel has, look into /boot. There you can find the images:
Example 1: \"bzImage-2.6.7\"        -> here the name is \"2.6.7\"
Example 2: \"vmlinuz-2.4.18-bf2.4\" -> here the name is \"2.4.18-bf2.4\"
Now type in the correct name: " 14 75 2.6. 2> /tmp/tmp.dialog
 name=`cat /tmp/tmp.dialog`
 
 dialog --clear --title "removing kernel $name" --backtitle "kernel-compile script $scversion" --yesno "Do you really want to remove that kernel?" 5 50
 if [ $? = 0 ]; then
 echo "removing file /boot/bzImage-$name..."
 rm /boot/bzImage-$name
 echo "removing file /boot/System.map-$name..."
 rm /boot/System.map-$name
 echo "removing directory /lib/modules/$name..."
 rm -r /lib/modules/$name
 else # no removing
  dialog --clear --title "removing aborted" --backtitle "kernel-compile script $scversion" --msgbox "OK. I do not remove the kernel." 6 50
 fi # remove
fi # configure
 
rm /tmp/tmp.dialog
 
echo
echo "finished"
 
echo
echo "---"
echo
echo "kernel-compile script $scversion generated by scytheman"
scytheman/zeugs/scripte/kernel_2.6_compile_script.sh.txt · Zuletzt geändert: 2014/03/01 17:13 (Externe Bearbeitung)