Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *