summaryrefslogtreecommitdiffstats
path: root/scripts/upd-kernel
blob: 0face88282380e1bc73e59b4c14df03599074a2d (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
#!/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>

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 <olddir> <newdir> <newkernelrpm>"
  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