#!/bin/sh # # take a boot directory with kernel + initrd and create a new one # with a new kernel + initrd # Usage: ./upd-kernel # # Copyright (C) 2007 Red Hat, Inc. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # OLDDIR=`readlink -f $1` NEWDIR=$2 KRPM=`readlink -f $3` KNAME=$(rpm -qp --qf "%{NAME}" $KRPM) if [ "$KNAME" != "kernel" ]; then var=$(echo $KNAME | sed -e 's/kernel-//') fi ARCH=$(rpm -qp --qf "%{ARCH}" $KRPM) NEWVER=$(rpm -qp --qf "%{VERSION}-%{RELEASE}" $KRPM)$var if [ -z "$OLDDIR" -o -z "$NEWDIR" -o -z "$KRPM" ]; then echo "Usage: $0 " exit 1 fi if [ ! -d $OLDDIR ]; then echo "Directory $OLDDIR doesn't exist" exit 1 fi if [ -f $NEWDIR ]; then NEWDIR=`readlink -f $NEWDIR` else NEWDIR=`readlink -f .`/$NEWDIR mkdir $NEWDIR fi WORKDIR=$(/bin/mktemp -d /tmp/kernrpm.XXXXXX) pushd $WORKDIR # explode the rpm mkdir rpm pushd rpm rpm2cpio $KRPM |cpio -id popd # explode the rpm mkdir initrd pushd initrd zcat $OLDDIR/initrd.img |cpio -id popd mkdir initrd/modules/mods # explode the moduleball pushd initrd/modules/mods zcat ../modules.cgz |cpio -id popd mkdir -p newmods/$NEWVER/$ARCH for i in $(find initrd/modules/mods -type f -name '*.ko' -exec basename {} \;); do find $WORKDIR/rpm/lib/modules/*/ -name $i -exec cp -v {} $WORKDIR/newmods/$NEWVER/$ARCH \; ; done rm -rf initrd/modules/mods pushd newmods find . |cpio --quiet -H crc -o |gzip -9 > $WORKDIR/initrd/modules/modules.cgz popd pushd initrd find . |cpio -c -o |gzip -9 > $NEWDIR/initrd.img popd cp -v $WORKDIR/rpm/boot/vmlinuz-* $NEWDIR/vmlinuz popd rm -rf $WORKDIR