summaryrefslogtreecommitdiffstats
path: root/scripts/upd-kernel
blob: 30871135eff0b4ad87bad8e0c84498a46bbf05d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/sh
#
# take a boot directory with kernel + initrd and create a new one
# with a new kernel + initrd
# Usage: ./upd-kernel <olddir> <newdir> <newkernelrpm>
#
# 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 <http://www.gnu.org/licenses/>.
#

OLDDIR=`readlink -f $1`
NEWDIR=$2
KRPM=`readlink -f $3`

NEWVER=$(rpm -qp --provides $KRPM | awk -F ' = ' '/kernel-uname-r/ { print $2; }')

if [ -z "$OLDDIR" -o -z "$NEWDIR" -o -z "$KRPM" ]; then
  echo "Usage: $0 <olddir> <newdir> <newkernelrpm>"
  exit 1
fi

if [ ! -d $OLDDIR ]; then
  echo "Directory $OLDDIR doesn't exist"
  exit 1
fi

if [ -d $NEWDIR ]; then
    NEWDIR=`readlink -f $NEWDIR`
else
    NEWDIR=`readlink -f .`/$NEWDIR
    mkdir $NEWDIR
fi

WORKDIR=$(/bin/mktemp -d /tmp/kernrpm.XXXXXX)

pushd $WORKDIR > /dev/null

# explode the rpm
mkdir rpm
pushd rpm > /dev/null
rpm2cpio $KRPM | cpio -id --quiet
popd > /dev/null

# explode the initrd
mkdir initrd
pushd initrd > /dev/null
zcat $OLDDIR/initrd.img | cpio -id --quiet

for mod in $(find modules/ -type f -name '*.ko.gz' -exec basename {} \; | sort | uniq) ; do
    for path in $(find $WORKDIR/rpm/lib/modules/$NEWVER/ -name ${mod%.gz}); do
        dest=${path##$WORKDIR/rpm/lib/}
        mkdir -p $(dirname $dest)
        gzip < $path > $dest.gz
    done
done

/sbin/depmod -a -b . $NEWVER
rm -f modules/$NEWVER/modules.*map

find . | cpio --quiet -c -o | gzip -9 > $NEWDIR/initrd.img
popd > /dev/null

cp $WORKDIR/rpm/boot/vmlinuz-* $NEWDIR/vmlinuz
popd > /dev/null
rm -rf $WORKDIR