Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1305 - (hide annotations) (download)
Fri May 27 17:31:15 2011 UTC (13 years, 5 months ago) by niro
Original Path: trunk/mkinitrd-magellan/grubby/new-kernel-pkg
File size: 12412 byte(s)
merged with 7.0.16: upstream commit:  http://git.fedorahosted.org/git?p=grubby.git;a=commit;h=1301a5819fa50b432b6ab0075f36f4019855e860
Add support for grub2 to new-kernel-pkg

http://git.fedorahosted.org/git?p=grubby.git;a=commit;h=da297818977654a680f938a1ccef84f3994a9de0
Make --update capable of adding an initramfs, so that we can use it in  --posttrans from the kernel, and add an entry without the initrd in
 %post.  This way we can build the initrd later than the kernel
 %installation.

and added some minor fixes
1 niro 532 #!/bin/bash
2 niro 924 # $Id$
3 niro 532 #
4 niro 923 # new-kernel-pkg
5 niro 532 # Invoked upon installation or removal of a kernel package, the following
6     # tasks are/can be done here:
7     # creation/removal of initrd
8     # run of depmod/removal of depmod generated files
9     # addition/removal of kernel images from grub/lilo configuration (via grubby)
10     #
11 niro 923 # Copyright 2002-2008 Red Hat, Inc. All rights reserved.
12 niro 532 # modified for Magellan-Linux by Niels Rogalla <niro@magellan-linux.de>
13     #
14 niro 923 # This program is free software; you can redistribute it and/or modify
15     # it under the terms of the GNU General Public License as published by
16     # the Free Software Foundation; either version 2 of the License, or
17     # (at your option) any later version.
18     #
19     # This program is distributed in the hope that it will be useful,
20     # but WITHOUT ANY WARRANTY; without even the implied warranty of
21     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22     # GNU General Public License for more details.
23     #
24     # You should have received a copy of the GNU General Public License
25     # along with this program. If not, see <http://www.gnu.org/licenses/>.
26     #
27 niro 532
28     PATH=/sbin:/bin:$PATH
29    
30     lilo=/sbin/lilo
31    
32     # some defaults that are sane for most arches
33     kernelName=kernel
34    
35 niro 924 if [ -x ./grubby ]
36     then
37     grubby=./grubby
38 niro 532 else
39 niro 924 grubby=/sbin/grubby
40 niro 532 fi
41    
42 niro 925 [ -f /etc/conf.d/grubby ] && . /etc/conf.d/grubby
43 niro 532
44     cfgGrub=""
45     cfgLilo=""
46     runLilo=""
47     grubConfig=""
48    
49     ARCH=$(uname -m)
50    
51 niro 924 if [[ ${ARCH} = ia64 ]]
52     then
53     liloConfig=/boot/efi/EFI/redhat/elilo.conf
54     bootPrefix=/boot/efi/EFI/redhat
55     liloFlag=elilo
56     isx86=""
57     elif [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]]
58     then
59     liloConfig=/etc/yaboot.conf
60     bootPrefix=/boot
61     lilo=/sbin/ybin
62     liloFlag=yaboot
63     runLilo="yes"
64     isx86=""
65     elif [[ ${ARCH} = sparc ]] || [[ ${ARCH} = sparc64 ]]
66     then
67     liloConfig=/etc/silo.conf
68     bootPrefix=/boot
69     liloFlag=silo
70     lilo=/sbin/silo
71     isx86=""
72     elif [[ ${ARCH} = s390 ]] || [[ ${ARCH} = s390x ]]
73     then
74     liloConfig=/etc/zipl.conf
75     bootPrefix=/boot
76     liloFlag=zipl
77     lilo=/sbin/zipl
78     runLilo="yes"
79     isx86=""
80 niro 532 else
81 niro 924 # this leaves i?86 and x86_64
82     liloConfig=/etc/lilo.conf
83     grubConfig=/boot/grub/grub.conf
84     bootPrefix=/boot
85     liloFlag=lilo
86     isx86="yes"
87 niro 532 fi
88    
89     mode=""
90     version=""
91     initrd=""
92     initrdfile=""
93     moddep=""
94     verbose=""
95     makedefault=""
96     package=""
97     mbkernel=""
98     mbargs=""
99    
100 niro 924 usage()
101     {
102     echo "Usage: $(basename $0) [-v] [--mkinitrd] [--rminitrd]" >&2
103     echo " [--initrdfile=<initrd-image>] [--depmod] [--rmmoddep]" >&2
104 niro 1305 echo " [--kernel-args=<args>] [--remove-args=<args>]" >&2
105 niro 924 echo " [--banner=<banner>] [--multiboot=multiboot]" >&2
106     echo " [--mbargs=mbargs] [--make-default]" >&2
107     echo " <--install | --remove | --update> <kernel-version>" >&2
108     echo " (ex: $(basename $0) --mkinitrd --depmod --install 2.4.7-2)" >&2
109     exit 1
110 niro 532 }
111    
112 niro 1305 run_grub2()
113     {
114     if [ -d /boot/grub2 -a -x /sbin/grub2-mkconfig ]
115     then
116     cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.old
117     /sbin/grub2-mkconfig -o /boot/grub2/grub.cfg
118     fi
119     }
120    
121 niro 924 install()
122     {
123     # XXX kernel should be able to be specified also (or work right on ia64)
124     if [ ! -f ${bootPrefix}/${kernelName}-${version} ]
125     then
126     [[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby"
127     return
128     fi
129 niro 923
130 niro 924 INITRD=""
131     if [ -f ${initrdfile} ]
132     then
133     [[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby"
134     INITRD="--initrd ${initrdfile}"
135     fi
136 niro 532
137 niro 924 # FIXME: is this a good heuristic to find out if we're on iSeries?
138     if [ -d /proc/iSeries ]
139     then
140     [[ -n ${verbose} ]] && echo "On an iSeries, just making img file"
141     if [[ -z ${initrdfile} ]]
142     then
143     [[ -n ${verbose} ]] && echo "No initrd, just adding system map"
144     /sbin/addSystemMap ${bootPrefix}/System.map-${version} ${bootPrefix}/${kernelName}-${version} ${bootPrefix}/vmlinitrd-${version}
145     else
146     /sbin/addSystemMap ${bootPrefix}/System.map-${version} ${bootPrefix}/${kernelName}-${version} ${bootPrefix}/vmlinux.sm-${version}
147     /sbin/addRamDisk ${initrdfile} ${bootPrefix}/System.map-${version} ${bootPrefix}/vmlinux.sm-${version} ${bootPrefix}/vmlinitrd-${version} 2>/dev/null
148     rm ${bootPrefix}/vmlinux.sm-${version}
149     fi
150     return
151 niro 532 fi
152    
153 niro 1305 # Run grub2's configuration update in parallel, if it is installed
154     run_grub2
155    
156 niro 924 # get the root filesystem to use
157     rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab)
158 niro 532
159 niro 924 if [[ -n ${mbkernel} ]] && [[ -n ${cfgLilo} ]] && [[ ${liloFlag} != elilo ]]
160     then
161     [[ -n ${verbose} ]] && echo "multiboot specified, not updating lilo.conf"
162     cfgLilo=""
163     fi
164 niro 532
165 niro 924 if [[ -n ${cfgGrub} ]]
166     then
167     [[ -n ${verbose} ]] && echo "adding ${version} to ${grubConfig}"
168 niro 532
169 niro 924 if [[ -n ${banner} ]]
170     then
171     title="${banner} (${version})"
172     elif [ -f /etc/mageversion ]
173     then
174     title="Magellan Linux $(< /etc/mageversion) (${version})"
175     else
176     title="Magellan Linux (${version})"
177     fi
178     ${grubby} --add-kernel=${bootPrefix}/${kernelName}-${version} \
179     ${INITRD} --copy-default ${makedefault} --title "${title}" \
180     ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \
181     --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
182 niro 532 else
183 niro 924 [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"
184 niro 532 fi
185    
186 niro 924 if [[ -n ${cfgLilo} ]]
187     then
188     [[ -n ${verbose} ]] && echo "adding ${version} to ${liloConfig}"
189 niro 532
190 niro 924 ${grubby} --add-kernel=${bootPrefix}/${kernelName}-${version} ${INITRD} \
191     --copy-default ${makedefault} --title ${version} \
192     ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \
193     --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${version}" \
194     --${liloFlag}
195 niro 532
196 niro 924 if [[ -n ${runLilo} ]]
197     then
198     [[ -n ${verbose} ]] && echo "running ${lilo}"
199 niro 1305 if [ ! -x ${lilo} ]
200 niro 924 then
201     [[ -n ${verbose} ]] && echo "${lilo} does not exist"
202     else
203     ${lilo} > /dev/null
204     fi
205     fi
206     else
207     [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
208 niro 532 fi
209     }
210    
211 niro 924 remove()
212     {
213     # FIXME: is this a good heuristic to find out if we're on iSeries?
214     if [ -d /proc/iSeries ]
215     then
216     [[ -n ${verbose} ]] && echo "On an iSeries, remove img file"
217     rm -f ${bootPrefix}/${kernelName}-${version}.img 2>/dev/null
218     return
219     fi
220 niro 532
221 niro 1305 # Run grub2's configuration update in parallel, if it is installed
222     run_grub2
223    
224 niro 924 if [[ -n ${cfgGrub} ]]
225     then
226     [[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}"
227     ${grubby} --remove-kernel=${bootPrefix}/${kernelName}-${version}
228     else
229     [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"
230     fi
231 niro 532
232 niro 924 if [[ -n ${cfgLilo} ]]
233     then
234     [[ -n ${verbose} ]] && echo "removing ${version} from ${liloConfig}"
235 niro 1305 ${grubby} --remove-kernel=${bootPrefix}/${kernelName}-${version} --${liloFlag}
236 niro 532
237 niro 924 if [[ -n ${runLilo} ]]
238     then
239     [[ -n ${verbose} ]] && echo "running ${lilo}"
240     if [ ! -x ${lilo} ]
241     then
242     [[ -n ${verbose} ]] && echo "${lilo} does not exist"
243     else
244     ${lilo} > /dev/null
245     fi
246     fi
247     else
248     [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
249 niro 532 fi
250     }
251    
252 niro 924 update()
253     {
254 niro 1305 if [ ! -f ${bootPrefix}/${kernelName}-${version} ]
255     then
256     [[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby"
257     return
258     fi
259    
260     INITRD=""
261     if [ -f ${initrdfile} ]
262     then
263     [[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby"
264     INITRD="--initrd ${initrdfile}"
265     fi
266    
267     # Run grub2's configuration update in parallel, if it is installed
268     run_grub2
269    
270 niro 924 if [[ -n ${cfgGrub} ]]
271     then
272     [[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}"
273     ${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \
274 niro 1305 ${INITRD} \
275 niro 924 ${kernargs:+--args="${kernargs}"} \
276     ${removeargs:+--remove-args="${removeargs}"}
277     else
278     [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"
279     fi
280 niro 923
281 niro 924 if [[ -n ${cfgLilo} ]]
282     then
283     [[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}"
284     ${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \
285 niro 1305 ${INITRD} \
286 niro 924 ${kernargs:+--args="${kernargs}"} \
287     ${removeargs:+--remove-args="${removeargs}"} \
288     --${liloFlag}
289 niro 923
290 niro 924 if [[ -n ${runLilo} ]]
291     then
292     [[ -n ${verbose} ]] && echo "running ${lilo}"
293     if [ ! -x ${lilo} ]
294     then
295     [[ -n ${verbose} ]] && echo "${lilo} does not exist"
296     else
297     ${lilo} > /dev/null
298     fi
299     fi
300     else
301     [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
302 niro 923 fi
303     }
304    
305 niro 924 mkinitrd()
306     {
307     [[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}"
308     /sbin/mkinitrd --allow-missing -f ${initrdfile} ${version}
309     rc=$?
310     if [ ${rc} != 0 ]
311     then
312     echo "mkinitrd failed" >&2
313     exit 1
314     fi
315 niro 532 }
316    
317 niro 924 rminitrd()
318     {
319     [[ -n ${verbose} ]] && echo "removing initrd ${initrdfile}"
320     [ -f ${initrdfile} ] && rm -f ${initrdfile}
321 niro 532 }
322    
323 niro 924 doDepmod()
324     {
325     [[ -n ${verbose} ]] && echo "running depmod for ${version}"
326     depmod -ae -F /boot/System.map-${version} ${version}
327 niro 532 }
328    
329 niro 924 doRmmoddep()
330     {
331     [[ -n ${verbose} ]] && echo "removing modules.dep info for ${version}"
332     [ -d /lib/modules/${version} ] && rm -f /lib/modules/${version}/modules.*
333 niro 532 }
334    
335    
336 niro 924 while [ $# -gt 0 ]
337     do
338     case $1 in
339     --mkinitrd)
340     initrd="make"
341     ;;
342 niro 532
343 niro 924 --rminitrd)
344     initrd="remove"
345     ;;
346 niro 532
347 niro 924 --initrdfile*)
348     if echo $1 | grep '=' >/dev/null
349     then
350     initrdfile=$(echo $1 | sed 's/^--initrdfile=//')
351     else
352     initrdfile=$2
353     shift
354     fi
355     ;;
356 niro 532
357 niro 924 --kernel-args*)
358     if echo $1 | grep '=' >/dev/null
359     then
360     kernargs=$(echo $1 | sed 's/^--kernel-args=//')
361     else
362     kernargs=$2
363     shift
364     fi
365     ;;
366 niro 532
367 niro 924 --remove-args*)
368     if echo $1 | grep '=' >/dev/null
369     then
370 niro 1305 removeargs=$(echo $1 | sed 's/^--remove-args=//')
371 niro 924 else
372     removeargs=$2
373     shift
374     fi
375     ;;
376 niro 923
377 niro 924 --banner*)
378     if echo $1 | grep '=' >/dev/null
379     then
380     banner=$(echo $1 | sed 's/^--banner=//')
381     else
382     banner=$2
383     shift
384     fi
385     ;;
386 niro 532
387 niro 924 --multiboot*)
388     if echo $1 |grep '=' >/dev/null
389     then
390     mbkernel=$(echo $1 | sed 's/^--multiboot=//')
391     else
392     # can't really support having an optional second arg here
393     # sorry!
394     mbkernel="/boot/xen.gz"
395     fi
396     ;;
397 niro 532
398 niro 924 --mbargs*)
399     if echo $1 |grep '=' >/dev/null
400     then
401     mbargs=$(echo $1 | sed 's/^--mbargs=//')
402     else
403     mbargs="$2"
404     shift
405     fi
406     ;;
407 niro 532
408 niro 924 --depmod)
409     moddep="make"
410     ;;
411 niro 532
412 niro 924 --rmmoddep)
413     moddep="remove"
414     ;;
415 niro 532
416 niro 924 --make-default)
417     makedefault="--make-default"
418     ;;
419 niro 532
420 niro 924 --package)
421     if echo $1 | grep '=' >/dev/null
422     then
423     package=$(echo $1 | sed 's/^--package=//')
424     else
425     package=$2
426     shift
427     fi
428     ;;
429 niro 532
430 niro 924 -v)
431     verbose=-v
432     ;;
433 niro 532
434 niro 924 *)
435     if [[ -z ${mode} ]]
436     then
437     mode=$1
438     elif [[ -z ${version} ]]
439     then
440     version=$1
441     else
442     usage
443     fi
444     ;;
445     esac
446 niro 532
447 niro 924 shift
448 niro 532 done
449    
450     # make sure the mode is valid
451 niro 924 if [[ ${mode} != --install ]] && [[ ${mode} != --remove ]] && [[ ${mode} != --update ]]
452     then
453     usage
454 niro 532 fi
455    
456 niro 924 if [[ -z ${version} ]]
457     then
458     usage
459 niro 532 fi
460    
461 niro 924 if [ "${mode}" != "--install" -a "${makedefault}" ]
462     then
463     usage
464 niro 532 fi
465    
466 niro 924 kernelmajor=$(echo ${kernel} | cut -d . -f 1,2)
467 niro 532
468 niro 1305 # kernel image for 2.4 is kernel
469 niro 924 if [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]]
470     then
471     if [[ ${kernelmajor} = 2.4 ]]
472     then
473     kernelName=kernel
474     fi
475 niro 532 fi
476    
477     # set the initrd file based on arch; ia64 is the only currently known oddball
478 niro 924 if [[ -z ${initrdfile} ]]
479     then
480     INITRD_NAME_PREFIX="initrd"
481 niro 923
482 niro 924 if [[ $(uname -m) = ia64 ]]
483     then
484     initrdfile="/boot/efi/EFI/redhat/${INITRD_NAME_PREFIX}-${version}.img"
485     else
486     initrdfile="/boot/${INITRD_NAME_PREFIX}-${version}.img"
487     fi
488 niro 532 fi
489 niro 924 [[ -n ${verbose} ]] && echo "initrdfile is ${initrdfile}"
490 niro 532
491     # set this as the default if we have the package and it matches
492 niro 924 if [[ ${mode} = --install ]] && [[ ${UPDATEDEFAULT} = yes ]] && [[ -n ${package} ]] &&
493     [[ -n ${DEFAULTKERNEL} ]] && [[ ${package} = ${DEFAULTKERNEL} ]]
494     then
495     makedefault="--make-default"
496     [[ -n ${verbose} ]] && echo "making it the default based on config"
497 niro 532 fi
498    
499 niro 924 if [[ ${moddep} = make ]]
500     then
501     doDepmod
502     elif [[ ${moddep} = remove ]]
503     then
504     doRmmoddep
505 niro 532 fi
506    
507 niro 924 if [[ ${initrd} = make ]]
508     then
509     mkinitrd
510     elif [[ ${initrd} = remove ]]
511     then
512     rminitrd
513 niro 532 fi
514    
515 niro 924 if [ ! -x ${grubby} ]
516     then
517     [[ -n ${verbose} ]] && echo "${grubby} does not exist"
518     exit 0
519 niro 532 fi
520    
521 niro 924 [[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1
522     [[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1
523 niro 532
524     # if we have a lilo config on an x86 box, see if the default boot loader
525     # is lilo to determine if it should be run
526 niro 924 if [[ -n ${cfgLilo} ]] && [[ -n ${isx86} ]]
527     then
528     runLilo=$(${grubby} --bootloader-probe | grep lilo)
529 niro 532 fi
530    
531 niro 924 if [[ ${mode} = --install ]]
532     then
533     install
534     elif [[ ${mode} = --remove ]]
535     then
536     remove
537     elif [[ ${mode} = --update ]]
538     then
539     update
540 niro 532 fi
541    
542     exit 0

Properties

Name Value
svn:executable *