Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
My Installkernel script
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
Dr.Willy
Guru
Guru


Joined: 15 Jul 2007
Posts: 491
Location: NRW, Germany

PostPosted: Mon Aug 03, 2009 6:38 pm    Post subject: My Installkernel script Reply with quote

Hi everybody,

all those of you who ever had a look at 'make help' when installing a new kernel probably noticed the installkernel script.
It's a script called by 'make install' to, well, install the kernel.
Now the default installkernel script is pretty simple. I think all it does is copy bzImage and System.map over to /boot.
A more sophisticated script comes with sys-apps/debianutils, but even that is kind of lacking in my opinion.
Long story short I wrote my own script:

When I install a new kernel there are two things I have to do by hand.
First copy over the kernel files and append a version-prefix and second, add an entry to grub's menu.lst. (I think grub2 has some sort of mechanism to modify it's config automatically, but i'm not going to hold my breath until that goes stable, so ...)
Appending the version-prefix was easy, modifying the menu.lst aka grub.conf was a bit more tricky:
My solution was to split up the config file and put each part in a seperate file. That way I could merge the static grub-settings with the automatically generated kernel entries.
The result is a ready-to-use kernel after you type 'make install'.

I found the script useful, so I thought I'd share it with you.
To use it you have to:
1) Split up your menu.lst file and place the files under /boot/*_grub
Name the files so that 'for f in $(ls /boot/*_grub) ; do cat $f ; done' outputs them in the same order as in the config file. The default naming scheme is "kernelversion_grub" e.g. "2.6.29-gentoo-r5_grub"
2) Put the script unter /root/bin/installkernel and make it executable.
3) READ THE SOURCECODE!
I mean it. This script is distributed in the hope that it will be useful, but if it eats your computer, it is not my fault (ok technically it might be my fault, but it sure will be your problem). Plus you have to adjust the script unless your root is /dev/hda3 on (hd0,0).
Oh and also you will be able to post suggestions, bug reports and patches ;)

Code:
#!/bin/bash
# Author: Wilke Schwiedop <w.schwiedop@web.de>
# Distributed under the terms of the GNU General Public License v3
#   $1 - kernel version (e.g 2.6.10-something-r5)
#   $2 - kernel image file
#   $3 - kernel map file
#   $4 - default install path (blank if root directory)

die() {
   echo ${@} >&2
   exit 1
}

[[ $# == 4 ]] || die "Params don't look sane"

kernelDir="/usr/src/linux-$1"

kernelImage="${1}_$(basename ${2})"
kernelConfig="${1}_config"
kernelMap="${1}_${3}"
kernelEntry="${1}_grub"

grubConfFile="/boot/grub/menu.lst"

if [[ -f "${4}/${kernelImage}" || -f "${4}/${kernelConfig}" || -f "${4}/${kernelMap}" ]] ; then
   currentDate=$(date +"%Y%m%d")
   echo "Creating backup of existing kernel"
   tarball="kernel-${1}.${currentDate}.tar"
   tar --create --verbose --backup=numbered --file ${4}/${tarball} \
                                       ${4}/${kernelImage} \
                                       ${4}/${kernelConfig} \
                                       ${4}/${kernelMap}
   echo "${tarball} is ready"
fi

echo "Copying kernel files"
cp --verbose ${kernelDir}/${2}     ${4}/${kernelImage}
cp --verbose ${kernelDir}/.config  ${4}/${kernelConfig}
cp --verbose ${kernelDir}/${3}     ${4}/${kernelMap}


if [[ ! -f $4/$kernelEntry ]] ; then # do not overwrite existing (possibly user modified) entries
   echo "Creating $4/$kernelEntry"
   # 2.6.10-something-r5 -> Something
   kernelTitle=$(echo $1 | awk 'BEGIN { FS = "-"; OFS = "" } { print toupper(substr($2, 0, 1)), substr($2, 2) }')
   # 2.6.10-something-r5 -> 2.6.10-r5
   kernelVersion=$(echo $1 | awk 'BEGIN { FS = "-"; OFS = "" } { if($3) { print $1, "-", $3 } else { print $1 } }')

   cat > $4/$kernelEntry <<-ENDENTRY
      title=${kernelTitle} Linux ${kernelVersion}
      root (hd0,0)
      kernel /${kernelImage} root=/dev/hda3
      savedefault
   ENDENTRY


   echo "Assembling menu.lst"
   :> $grubConfFile #clear file
   for f in $(ls $4/*_grub) ; do
      echo "## $f"  >> $grubConfFile
      cat $f        >> $grubConfFile
      echo          >> $grubConfFile
   done
fi

exit 0
Back to top
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 7060

PostPosted: Mon Aug 03, 2009 7:25 pm    Post subject: Reply with quote

i don't want kill your joy but make install do that
make install with 2.6.30 previous was 2.6.28
System.map (point to 2.6.30)
System.map-2.6.30
System.map.2.6.28
System-map.old (point to 2.6.28.) edit: add a dot after 28 else it will convert it to a smiley

same for config and vmlinuz, so grub entries as
kernel /vmlinuz root=/blahblah will boot latest kernel (the 2.6.30 as in the example)
and another grub entry with
kernel /vmlinuz.old root=/blahblah will boot previous kernel (the 2.6.28 so)

but thanks for sharing your work with us.
Back to top
View user's profile Send private message
Dr.Willy
Guru
Guru


Joined: 15 Jul 2007
Posts: 491
Location: NRW, Germany

PostPosted: Mon Aug 03, 2009 8:34 pm    Post subject: Reply with quote

krinn wrote:
i don't want kill your joy but make install do that
make install with 2.6.30 previous was 2.6.28
System.map (point to 2.6.30)
System.map-2.6.30
System.map.2.6.28
System-map.old (point to 2.6.28.) edit: add a dot after 28 else it will convert it to a smiley

same for config and vmlinuz, so grub entries as
kernel /vmlinuz root=/blahblah will boot latest kernel (the 2.6.30 as in the example)
and another grub entry with
kernel /vmlinuz.old root=/blahblah will boot previous kernel (the 2.6.28 so)

but thanks for sharing your work with us.

I know.
But I didn't like the script as I said. If I change the kernel-config and update the kernel 'make install' points the symlink to the previously used kernel and not the one I inted to use as backup.
Also I like to have my kernels labeled correctly (in grub).
The script also doesn't overwrite its' backups (".old") and I wanted to change the naming scheme so that kernels could be removed with tab completion before the wildcard (yes, I am that lazy ;))

Minor things you might say, but also just a small script :)
If nobody agrees with that - whatever :P
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum