#!/bin/bash function die() { echo " (EE) $1" exit 1 } function info() { echo " (II) $1" } function silent() { OUTPUT=`$*` if [ "$?" != "0" ]; then echo $OUTPUT die "$* failed!" fi } # Function to grab var from src function getvar() { old=$(head -5 Makefile | grep "^$1") echo $(echo ${old/"$1 ="/} | sed -e "s/[ ]*\(.*\)[ ]*/\1/g") return 0 } if [ ! -f "./.config" ]; then CURDIR=`pwd` die "No kernel .config exists in $CURDIR!" fi if [ ! -f "./Makefile" ]; then die "No Makefile present!" fi VERSION=`getvar VERSION` PATCHLEVEL=`getvar PATCHLEVEL` SUBLEVEL=`getvar SUBLEVEL` EXTRAVERSION=`getvar EXTRAVERSION` . ./.config NAME="$VERSION.$PATCHLEVEL.$SUBLEVEL$EXTRAVERSION$CONFIG_LOCALVERSION" info "Detected kernel version $NAME" if [ $UID != "0" ]; then die "Must be root to install kernel!" fi # (1) copy modules if [ "$1" != "-m" ]; then info "Installing modules..." silent make -j32 modules_install else info "Skipping installing modules." fi # (2) copy kernel info "Installing kernel..." silent cp -v arch/x86_64/boot/bzImage /boot/vmlinuz-$NAME silent cp -v System.map /boot/System.map-$NAME # (3) build ramdisk info "Building module dependencies" silent depmod -v $NAME if [ "$1" != "-m" ]; then info "Building initial ramdisk..." silent update-initramfs -c -k $NAME else info "Skipping updating initial ramdisk..." fi # (4) make bootloader entry ALREADY_PRESENT=`grep "/vmlinuz-$NAME" /etc/grub.d/15_litmus ` if [ ! -z "$ALREADY_PRESENT" ]; then info "Bootloader entry appears to be already present." else info "Creating bootloader entry..." if [[ "$NAME" =~ "litmus" ]]; then cat >> /etc/grub.d/15_litmus <<__EOE__ menuentry 'Ubuntu/Litmus, with $NAME' --class ubuntu --class gnu-linux --class gnu --class os { recordfail insmod ext2 set root='(hd0,3)' search --no-floppy --fs-uuid --set 08b4e70f-d536-45bc-8693-164891c8834b linux /vmlinuz-$NAME root=/dev/sda5 ro quanta=aligned initrd /initrd.img-$NAME } __EOE__ else cat >> /etc/grub.d/15_litmus <<__EOE__ menuentry 'Ubuntu/Custom Kernel, with $NAME' --class ubuntu --class gnu-linux --class gnu --class os { recordfail insmod ext2 set root='(hd0,3)' search --no-floppy --fs-uuid --set 08b4e70f-d536-45bc-8693-164891c8834b linux /vmlinuz-$NAME root=/dev/sda5 ro initrd /initrd.img-$NAME } __EOE__ fi update-grub fi info "Kernel $NAME has been installed."