Magellan Linux

Annotation of /tags/grubby-8_40_20170706/new-kernel-pkg

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1756 - (hide annotations) (download)
Sat Feb 18 11:05:14 2012 UTC (12 years, 2 months ago) by niro
Original Path: trunk/grubby/new-kernel-pkg
File size: 22456 byte(s)
-fix a infinite loop caused by dropping the path prefix of mkinitrd
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 1691 [ -f /etc/conf.d/grubby-uboot ] && . /etc/conf.d/grubby-uboot
44 niro 532
45 niro 1697 cfgGrub2=""
46     cfgGrub2Efi=""
47 niro 532 cfgGrub=""
48     cfgLilo=""
49 niro 1716 cfgExtlinux=""
50 niro 1691 cfguBoot=""
51 niro 532 runLilo=""
52     grubConfig=""
53 niro 1702 grub2Config=""
54     grub2EfiConfig=""
55 niro 1716 extlinuxConfig=""
56 niro 532
57     ARCH=$(uname -m)
58    
59 niro 924 if [[ ${ARCH} = ia64 ]]
60     then
61     liloConfig=/boot/efi/EFI/redhat/elilo.conf
62     bootPrefix=/boot/efi/EFI/redhat
63     liloFlag=elilo
64     isx86=""
65     elif [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]]
66     then
67     liloConfig=/etc/yaboot.conf
68     bootPrefix=/boot
69     lilo=/sbin/ybin
70     liloFlag=yaboot
71     runLilo="yes"
72     isx86=""
73     elif [[ ${ARCH} = sparc ]] || [[ ${ARCH} = sparc64 ]]
74     then
75     liloConfig=/etc/silo.conf
76     bootPrefix=/boot
77     liloFlag=silo
78     lilo=/sbin/silo
79     isx86=""
80     elif [[ ${ARCH} = s390 ]] || [[ ${ARCH} = s390x ]]
81     then
82     liloConfig=/etc/zipl.conf
83     bootPrefix=/boot
84     liloFlag=zipl
85     lilo=/sbin/zipl
86     runLilo="yes"
87     isx86=""
88 niro 1752 elif [[ ${ARCH} = armv7l ]] || [[ ${ARCH} = armv7hl ]]
89 niro 1691 then
90 niro 1752 machine=$(grep "^Hardware" /proc/cpuinfo | sed 's/Hardware\s*:\s*//')
91 niro 1691 liloConfig=""
92     bootPrefix=/boot
93     ubootDir=${UBOOT_DIR:-"/boot/uboot"}
94     ubootScript=$ubootDir/${UBOOT_SCR:-"boot.scr"}
95     ubootKList=${UBOOT_KLIST:-"klist.txt"}
96     ubootDevice=/dev/${UBOOT_DEVICE:-"mmcblk0p1"}
97     ubootDefaultImage=${UBOOT_UIMAGE:-"uImage"}
98     ubootDefaultInitrd=${UBOOT_UINITRD:-"uInitrd"}
99     mounted=""
100     liloFlag=""
101     isx86=""
102 niro 1752 if [[ ${machine} == "OMAP3 Beagle Board" ]] || [[ ${machine} == "OMAP4 Panda board" ]]
103     then
104     ubootAddress=0x80008000
105     else
106     ubootAddress=0x00008000
107     fi
108 niro 532 else
109 niro 924 # this leaves i?86 and x86_64
110     liloConfig=/etc/lilo.conf
111     grubConfig=/boot/grub/grub.conf
112 niro 1697 grub2Config=/boot/grub/grub.cfg
113     grub2EfiConfig=/boot/grub/grub-efi.cfg
114 niro 1716 extlinuxConfig=/boot/extlinux/extlinux.conf
115 niro 924 bootPrefix=/boot
116     liloFlag=lilo
117     isx86="yes"
118 niro 532 fi
119    
120     mode=""
121     version=""
122     initrd=""
123 niro 1334 dracut=""
124     dracuthostonly=""
125 niro 532 initrdfile=""
126     moddep=""
127     verbose=""
128     makedefault=""
129     package=""
130 niro 1706 mbkernel="${HYPERVISOR}"
131     mbargs="${HYPERVISOR_ARGS}"
132 niro 1334 adddracutargs=""
133     addplymouthinitrd=""
134 niro 532
135 niro 924 usage()
136     {
137 niro 1334 echo "Usage: $(basename $0) [-v] [--mkinitrd] [--rminitrd] [--dracut]" >&2
138 niro 924 echo " [--initrdfile=<initrd-image>] [--depmod] [--rmmoddep]" >&2
139 niro 1305 echo " [--kernel-args=<args>] [--remove-args=<args>]" >&2
140 niro 924 echo " [--banner=<banner>] [--multiboot=multiboot]" >&2
141 niro 1334 echo " [--mbargs=mbargs] [--make-default] [--add-dracut-args]" >&2
142     echo " [--add-plymouth-initrd]" >&2
143     echo " [--host-only]" >&2
144 niro 924 echo " <--install | --remove | --update> <kernel-version>" >&2
145     echo " (ex: $(basename $0) --mkinitrd --depmod --install 2.4.7-2)" >&2
146     exit 1
147 niro 532 }
148    
149 niro 924 install()
150     {
151     # XXX kernel should be able to be specified also (or work right on ia64)
152     if [ ! -f ${bootPrefix}/${kernelName}-${version} ]
153     then
154     [[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby"
155     return
156     fi
157 niro 923
158 niro 924 INITRD=""
159     if [ -f ${initrdfile} ]
160     then
161     [[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby"
162     INITRD="--initrd ${initrdfile}"
163 niro 1334
164     if [[ -n ${addplymouthinitrd} ]]
165     then
166     INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img"
167     fi
168 niro 924 fi
169 niro 532
170 niro 924 # FIXME: is this a good heuristic to find out if we're on iSeries?
171     if [ -d /proc/iSeries ]
172     then
173     [[ -n ${verbose} ]] && echo "On an iSeries, just making img file"
174     if [[ -z ${initrdfile} ]]
175     then
176     [[ -n ${verbose} ]] && echo "No initrd, just adding system map"
177     /sbin/addSystemMap ${bootPrefix}/System.map-${version} ${bootPrefix}/${kernelName}-${version} ${bootPrefix}/vmlinitrd-${version}
178     else
179     /sbin/addSystemMap ${bootPrefix}/System.map-${version} ${bootPrefix}/${kernelName}-${version} ${bootPrefix}/vmlinux.sm-${version}
180     /sbin/addRamDisk ${initrdfile} ${bootPrefix}/System.map-${version} ${bootPrefix}/vmlinux.sm-${version} ${bootPrefix}/vmlinitrd-${version} 2>/dev/null
181     rm ${bootPrefix}/vmlinux.sm-${version}
182     fi
183     return
184 niro 532 fi
185    
186 niro 924 # get the root filesystem to use
187     rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab)
188 niro 532
189 niro 924 if [[ -n ${mbkernel} ]] && [[ -n ${cfgLilo} ]] && [[ ${liloFlag} != elilo ]]
190     then
191     [[ -n ${verbose} ]] && echo "multiboot specified, not updating lilo.conf"
192     cfgLilo=""
193     fi
194 niro 532
195 niro 924 if [[ -n ${cfgGrub} ]]
196     then
197     [[ -n ${verbose} ]] && echo "adding ${version} to ${grubConfig}"
198 niro 532
199 niro 924 if [[ -n ${banner} ]]
200     then
201     title="${banner} (${version})"
202     elif [ -f /etc/mageversion ]
203     then
204     title="Magellan Linux $(< /etc/mageversion) (${version})"
205     else
206     title="Magellan Linux (${version})"
207     fi
208 niro 1710 ${grubby} --grub -c ${grubConfig} \
209     --add-kernel=${bootPrefix}/${kernelName}-${version} \
210 niro 924 ${INITRD} --copy-default ${makedefault} --title "${title}" \
211     ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \
212     --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
213 niro 532 else
214 niro 1697 [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97"
215 niro 532 fi
216 niro 1697 if [[ -n ${cfgGrub2} ]]
217     then
218     [[ -n ${verbose} ]] && echo "adding ${version} to ${grub2Config}"
219 niro 532
220 niro 1697 if [[ -n ${banner} ]]
221     then
222     title="${banner} (${version})"
223     elif [ -f /etc/mageversion ]
224     then
225     title="Magellan Linux $(< /etc/mageversion) (${version})"
226     else
227     title="Magellan Linux (${version})"
228     fi
229 niro 1702 ${grubby} --grub2 -c ${grub2Config} \
230 niro 1697 --add-kernel=${bootPrefix}/${kernelName}-${version} \
231     ${INITRD} --copy-default ${makedefault} --title "${title}" \
232     ${mbkernel:+--add-multiboot="${mbkernel}"} \
233     ${mbargs:+--mbargs="${mbargs}"} \
234     --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
235     else
236     [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby for grub 2"
237     fi
238     if [[ -n ${cfgGrub2Efi} ]]
239     then
240     [[ -n ${verbose} ]] && echo "adding ${version} to ${grub2EfiConfig}"
241    
242     if [[ -n ${banner} ]]
243     then
244     title="${banner} (${version})"
245     elif [ -f /etc/mageversion ]
246     then
247     title="Magellan Linux $(< /etc/mageversion) (${version})"
248     else
249     title="Magellan Linux (${version})"
250     fi
251 niro 1702 ${grubby} --grub2 -c ${grub2EfiConfig} \
252 niro 1697 --add-kernel=${bootPrefix}/${kernelName}-${version} \
253     ${INITRD} --copy-default ${makedefault} --title "${title}" \
254     ${mbkernel:+--add-multiboot="${mbkernel}"} \
255     ${mbargs:+--mbargs="${mbargs}"} \
256     --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
257     else
258     [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby for grub 2 with UEFI"
259     fi
260    
261 niro 924 if [[ -n ${cfgLilo} ]]
262     then
263     [[ -n ${verbose} ]] && echo "adding ${version} to ${liloConfig}"
264 niro 532
265 niro 924 ${grubby} --add-kernel=${bootPrefix}/${kernelName}-${version} ${INITRD} \
266     --copy-default ${makedefault} --title ${version} \
267     ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \
268     --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${version}" \
269     --${liloFlag}
270 niro 532
271 niro 924 if [[ -n ${runLilo} ]]
272     then
273     [[ -n ${verbose} ]] && echo "running ${lilo}"
274 niro 1305 if [ ! -x ${lilo} ]
275 niro 924 then
276     [[ -n ${verbose} ]] && echo "${lilo} does not exist"
277     else
278     ${lilo} > /dev/null
279     fi
280     fi
281     else
282     [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
283 niro 532 fi
284 niro 1716
285     if [[ -n ${cfgExtlinux} ]]
286     then
287     [[ -n ${verbose} ]] && echo "adding ${version} to ${extlinuxConfig}"
288    
289     if [[ -n ${banner} ]]
290     then
291     title="${banner} (${version})"
292     elif [ -f /etc/mageversion ]
293     then
294     title="Magellan Linux $(< /etc/mageversion) (${version})"
295     else
296     title="Magellan Linux (${version})"
297     fi
298     ${grubby} --extlinux -c ${extlinuxConfig} \
299     --add-kernel=${bootPrefix}/${kernelName}-${version} \
300     ${INITRD} --copy-default ${makedefault} --title "${title}" \
301     ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \
302     --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
303     else
304     [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux"
305     fi
306 niro 532 }
307    
308 niro 924 remove()
309     {
310     # FIXME: is this a good heuristic to find out if we're on iSeries?
311     if [ -d /proc/iSeries ]
312     then
313     [[ -n ${verbose} ]] && echo "On an iSeries, remove img file"
314     rm -f ${bootPrefix}/${kernelName}-${version}.img 2>/dev/null
315     return
316     fi
317 niro 532
318 niro 924 if [[ -n ${cfgGrub} ]]
319     then
320     [[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}"
321 niro 1710 ${grubby} --grub -c ${grubConfig} \
322     --remove-kernel=${bootPrefix}/${kernelName}-${version}
323 niro 924 else
324 niro 1697 [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97"
325 niro 924 fi
326 niro 1697 if [[ -n ${cfgGrub2} ]]
327     then
328     [[ -n ${verbose} ]] && echo "removing ${version} from ${grub2Config}"
329     ${grubby} --grub2 -c ${grub2Config} \
330     --remove-kernel=${bootPrefix}/${kernelName}-${version}
331     else
332     [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby for grub 2"
333     fi
334     if [[ -n ${cfgGrub2Efi} ]]
335     then
336     [[ -n ${verbose} ]] && echo "removing ${version} from ${grub2EfiConfig}"
337     ${grubby} --grub2 -c ${grub2EfiConfig} \
338     --remove-kernel=${bootPrefix}/${kernelName}-${version}
339     else
340     [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby grub 2 with UEFI"
341     fi
342 niro 532
343 niro 924 if [[ -n ${cfgLilo} ]]
344     then
345     [[ -n ${verbose} ]] && echo "removing ${version} from ${liloConfig}"
346 niro 1305 ${grubby} --remove-kernel=${bootPrefix}/${kernelName}-${version} --${liloFlag}
347 niro 532
348 niro 924 if [[ -n ${runLilo} ]]
349     then
350     [[ -n ${verbose} ]] && echo "running ${lilo}"
351     if [ ! -x ${lilo} ]
352     then
353     [[ -n ${verbose} ]] && echo "${lilo} does not exist"
354     else
355     ${lilo} > /dev/null
356     fi
357     fi
358     else
359     [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
360 niro 532 fi
361 niro 1691
362     if [[ -n ${cfguBoot} ]]
363     then
364     [[ -n ${verbose} ]] && echo "removing ${version} from ${ubootDir}..."
365    
366     if [ -f ${ubootDir}/${ubootKList} ]
367     then
368     tmpKList=$(mktemp ${ubootDir}/${ubootKList}.XXXX)
369     curversion=$(tail -n1 ${ubootDir}/${ubootKList})
370     sed "/${version}/d" ${ubootDir}/${ubootKList} > ${tmpKList}
371     newversion=$(tail -n1 ${tmpKList})
372     if [ -f ${ubootDir}/uImage-${newversion} ] && [ -f ${ubootDir}/uInitrd-${newversion} ]
373     then
374     if [[ ${curversion} != ${newversion} ]]
375     then
376     cp -fp ${ubootDir}/uImage-${newversion} ${ubootDir}/${ubootDefaultImage}
377     if [ $? -ne 0 ]
378     then
379     [[ -n ${verbose} ]] && echo "copy uImage-${newversion} error, default kernel not replaced!" && exit
380     fi
381     cp -fp ${ubootDir}/uInitrd-${newversion} ${ubootDir}/${ubootDefaultInitrd}
382     if [ $? -ne 0 ]
383     then
384     [[ -n ${verbose} ]] && echo "copy uInitrd-${newversion} error, default Initrd not replaced!" && exit
385     fi
386     fi
387    
388     [[ -n ${verbose} ]] && echo "removing uImage-${version}"
389     if [ -f ${ubootDir}/uImage-${version} ]
390     then
391     rm -f ${ubootDir}/uImage-${version}
392     else
393     [[ -n ${verbose} ]] && echo "uImage-${version} did not exist!"
394     fi
395    
396     [[ -n ${verbose} ]] && echo "removing uInitrd-${version}"
397     if [ -f ${ubootDir}/uInitrd-${version} ]
398     then
399     rm -f ${ubootDir}/uInitrd-${version}
400     else
401     [[ -n ${verbose} ]] && echo "uInitrd-${version} did not exist!"
402     fi
403    
404     mv ${tmpKList} ${ubootDir}/${ubootKList}
405     else
406     [[ -n ${verbose} ]] && echo "uImage ${newversion} does not exist!"
407     [ -f ${tmpKList} ] && rm -f ${tmpKList}
408     fi
409     else
410 niro 1752 [[ -n ${verbose} ]] && echo "No previous kernel version. U-Boot images not removed!"
411 niro 1691 fi
412     else
413     [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}"
414     fi
415 niro 1716
416     if [[ -n ${cfgExtlinux} ]]
417     then
418     [[ -n ${verbose} ]] && echo "removing ${version} from ${extlinuxConfig}"
419     ${grubby} --extlinux -c ${extlinuxConfig} \
420     --remove-kernel=${bootPrefix}/${kernelName}-${version}
421     else
422     [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux"
423     fi
424 niro 532 }
425    
426 niro 924 update()
427     {
428 niro 1305 if [ ! -f ${bootPrefix}/${kernelName}-${version} ]
429     then
430     [[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby"
431     return
432     fi
433    
434     INITRD=""
435     if [ -f ${initrdfile} ]
436     then
437     [[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby"
438     INITRD="--initrd ${initrdfile}"
439 niro 1334
440     if [[ -n ${addplymouthinitrd} ]]
441     then
442     INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img"
443     fi
444 niro 1305 fi
445    
446 niro 924 if [[ -n ${cfgGrub} ]]
447     then
448     [[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}"
449 niro 1710 ${grubby} --grub -c ${grubConfig} \
450     --update-kernel=${bootPrefix}/${kernelName}-${version} \
451 niro 1305 ${INITRD} \
452 niro 924 ${kernargs:+--args="${kernargs}"} \
453     ${removeargs:+--remove-args="${removeargs}"}
454     else
455     [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"
456     fi
457 niro 923
458 niro 1697 if [[ -n ${cfgGrub2} ]]
459     then
460     [[ -n ${verbose} ]] && echo "updating ${version} from ${grub2Config}"
461     ${grubby} --grub2 -c ${grub2Config} \
462     --update-kernel=${bootPrefix}/${kernelName}-${version} \
463     ${INITRD} \
464     ${kernargs:+--args="${kernargs}"} \
465     ${removeargs:+--remove-args="${removeargs}"}
466     else
467     [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby"
468     fi
469    
470     if [[ -n ${cfgGrub2Efi} ]]
471     then
472     [[ -n ${verbose} ]] && echo "updating ${version} from ${grub2EfiConfig}"
473     ${grubby} --grub2 -c ${grub2EfiConfig} \
474     --update-kernel=${bootPrefix}/${kernelName}-${version} \
475     ${INITRD} \
476     ${kernargs:+--args="${kernargs}"} \
477     ${removeargs:+--remove-args="${removeargs}"}
478     else
479     [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby"
480     fi
481    
482 niro 924 if [[ -n ${cfgLilo} ]]
483     then
484     [[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}"
485     ${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \
486 niro 1305 ${INITRD} \
487 niro 924 ${kernargs:+--args="${kernargs}"} \
488     ${removeargs:+--remove-args="${removeargs}"} \
489     --${liloFlag}
490 niro 923
491 niro 924 if [[ -n ${runLilo} ]]
492     then
493     [[ -n ${verbose} ]] && echo "running ${lilo}"
494     if [ ! -x ${lilo} ]
495     then
496     [[ -n ${verbose} ]] && echo "${lilo} does not exist"
497     else
498     ${lilo} > /dev/null
499     fi
500     fi
501     else
502     [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
503 niro 923 fi
504 niro 1691
505     if [[ -n ${cfguBoot} ]]
506     then
507     [[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..."
508    
509     [[ -n ${verbose} ]] && echo "creating uImage-${version}"
510 niro 1752 mkimage -A arm -O linux -T kernel -C none -a ${ubootAddress} \
511     -e ${ubootAddress} -n ${version} \
512     -d ${bootPrefix}/${kernelName}-${version} ${ubootDir}/uImage-${version}
513 niro 1691
514     [[ -n ${verbose} ]] && echo "creating uInitrd-${version}"
515     mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 \
516     -n initramfs -d ${initrdfile} ${ubootDir}/uInitrd-${version}
517    
518     if [ -f ${ubootDir}/uImage-${version} ] && [ -f ${ubootDir}/uInitrd-${version} ]
519     then
520     cp -fp ${ubootDir}/uImage-${version} ${ubootDir}/${ubootDefaultImage}
521     if [ $? -ne 0 ]
522     then
523     [[ -n ${verbose} ]] && echo "copy uImage-${version} error, kernel not installed!" && exit
524     fi
525     cp -fp ${ubootDir}/uInitrd-${version} ${ubootDir}/${ubootDefaultInitrd}
526     if [ $? -ne 0 ]
527     then
528     [[ -n ${verbose} ]] && echo "copy uInitrd-${version} error, kernel not installed!" && exit
529     fi
530     echo ${version} >> ${ubootDir}/${ubootKList}
531     else
532     [[ -n ${verbose} ]] && echo "cannot make ${version} the default"
533     fi
534     else
535     [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not setting up ${ubootDir}"
536     fi
537 niro 1716
538     if [[ -n ${cfgExtlinux} ]]
539     then
540     [[ -n ${verbose} ]] && echo "updating ${version} from ${extlinuxConfig}"
541     ${grubby} --extlinux -c ${extlinuxConfig} \
542     --update-kernel=${bootPrefix}/${kernelName}-${version} \
543     ${INITRD} \
544     ${kernargs:+--args="${kernargs}"} \
545     ${removeargs:+--remove-args="${removeargs}"}
546     else
547     [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby"
548     fi
549 niro 923 }
550    
551 niro 1756 makeinitrd()
552 niro 924 {
553 niro 1334 if [[ -n ${dracut} ]]
554     then
555 niro 1728 tool="dracut ${dracuthostonly} -f ${initrdfile} ${version}"
556 niro 1334 else
557 niro 1749 tool="mkinitrd --allow-missing -f ${initrdfile} ${version}"
558 niro 1334 fi
559 niro 924 [[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}"
560 niro 1334 ${tool}
561 niro 924 rc=$?
562     if [ ${rc} != 0 ]
563     then
564     echo "mkinitrd failed" >&2
565     exit 1
566     fi
567 niro 532 }
568    
569 niro 924 rminitrd()
570     {
571     [[ -n ${verbose} ]] && echo "removing initrd ${initrdfile}"
572     [ -f ${initrdfile} ] && rm -f ${initrdfile}
573 niro 532 }
574    
575 niro 924 doDepmod()
576     {
577     [[ -n ${verbose} ]] && echo "running depmod for ${version}"
578     depmod -ae -F /boot/System.map-${version} ${version}
579 niro 532 }
580    
581 niro 924 doRmmoddep()
582     {
583     [[ -n ${verbose} ]] && echo "removing modules.dep info for ${version}"
584     [ -d /lib/modules/${version} ] && rm -f /lib/modules/${version}/modules.*
585 niro 532 }
586    
587    
588 niro 924 while [ $# -gt 0 ]
589     do
590     case $1 in
591     --mkinitrd)
592     initrd="make"
593     ;;
594 niro 532
595 niro 924 --rminitrd)
596     initrd="remove"
597     ;;
598 niro 532
599 niro 1334 --dracut)
600     dracut=--dracut
601     ;;
602    
603     --host-only)
604     dracuthostonly=-H
605     ;;
606    
607 niro 924 --initrdfile*)
608     if echo $1 | grep '=' >/dev/null
609     then
610     initrdfile=$(echo $1 | sed 's/^--initrdfile=//')
611     else
612     initrdfile=$2
613     shift
614     fi
615     ;;
616 niro 532
617 niro 924 --kernel-args*)
618     if echo $1 | grep '=' >/dev/null
619     then
620     kernargs=$(echo $1 | sed 's/^--kernel-args=//')
621     else
622     kernargs=$2
623     shift
624     fi
625     ;;
626 niro 532
627 niro 924 --remove-args*)
628     if echo $1 | grep '=' >/dev/null
629     then
630 niro 1305 removeargs=$(echo $1 | sed 's/^--remove-args=//')
631 niro 924 else
632     removeargs=$2
633     shift
634     fi
635     ;;
636 niro 923
637 niro 924 --banner*)
638     if echo $1 | grep '=' >/dev/null
639     then
640     banner=$(echo $1 | sed 's/^--banner=//')
641     else
642     banner=$2
643     shift
644     fi
645     ;;
646 niro 532
647 niro 924 --multiboot*)
648     if echo $1 |grep '=' >/dev/null
649     then
650     mbkernel=$(echo $1 | sed 's/^--multiboot=//')
651     else
652     # can't really support having an optional second arg here
653     # sorry!
654     mbkernel="/boot/xen.gz"
655     fi
656     ;;
657 niro 532
658 niro 924 --mbargs*)
659     if echo $1 |grep '=' >/dev/null
660     then
661     mbargs=$(echo $1 | sed 's/^--mbargs=//')
662     else
663     mbargs="$2"
664     shift
665     fi
666     ;;
667 niro 532
668 niro 924 --depmod)
669     moddep="make"
670     ;;
671 niro 532
672 niro 924 --rmmoddep)
673     moddep="remove"
674     ;;
675 niro 532
676 niro 924 --make-default)
677     makedefault="--make-default"
678     ;;
679 niro 532
680 niro 924 --package)
681     if echo $1 | grep '=' >/dev/null
682     then
683     package=$(echo $1 | sed 's/^--package=//')
684     else
685     package=$2
686     shift
687     fi
688     ;;
689 niro 532
690 niro 1334 --add-dracut-args)
691     adddracutargs=--add-dracut-args
692     ;;
693    
694     --add-plymouth-initrd)
695     addplymouthinitrd=--add-plymouth-initrd
696     ;;
697    
698 niro 924 -v)
699     verbose=-v
700     ;;
701 niro 532
702 niro 924 *)
703     if [[ -z ${mode} ]]
704     then
705     mode=$1
706     elif [[ -z ${version} ]]
707     then
708     version=$1
709     else
710     usage
711     fi
712     ;;
713     esac
714 niro 532
715 niro 924 shift
716 niro 532 done
717    
718     # make sure the mode is valid
719 niro 924 if [[ ${mode} != --install ]] && [[ ${mode} != --remove ]] && [[ ${mode} != --update ]]
720     then
721     usage
722 niro 532 fi
723    
724 niro 924 if [[ -z ${version} ]]
725     then
726     usage
727 niro 532 fi
728    
729 niro 924 if [ "${mode}" != "--install" -a "${makedefault}" ]
730     then
731     usage
732 niro 532 fi
733    
734 niro 924 kernelmajor=$(echo ${kernel} | cut -d . -f 1,2)
735 niro 532
736 niro 1305 # kernel image for 2.4 is kernel
737 niro 924 if [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]]
738     then
739     if [[ ${kernelmajor} = 2.4 ]]
740     then
741     kernelName=kernel
742     fi
743 niro 532 fi
744    
745     # set the initrd file based on arch; ia64 is the only currently known oddball
746 niro 924 if [[ -z ${initrdfile} ]]
747     then
748     INITRD_NAME_PREFIX="initrd"
749 niro 1334 if [[ -n ${dracut} ]]
750     then
751     INITRD_NAME_PREFIX="initramfs"
752     fi
753 niro 923
754 niro 924 if [[ $(uname -m) = ia64 ]]
755     then
756     initrdfile="/boot/efi/EFI/redhat/${INITRD_NAME_PREFIX}-${version}.img"
757     else
758     initrdfile="/boot/${INITRD_NAME_PREFIX}-${version}.img"
759     fi
760 niro 532 fi
761 niro 924 [[ -n ${verbose} ]] && echo "initrdfile is ${initrdfile}"
762 niro 532
763 niro 1334 # add dracut i18n, keyboard and plymouth kernel args if requested
764     if [[ -n ${dracut} ]] || [[ -n ${adddracutargs} ]]
765     then
766     [ -r /etc/conf.d/keymap ] && . /etc/conf.d/keymap
767     [ -r /etc/conf.d/consolefont ] && . /etc/conf.d/consolefont
768    
769     if [[ -n ${KEYMAP} ]]
770     then
771     kernargs="${kernargs} KEYTABLE=${KEYMAP}"
772     fi
773    
774     if [[ -n ${CONSOLEFONT} ]]
775     then
776     kernargs="${kernargs} SYSFONT=${CONSOLEFONT}"
777     fi
778     fi
779    
780 niro 532 # set this as the default if we have the package and it matches
781 niro 924 if [[ ${mode} = --install ]] && [[ ${UPDATEDEFAULT} = yes ]] && [[ -n ${package} ]] &&
782     [[ -n ${DEFAULTKERNEL} ]] && [[ ${package} = ${DEFAULTKERNEL} ]]
783     then
784     makedefault="--make-default"
785     [[ -n ${verbose} ]] && echo "making it the default based on config"
786 niro 532 fi
787    
788 niro 924 if [[ ${moddep} = make ]]
789     then
790     doDepmod
791     elif [[ ${moddep} = remove ]]
792     then
793     doRmmoddep
794 niro 532 fi
795    
796 niro 924 if [[ ${initrd} = make ]]
797     then
798 niro 1756 makeinitrd
799 niro 924 elif [[ ${initrd} = remove ]]
800     then
801     rminitrd
802 niro 532 fi
803    
804 niro 924 if [ ! -x ${grubby} ]
805     then
806     [[ -n ${verbose} ]] && echo "${grubby} does not exist"
807     exit 0
808 niro 532 fi
809    
810 niro 924 [[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1
811 niro 1697 [[ -n ${grub2Config} ]] && [ -f ${grub2Config} ] && cfgGrub2=1
812     [[ -n ${grub2EfiConfig} ]] && [ -f ${grub2EfiConfig} ] && cfgGrub2Efi=1
813 niro 924 [[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1
814 niro 1716 [[ -n ${extlinuxConfig} ]] && [ -f ${extlinuxConfig} ] && cfgExtlinux=1
815 niro 532
816 niro 1752 # if we have a U-Boot directory, but no boot script, check if the directory
817     # is mounted. If not, mount it, and then check if a boot script exists.
818 niro 1691 if [[ -n ${ubootDir} ]]
819     then
820 niro 1752 if [ -f ${ubootScript} ]
821 niro 1691 then
822 niro 1752 cfguBoot=1
823     else
824     mountEntry=$(mount | grep ${ubootDir})
825     if [[ -z ${mountEntry} ]]
826     then
827     mount ${ubootDevice} ${ubootDir}
828     mounted=1
829     fi
830     [ -f ${ubootScript} ] && cfguBoot=1
831 niro 1691 fi
832     fi
833    
834 niro 532 # if we have a lilo config on an x86 box, see if the default boot loader
835     # is lilo to determine if it should be run
836 niro 924 if [[ -n ${cfgLilo} ]] && [[ -n ${isx86} ]]
837     then
838     runLilo=$(${grubby} --bootloader-probe | grep lilo)
839 niro 532 fi
840    
841 niro 924 if [[ ${mode} = --install ]]
842     then
843     install
844     elif [[ ${mode} = --remove ]]
845     then
846     remove
847     elif [[ ${mode} = --update ]]
848     then
849     update
850 niro 532 fi
851    
852 niro 1752 # if we mounted the U-Boot directory, unmount it.
853     [[ -n ${mounted} ]] && umount ${ubootDir}
854    
855 niro 532 exit 0

Properties

Name Value
svn:executable *