- Joined
- Sep 26, 2002
- Location
- Indianapolis, IN
ok, i've been working on a script for my debian box... basically what the script does is it automatically runs all of the commands necessary to install a new kernel (with some slight user intervention of course). here is what i have so far:
now for the part where i am clueless: i want to make it so the script file (instead of starting vi to edit menu.lst) will automatically edit /boot/grub/menu.lst and make it search until it finds the line:
kernel /boot/vmlinuz-$1 root=/dev/hdc1 ro
and adds:
initrd /boot/initrd.img-$1
right after it. that will totally automate the whole process of creating a new kernel (with an exception of configuring the kernel in this case since that sort of defeats the purpose of using the latest kernel if you don't enable new options)
Code:
#!/bin/sh
# kernel update script
# created by: matt bentley
# creation date: 09/10/2006 2:01 AM
# last update: 09/10/2006 9:41 AM
# usage: run script in the form: './kernel_update 2.6.16.20' where 2.6.16.20 is the kernel you wish to use
if [ -z $1 ]; then
echo "error! please specify which kernel version you which to use"
echo "(example: './kernel_update 2.6.16.20')"
else
# install required debian packages from repository
echo "---INSTALLING NECESSARY PROGRAMS---"
sleep 3
apt-get install kernel-package ncurses-dev fakeroot wget bzip2 module-init-tools initrd-tools procps
# change pwd to /usr/src directory
cd /usr/src
# remove previous link to linux source
echo "---REMOVING PREVIOUS SOURCE LINKS---"
sleep 3
rm -r linux
# remove any old files from failed build
echo "---REMOVING OLD FAILED BUILD FILES---"
sleep 3
rm -r linux-$1
if [ -e /usr/src/linux-$1.tar.bz2 ]; then
echo "---NO DOWNLOAD IS NECESSARY, PROPER SOURCE FOUND---"
sleep 3
echo "---EXTRACTING SOURCE---"
sleep 3
tar -xjf linux-$1.tar.bz2
else
echo "---DOWNLOAD REQUIRED, DOWNLOADING PROPER SOURCE---"
sleep 3
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-$1.tar.bz2
echo "---EXTRACTING SOURCE---"
sleep 3
tar -xjf linux-$1.tar.bz2
fi
# create symbolic link
ln -s linux-$1 linux
# change pwd to /boot directory
cd /boot
# copy old config from current kernel
echo "---COPYING CONFIG FROM CURRENT KERNEL---"
sleep 3
cp config-$(uname -r) /usr/src/linux/.config
# change pwd to /usr/src/linux
cd /usr/src/linux
# build menuconfig
echo "---BUILDING MENUCONFIG---"
sleep 3
make menuconfig
# clean
echo "---CLEANING BUILD FILES---"
sleep 3
make-kpkg clean
# create .deb file
echo "---CREATING .DEB FILE---"
sleep 3
fakeroot make-kpkg --revision=custom.1.0 kernel_image
# change pwd to /usr/src
cd /usr/src
# install .deb file
echo "---INSTALLING .DEB KERNEL FILE---"
sleep 3
dpkg -i kernel-image-$1_custom.1.0_i386.deb
# change pwd to /boot
cd /boot
# create initrd.img
echo "---CREATING INITRD.IMG FOR NEW KERNEL---"
sleep 3
mkinitrd -o /boot/initrd.img-$1 $1
# reminder to add initrd section to grub config
echo "don't forget to add initrd section to grub config!"
sleep 3
# change pwd to /boot/grub
cd /boot/grub
# starting vi for menu.lst
echo "---STARTING VI EDITING MENU.LST---"
sleep 3
vi menu.lst
fi
now for the part where i am clueless: i want to make it so the script file (instead of starting vi to edit menu.lst) will automatically edit /boot/grub/menu.lst and make it search until it finds the line:
kernel /boot/vmlinuz-$1 root=/dev/hdc1 ro
and adds:
initrd /boot/initrd.img-$1
right after it. that will totally automate the whole process of creating a new kernel (with an exception of configuring the kernel in this case since that sort of defeats the purpose of using the latest kernel if you don't enable new options)