Azitech

Azimout's Linux weblog

instkernel.sh script

leave a comment »

I have written a script that automates for me the task of installing a new kernel. That is, after I have done all the ketchup, config and make stuff, I would have to install the kernel, its modules, create and populate a new subdirectory under /lib/firmware, and update the initrd. This script does all this automatically. This was my first serious bash script, so I found the Advanced Bash-Scripting Guide very helpful.

# azimout: this script installs a given kernel version
# it takes the new kernel version from the Makefile
# it will install the kernel and its modules
# it will create the appropriate /lib/firmware sub-directory if missing
# and it will update the ramdisk

#!/bin/bash
CURRENT_KERNEL=$(uname -r)
KERNEL_DIRECTORY=$(pwd)
VAR1=$(grep -w 'VERSION =' Makefile | awk '{print $3}')
VAR2=$(grep -w 'PATCHLEVEL =' Makefile | awk '{print $3}')
VAR3=$(grep -w 'SUBLEVEL =' Makefile | awk '{print $3}')
VAR4=$(grep -w 'EXTRAVERSION =' Makefile | awk '{print $3}')
NEW_KERNEL=$VAR1.$VAR2.$VAR3$VAR4

read -p "Installing the kernel and modules; press any key..."
sudo make modules_install install

if [ $NEW_KERNEL != "$CURRENT_KERNEL" ]
then
  read -p "Copying firmware from $CURRENT_KERNEL to $NEW_KERNEL; press any key..."
  cd /lib/firmware
  sudo mkdir $NEW_KERNEL
  sudo cp -r $CURRENT_KERNEL/* -t $NEW_KERNEL
  cd $KERNEL_DIRECTORY
fi

if [ $NEW_KERNEL != "$CURRENT_KERNEL" ]
then
  read -p "Creating the ramdisk; press any key..."
  sudo update-initramfs -k $NEW_KERNEL -c
else
  read -p "Updating the ramdisk; press any key..."
  sudo update-initramfs -k $NEW_KERNEL -u
fi

echo "You still need to edit the grub menu file manually..."
Advertisements

Written by azimout

17/06/2008 at 10:15

Posted in Tricks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: