Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *