Magellan Linux

Annotation of /trunk/grubby/new-kernel-pkg

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (hide annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (17 years, 2 months ago) by niro
Original Path: trunk/mkinitrd-magellan/grubby/new-kernel-pkg
File size: 10183 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

1 niro 532 #!/bin/bash
2     #
3     # Invoked upon installation or removal of a kernel package, the following
4     # tasks are/can be done here:
5     # creation/removal of initrd
6     # run of depmod/removal of depmod generated files
7     # addition/removal of kernel images from grub/lilo configuration (via grubby)
8     #
9     # Copyright (C) 2002-2005 Red Hat, Inc.
10     #
11     # modified for Magellan-Linux by Niels Rogalla <niro@magellan-linux.de>
12     #
13    
14     PATH=/sbin:/bin:$PATH
15    
16     lilo=/sbin/lilo
17    
18     # some defaults that are sane for most arches
19     kernelName=kernel
20    
21     if [ -x ./grubby ]; then
22     grubby=./grubby
23     else
24     grubby=/sbin/grubby
25     fi
26    
27     [ -f /etc/sysconfig/kernel ] && . /etc/sysconfig/kernel
28    
29     cfgGrub=""
30     cfgLilo=""
31     runLilo=""
32     grubConfig=""
33    
34     ARCH=$(uname -m)
35    
36     if [ $ARCH = 'ia64' ]; then
37     liloConfig=/boot/efi/EFI/redhat/elilo.conf
38     bootPrefix=/boot/efi/EFI/redhat
39     liloFlag=elilo
40     isx86=""
41     elif [ $ARCH = 'ppc64' -o $ARCH = 'ppc' ]; then
42     liloConfig=/etc/yaboot.conf
43     bootPrefix=/boot
44     lilo=/sbin/ybin
45     liloFlag=yaboot
46     runLilo="yes"
47     isx86=""
48     elif [ $ARCH = 'sparc' -o $ARCH = 'sparc64' ]; then
49     liloConfig=/etc/silo.conf
50     bootPrefix=/boot
51     liloFlag=silo
52     lilo=/sbin/silo
53     isx86=""
54     elif [ $ARCH = 's390' -o $ARCH = 's390x' ]; then
55     liloConfig=/etc/zipl.conf
56     bootPrefix=/boot
57     liloFlag=zipl
58     lilo=/sbin/zipl
59     runLilo="yes"
60     isx86=""
61     else
62     # this leaves i?86 and x86_64
63     liloConfig=/etc/lilo.conf
64     grubConfig=/boot/grub/grub.conf
65     bootPrefix=/boot
66     liloFlag=lilo
67     isx86="yes"
68     fi
69    
70     mode=""
71     version=""
72     initrd=""
73     initrdfile=""
74     moddep=""
75     verbose=""
76     makedefault=""
77     package=""
78     mbkernel=""
79     mbargs=""
80    
81     usage() {
82     echo "Usage: `basename $0` [-v] [--mkinitrd] [--rminitrd]" >&2
83     echo " [--initrdfile=<initrd-image>] [--depmod] [--rmmoddep]" >&2
84     echo " [--kernel-args=<args>] [--banner=<banner>]" >&2
85     echo " [--multiboot=multiboot] [--mbargs=mbargs]" >&2
86     echo " [--make-default] <--install | --remove> <kernel-version>" >&2
87     echo " (ex: `basename $0` --mkinitrd --depmod --install 2.4.7-2)" >&2
88     exit 1
89     }
90    
91     install() {
92     # XXX kernel should be able to be specified also (or work right on ia64)
93     if [ ! -f $bootPrefix/$kernelName-$version ] ; then
94     [ -n "$verbose" ] && echo "kernel for $version does not exist, not running grubby"
95     return
96     fi
97    
98     INITRD=""
99     if [ -f $initrdfile ]; then
100     [ -n "$verbose" ] && echo "found $initrdfile and using it with grubby"
101     INITRD="--initrd $initrdfile"
102     fi
103    
104     # FIXME: is this a good heuristic to find out if we're on iSeries?
105     if [ -d /proc/iSeries ]; then
106     [ -n "$verbose" ] && echo "On an iSeries, just making img file"
107     if [ -z $initrdfile ]; then
108     [ -n "$verbose" ] && echo "No initrd, just adding system map"
109     /sbin/addSystemMap $bootPrefix/System.map-$version $bootPrefix/$kernelName-$version $bootPrefix/vmlinitrd-$version
110     else
111     /sbin/addSystemMap $bootPrefix/System.map-$version $bootPrefix/$kernelName-$version $bootPrefix/vmlinux.sm-$version
112     /sbin/addRamDisk $initrdfile $bootPrefix/System.map-$version $bootPrefix/vmlinux.sm-$version $bootPrefix/vmlinitrd-$version 2>/dev/null
113     rm $bootPrefix/vmlinux.sm-$version
114     fi
115     return
116     fi
117    
118     # get the root filesystem to use; if it's on a label make sure it's
119     # been configured. if not, get the root device from mount
120     rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab)
121     short=$(echo $rootdevice | cut -d= -f1)
122     if [ "$short" == "LABEL" ]; then
123     label=$(echo $rootdevice | cut -d= -f2 |head -n 1)
124     device=$(echo "showlabels" | /sbin/nash --force --quiet |
125     awk '$2 == "'$label'" {print $1}')
126     if [ -z "$device" ]; then
127     rootdevice=$(mount | awk '$3 == "/" { print $1 }')
128     fi
129     fi
130    
131     if [ -n "$mbkernel" ]; then
132     mb="--add-multiboot=$mbkernel"
133     if [ -n "$mbargs" ]; then
134     mb="$mb --mbargs=$mbargs"
135     fi
136     [ -n "$verbose" ] && echo "multiboot specified, not updating lilo.conf"
137     cfgLilo=""
138     fi
139    
140     if [ -n "$cfgGrub" ]; then
141     [ -n "$verbose" ] && echo "adding $version to $grubConfig"
142    
143     if [ -n "$banner" ]; then
144     title="$banner ($version)"
145     elif [ -f /etc/mageversion ]; then
146     title="Magellan Linux $(< /etc/mageversion) ($version)"
147     else
148     title="Magellan Linux ($version)"
149     fi
150     /sbin/grubby --add-kernel=$bootPrefix/$kernelName-$version $INITRD \
151     --copy-default $makedefault $mb --title "$title" \
152     --args="root=$rootdevice $kernargs" \
153     --remove-kernel="TITLE=$title"
154     else
155     [ -n "$verbose" ] && echo "$grubConfig does not exist, not running grubby"
156     fi
157    
158     if [ -n "$cfgLilo" ]; then
159     [ -n "$verbose" ] && echo "adding $version to $liloConfig"
160    
161     /sbin/grubby --add-kernel=$bootPrefix/$kernelName-$version $INITRD \
162     --copy-default $makedefault --title $version \
163     --args="root=$rootdevice $kernargs" \
164     --remove-kernel="TITLE=$version" \
165     --$liloFlag
166    
167     if [ -n "$runLilo" ]; then
168     [ -n "$verbose" ] && echo "running $lilo"
169     if [ ! -x $lilo ] ; then
170     [ -n "$verbose" ] && echo "$lilo does not exist"
171     else
172     $lilo > /dev/null
173     fi
174     fi
175     else
176     [ -n "$verbose" ] && echo "$liloConfig does not exist, not running grubby"
177     fi
178    
179     }
180    
181     remove() {
182     # FIXME: is this a good heuristic to find out if we're on iSeries?
183     if [ -d /proc/iSeries ]; then
184     [ -n "$verbose" ] && echo "On an iSeries, remove img file"
185     rm -f $bootPrefix/$kernelName-$version.img 2>/dev/null
186     return
187     fi
188    
189     if [ -n "$cfgGrub" ]; then
190     [ -n "$verbose" ] && echo "removing $version from $grubConfig"
191     /sbin/grubby --remove-kernel=$bootPrefix/$kernelName-$version
192     else
193     [ -n "$verbose" ] && echo "$grubConfig does not exist, not running grubby"
194     fi
195    
196     if [ -n "$cfgLilo" ]; then
197     [ -n "$verbose" ] && echo "removing $version from $liloConfig"
198     /sbin/grubby --remove-kernel=$bootPrefix/$kernelName-$version \
199     --$liloFlag
200    
201     if [ -n "$runLilo" ]; then
202     [ -n "$verbose" ] && echo "running $lilo"
203     if [ ! -x $lilo ] ; then
204     [ -n "$verbose" ] && echo "$lilo does not exist"
205     else
206     $lilo > /dev/null
207     fi
208     fi
209     else
210     [ -n "$verbose" ] && echo "$liloConfig does not exist, not running grubby"
211     fi
212     }
213    
214     mkinitrd() {
215     [ -n "$verbose" ] && echo "creating initrd $initrdfile using $version"
216     /sbin/mkinitrd --allow-missing -f $initrdfile $version
217     rc=$?
218     if [ $rc != 0 ]; then
219     echo "mkinitrd failed" >&2
220     exit 1
221     fi
222     }
223    
224     rminitrd() {
225     [ -n "$verbose" ] && echo "removing initrd $initrdfile"
226     [ -f $initrdfile ] && rm -f $initrdfile
227     }
228    
229     doDepmod() {
230     [ -n "$verbose" ] && echo "running depmod for $version"
231     depmod -ae -F /boot/System.map-$version $version
232     }
233    
234     doRmmoddep() {
235     [ -n "$verbose" ] && echo "removing modules.dep info for $version"
236     [ -d /lib/modules/$version ] && rm -f /lib/modules/$version/modules.*
237     }
238    
239    
240     while [ $# -gt 0 ]; do
241     case $1 in
242     --mkinitrd)
243     initrd="make"
244     ;;
245    
246     --rminitrd)
247     initrd="remove"
248     ;;
249    
250     --initrdfile*)
251     if echo $1 | grep '=' >/dev/null ; then
252     initrdfile=`echo $1 | sed 's/^--initrdfile=//'`
253     else
254     initrdfile=$2
255     shift
256     fi
257     ;;
258    
259     --kernel-args*)
260     if echo $1 | grep '=' >/dev/null ; then
261     kernargs=`echo $1 | sed 's/^--kernel-args=//'`
262     else
263     kernargs=$2
264     shift
265     fi
266     ;;
267    
268     --banner*)
269     if echo $1 | grep '=' >/dev/null ; then
270     banner=`echo $1 | sed 's/^--banner=//'`
271     else
272     banner=$2
273     shift
274     fi
275     ;;
276    
277     --multiboot*)
278     if echo $1 |grep '=' >/dev/null; then
279     mbkernel=`echo $1 | sed 's/^--multiboot=//'`
280     else
281     # can't really support having an optional second arg here
282     # sorry!
283     mbkernel="/boot/xen.gz"
284     fi
285     ;;
286    
287     --mbargs*)
288     if echo $1 |grep '=' >/dev/null; then
289     mbargs=`echo $1 | sed 's/^--mbargs=//'`
290     else
291     mbargs=$2
292     shift
293     fi
294     ;;
295    
296     --depmod)
297     moddep="make"
298     ;;
299    
300     --rmmoddep)
301     moddep="remove"
302     ;;
303    
304     --make-default)
305     makedefault="--make-default"
306     ;;
307    
308     --package)
309     if echo $1 | grep '=' >/dev/null ; then
310     package=`echo $1 | sed 's/^--package=//'`
311     else
312     package=$2
313     shift
314     fi
315     ;;
316    
317     -v)
318     verbose=-v
319     ;;
320    
321     *)
322     if [ -z "$mode" ]; then
323     mode=$1
324     elif [ -z "$version" ]; then
325     version=$1
326     else
327     usage
328     fi
329     ;;
330     esac
331    
332     shift
333     done
334    
335     # make sure the mode is valid
336     if [ "$mode" != "--install" -a "$mode" != "--remove" ] ; then
337     usage
338     fi
339    
340     if [ -z "$version" ]; then
341     usage
342     fi
343    
344     if [ "$mode" != "--install" -a "$makedefault" ]; then
345     usage
346     fi
347    
348     # make sure that /dev/loop exist
349     [[ ! -e /dev/loop ]] && modprobe loop
350    
351     kernelmajor=`echo $kernel | cut -d . -f 1,2`
352    
353     # kernel image for 2.4 is vmlinux
354     if [ $ARCH = 'ppc64' -o $ARCH = 'ppc' ]; then
355     if [ "$kernelmajor" == "2.4" ]; then
356     kernelName=vmlinux
357     fi
358     fi
359    
360    
361     # set the initrd file based on arch; ia64 is the only currently known oddball
362     if [ -z "$initrdfile" ]; then
363     if [ `uname -m` = "ia64" ]; then
364     initrdfile="/boot/efi/EFI/redhat/initrd-$version.img"
365     else
366     initrdfile="/boot/initrd-$version.img"
367     fi
368    
369     fi
370     [ -n "$verbose" ] && echo "initrdfile is $initrdfile"
371    
372     # set this as the default if we have the package and it matches
373     if [ "$mode" == "--install" -a "$UPDATEDEFAULT" == "yes" -a -n "$package" -a -n "$DEFAULTKERNEL" -a "$package" == "$DEFAULTKERNEL" ]; then
374     makedefault="--make-default"
375     [ -n "$verbose" ] && echo "making it the default based on config"
376     fi
377    
378     if [ "$moddep" == "make" ]; then
379     doDepmod
380     elif [ "$moddep" == "remove" ]; then
381     doRmmoddep
382     fi
383    
384     if [ "$initrd" == "make" ]; then
385     mkinitrd
386     elif [ "$initrd" == "remove" ]; then
387     rminitrd
388     fi
389    
390     if [ ! -x $grubby ] ; then
391     [ -n "$verbose" ] && echo "$grubby does not exist"
392     exit 0
393     fi
394    
395    
396     [ -n "$grubConfig" ] && [ -f "$grubConfig" ] && cfgGrub=1;
397     [ -n "$liloConfig" ] && [ -f "$liloConfig" ] && cfgLilo=1;
398    
399     # if we have a lilo config on an x86 box, see if the default boot loader
400     # is lilo to determine if it should be run
401     if [ -n "$cfgLilo" -a -n "$isx86" ]; then
402     runLilo=$($grubby --bootloader-probe | grep lilo)
403     fi
404    
405     if [ "$mode" == "--install" ]; then
406     install
407     elif [ "$mode" == "--remove" ]; then
408     remove
409     fi
410    
411     exit 0

Properties

Name Value
svn:executable *