Contents of /tags/grubby-8_29/new-kernel-pkg
Parent Directory | Revision Log
Revision 1848 -
(show annotations)
(download)
Mon Jul 2 13:07:56 2012 UTC (12 years, 2 months ago) by niro
Original Path: trunk/grubby/new-kernel-pkg
File size: 23654 byte(s)
Mon Jul 2 13:07:56 2012 UTC (12 years, 2 months ago) by niro
Original Path: trunk/grubby/new-kernel-pkg
File size: 23654 byte(s)
Update the code to set the ubootAddress.
1 | #!/bin/bash |
2 | # $Id$ |
3 | # |
4 | # new-kernel-pkg |
5 | # 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 | # Copyright 2002-2008 Red Hat, Inc. All rights reserved. |
12 | # modified for Magellan-Linux by Niels Rogalla <niro@magellan-linux.de> |
13 | # |
14 | # 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 | |
28 | 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 | PATH=/sbin:/bin:$PATH |
55 | |
56 | lilo=/sbin/lilo |
57 | |
58 | # some defaults that are sane for most arches |
59 | kernelName=kernel |
60 | |
61 | if [ -x ./grubby ] |
62 | then |
63 | grubby=./grubby |
64 | else |
65 | grubby=/sbin/grubby |
66 | fi |
67 | |
68 | [ -f /etc/conf.d/grubby ] && . /etc/conf.d/grubby |
69 | [ -f /etc/conf.d/grubby-uboot ] && . /etc/conf.d/grubby-uboot |
70 | |
71 | cfgGrub2="" |
72 | cfgGrub2Efi="" |
73 | cfgGrub="" |
74 | cfgLilo="" |
75 | cfgExtlinux="" |
76 | cfguBoot="" |
77 | runLilo="" |
78 | grubConfig="" |
79 | grub2Config="" |
80 | grub2EfiConfig="" |
81 | extlinuxConfig="" |
82 | |
83 | ARCH=$(uname -m) |
84 | |
85 | 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 | grub2Config=/boot/grub/grub.cfg |
95 | 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 | elif [[ ${ARCH} =~ armv[5|7].*l ]] |
116 | then |
117 | liloConfig="" |
118 | bootPrefix=/boot |
119 | ubootDir=${UBOOT_DIR:-"/boot"} |
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 | if [[ -z ${UBOOT_IMGADDR} ]] |
129 | then |
130 | 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 | then |
134 | ubootAddress=0x80008000 |
135 | elif [[ "${machine}" =~ ^Efika\ MX.* ]] |
136 | then |
137 | ubootAddress=0x90008000 |
138 | else |
139 | ubootAddress=0x00008000 |
140 | fi |
141 | else |
142 | ubootAddress="${UBOOT_IMGADDR}" |
143 | fi |
144 | else |
145 | # this leaves i?86 and x86_64 |
146 | liloConfig=/etc/lilo.conf |
147 | grubConfig=/boot/grub/grub.conf |
148 | grub2Config=/boot/grub/grub.cfg |
149 | grub2EfiConfig=/boot/grub/grub-efi.cfg |
150 | extlinuxConfig=/boot/extlinux/extlinux.conf |
151 | bootPrefix=/boot |
152 | liloFlag=lilo |
153 | isx86="yes" |
154 | fi |
155 | |
156 | mode="" |
157 | version="" |
158 | initrd="" |
159 | dracut="" |
160 | dracuthostonly="" |
161 | initrdfile="" |
162 | moddep="" |
163 | verbose="" |
164 | makedefault="" |
165 | package="" |
166 | mbkernel="${HYPERVISOR}" |
167 | mbargs="${HYPERVISOR_ARGS}" |
168 | adddracutargs="" |
169 | addplymouthinitrd="" |
170 | |
171 | usage() |
172 | { |
173 | echo "Usage: $(basename $0) [-v] [--mkinitrd] [--rminitrd] [--dracut]" >&2 |
174 | echo " [--initrdfile=<initrd-image>] [--depmod] [--rmmoddep]" >&2 |
175 | echo " [--kernel-args=<args>] [--remove-args=<args>]" >&2 |
176 | echo " [--banner=<banner>] [--multiboot=multiboot]" >&2 |
177 | echo " [--mbargs=mbargs] [--make-default] [--add-dracut-args]" >&2 |
178 | echo " [--add-plymouth-initrd]" >&2 |
179 | echo " [--host-only]" >&2 |
180 | echo " <--install | --remove | --update> <kernel-version>" >&2 |
181 | echo " (ex: $(basename $0) --mkinitrd --depmod --install 2.4.7-2)" >&2 |
182 | exit 1 |
183 | } |
184 | |
185 | 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 | |
194 | INITRD="" |
195 | if [ -f ${initrdfile} ] |
196 | then |
197 | [[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby" |
198 | INITRD="--initrd ${initrdfile}" |
199 | |
200 | if [[ -n ${addplymouthinitrd} ]] |
201 | then |
202 | INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img" |
203 | fi |
204 | fi |
205 | |
206 | # 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 | fi |
221 | |
222 | # get the root filesystem to use |
223 | rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab) |
224 | |
225 | if [[ -n ${mbkernel} ]] && [[ -n ${cfgLilo} ]] && [[ ${liloFlag} != elilo ]] |
226 | then |
227 | [[ -n ${verbose} ]] && echo "multiboot specified, not updating lilo.conf" |
228 | cfgLilo="" |
229 | fi |
230 | |
231 | if [[ -n ${cfgGrub} ]] |
232 | then |
233 | [[ -n ${verbose} ]] && echo "adding ${version} to ${grubConfig}" |
234 | |
235 | if [[ -n ${banner} ]] |
236 | then |
237 | title="${banner} [ ${version} ]" |
238 | elif [ -f /etc/mageversion ] |
239 | then |
240 | title="Magellan Linux $(< /etc/mageversion) [ ${version} ]" |
241 | elif [[ $(read_os_release id) = magellan ]] |
242 | then |
243 | title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]" |
244 | else |
245 | title="Magellan Linux [ ${version} ]" |
246 | fi |
247 | ${grubby} --grub -c ${grubConfig} \ |
248 | --add-kernel=${bootPrefix}/${kernelName}-${version} \ |
249 | ${INITRD} --copy-default ${makedefault} --title "${title}" \ |
250 | ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \ |
251 | --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}" |
252 | else |
253 | [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97" |
254 | fi |
255 | if [[ -n ${cfgGrub2} ]] |
256 | then |
257 | [[ -n ${verbose} ]] && echo "adding ${version} to ${grub2Config}" |
258 | |
259 | if [[ -n ${banner} ]] |
260 | then |
261 | title="${banner} [ ${version} ]" |
262 | elif [ -f /etc/mageversion ] |
263 | then |
264 | title="Magellan Linux $(< /etc/mageversion) [ ${version} ]" |
265 | elif [[ $(read_os_release id) = magellan ]] |
266 | then |
267 | title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]" |
268 | else |
269 | title="Magellan Linux [ ${version} ]" |
270 | fi |
271 | ${grubby} --grub2 -c ${grub2Config} \ |
272 | --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 | title="${banner} [ ${version} ]" |
287 | elif [ -f /etc/mageversion ] |
288 | then |
289 | title="Magellan Linux $(< /etc/mageversion) [ ${version} ]" |
290 | elif [[ $(read_os_release id) = magellan ]] |
291 | then |
292 | title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]" |
293 | else |
294 | title="Magellan Linux [ ${version} ]" |
295 | fi |
296 | ${grubby} --grub2 -c ${grub2EfiConfig} \ |
297 | --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 | if [[ -n ${cfgLilo} ]] |
307 | then |
308 | [[ -n ${verbose} ]] && echo "adding ${version} to ${liloConfig}" |
309 | |
310 | ${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 | |
316 | if [[ -n ${runLilo} ]] |
317 | then |
318 | [[ -n ${verbose} ]] && echo "running ${lilo}" |
319 | if [ ! -x ${lilo} ] |
320 | 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 | fi |
329 | |
330 | if [[ -n ${cfgExtlinux} ]] |
331 | then |
332 | [[ -n ${verbose} ]] && echo "adding ${version} to ${extlinuxConfig}" |
333 | |
334 | if [[ -n ${banner} ]] |
335 | then |
336 | title="${banner} [ ${version} ]" |
337 | elif [ -f /etc/mageversion ] |
338 | then |
339 | title="Magellan Linux $(< /etc/mageversion) [ ${version} ]" |
340 | elif [[ $(read_os_release id) = magellan ]] |
341 | then |
342 | title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]" |
343 | else |
344 | title="Magellan Linux [ ${version} ]" |
345 | 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 | } |
355 | |
356 | 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 | |
366 | if [[ -n ${cfgGrub} ]] |
367 | then |
368 | [[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}" |
369 | ${grubby} --grub -c ${grubConfig} \ |
370 | --remove-kernel=${bootPrefix}/${kernelName}-${version} |
371 | else |
372 | [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97" |
373 | fi |
374 | 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 | |
391 | if [[ -n ${cfgLilo} ]] |
392 | then |
393 | [[ -n ${verbose} ]] && echo "removing ${version} from ${liloConfig}" |
394 | ${grubby} --remove-kernel=${bootPrefix}/${kernelName}-${version} --${liloFlag} |
395 | |
396 | 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 | fi |
409 | |
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 | sed "/$version$/d" ${ubootDir}/${ubootKList} > ${tmpKList} |
419 | 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 | [[ -n ${verbose} ]] && echo "No previous kernel version. U-Boot images not removed!" |
459 | fi |
460 | else |
461 | [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}" |
462 | fi |
463 | |
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 | } |
473 | |
474 | update() |
475 | { |
476 | 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 | |
488 | if [[ -n ${addplymouthinitrd} ]] |
489 | then |
490 | INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img" |
491 | fi |
492 | fi |
493 | |
494 | if [[ -n ${cfgGrub} ]] |
495 | then |
496 | [[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}" |
497 | ${grubby} --grub -c ${grubConfig} \ |
498 | --update-kernel=${bootPrefix}/${kernelName}-${version} \ |
499 | ${INITRD} \ |
500 | ${kernargs:+--args="${kernargs}"} \ |
501 | ${removeargs:+--remove-args="${removeargs}"} |
502 | else |
503 | [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby" |
504 | fi |
505 | |
506 | 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 | if [[ -n ${cfgLilo} ]] |
531 | then |
532 | [[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}" |
533 | ${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \ |
534 | ${INITRD} \ |
535 | ${kernargs:+--args="${kernargs}"} \ |
536 | ${removeargs:+--remove-args="${removeargs}"} \ |
537 | --${liloFlag} |
538 | |
539 | 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 | fi |
552 | |
553 | if [[ -n ${cfguBoot} ]] |
554 | then |
555 | [[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..." |
556 | |
557 | [[ -n ${verbose} ]] && echo "creating uImage-${version}" |
558 | 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 | |
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 | |
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 | } |
598 | |
599 | makeinitrd() |
600 | { |
601 | if [[ -n ${dracut} ]] |
602 | then |
603 | tool="dracut ${dracuthostonly} -f ${initrdfile} ${version}" |
604 | else |
605 | tool="mkinitrd --allow-missing -f ${initrdfile} ${version}" |
606 | fi |
607 | [[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}" |
608 | ${tool} |
609 | rc=$? |
610 | if [ ${rc} != 0 ] |
611 | then |
612 | echo "mkinitrd failed" >&2 |
613 | exit 1 |
614 | fi |
615 | } |
616 | |
617 | rminitrd() |
618 | { |
619 | [[ -n ${verbose} ]] && echo "removing initrd ${initrdfile}" |
620 | [ -f ${initrdfile} ] && rm -f ${initrdfile} |
621 | } |
622 | |
623 | doDepmod() |
624 | { |
625 | [[ -n ${verbose} ]] && echo "running depmod for ${version}" |
626 | depmod -ae -F /boot/System.map-${version} ${version} |
627 | } |
628 | |
629 | doRmmoddep() |
630 | { |
631 | [[ -n ${verbose} ]] && echo "removing modules.dep info for ${version}" |
632 | [ -d /lib/modules/${version} ] && rm -f /lib/modules/${version}/modules.* |
633 | } |
634 | |
635 | |
636 | while [ $# -gt 0 ] |
637 | do |
638 | case $1 in |
639 | --mkinitrd) |
640 | initrd="make" |
641 | ;; |
642 | |
643 | --rminitrd) |
644 | initrd="remove" |
645 | ;; |
646 | |
647 | --dracut) |
648 | dracut=--dracut |
649 | ;; |
650 | |
651 | --host-only) |
652 | dracuthostonly=-H |
653 | ;; |
654 | |
655 | --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 | |
665 | --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 | |
675 | --remove-args*) |
676 | if echo $1 | grep '=' >/dev/null |
677 | then |
678 | removeargs=$(echo $1 | sed 's/^--remove-args=//') |
679 | else |
680 | removeargs=$2 |
681 | shift |
682 | fi |
683 | ;; |
684 | |
685 | --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 | |
695 | --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 | |
706 | --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 | |
716 | --depmod) |
717 | moddep="make" |
718 | ;; |
719 | |
720 | --rmmoddep) |
721 | moddep="remove" |
722 | ;; |
723 | |
724 | --make-default) |
725 | makedefault="--make-default" |
726 | ;; |
727 | |
728 | --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 | |
738 | --add-dracut-args) |
739 | adddracutargs=--add-dracut-args |
740 | ;; |
741 | |
742 | --add-plymouth-initrd) |
743 | addplymouthinitrd=--add-plymouth-initrd |
744 | ;; |
745 | |
746 | -v) |
747 | verbose=-v |
748 | ;; |
749 | |
750 | *) |
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 | |
763 | shift |
764 | done |
765 | |
766 | # make sure the mode is valid |
767 | if [[ ${mode} != --install ]] && [[ ${mode} != --remove ]] && [[ ${mode} != --update ]] |
768 | then |
769 | usage |
770 | fi |
771 | |
772 | if [[ -z ${version} ]] |
773 | then |
774 | usage |
775 | fi |
776 | |
777 | if [ "${mode}" != "--install" -a "${makedefault}" ] |
778 | then |
779 | usage |
780 | fi |
781 | |
782 | kernelmajor=$(echo ${kernel} | cut -d . -f 1,2) |
783 | |
784 | # kernel image for 2.4 is kernel |
785 | if [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]] |
786 | then |
787 | if [[ ${kernelmajor} = 2.4 ]] |
788 | then |
789 | kernelName=kernel |
790 | fi |
791 | fi |
792 | |
793 | # set the initrd file based on arch; ia64 is the only currently known oddball |
794 | if [[ -z ${initrdfile} ]] |
795 | then |
796 | INITRD_NAME_PREFIX="initrd" |
797 | if [[ -n ${dracut} ]] |
798 | then |
799 | INITRD_NAME_PREFIX="initramfs" |
800 | fi |
801 | |
802 | 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 | fi |
809 | [[ -n ${verbose} ]] && echo "initrdfile is ${initrdfile}" |
810 | |
811 | # 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 | # set this as the default if we have the package and it matches |
829 | 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 | fi |
835 | |
836 | if [[ ${moddep} = make ]] |
837 | then |
838 | doDepmod |
839 | elif [[ ${moddep} = remove ]] |
840 | then |
841 | doRmmoddep |
842 | fi |
843 | |
844 | if [[ ${initrd} = make ]] |
845 | then |
846 | makeinitrd |
847 | elif [[ ${initrd} = remove ]] |
848 | then |
849 | rminitrd |
850 | fi |
851 | |
852 | if [ ! -x ${grubby} ] |
853 | then |
854 | [[ -n ${verbose} ]] && echo "${grubby} does not exist" |
855 | exit 0 |
856 | fi |
857 | |
858 | [[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1 |
859 | [[ -n ${grub2Config} ]] && [ -f ${grub2Config} ] && cfgGrub2=1 |
860 | [[ -n ${grub2EfiConfig} ]] && [ -f ${grub2EfiConfig} ] && cfgGrub2Efi=1 |
861 | [[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1 |
862 | [[ -n ${extlinuxConfig} ]] && [ -f ${extlinuxConfig} ] && cfgExtlinux=1 |
863 | |
864 | # 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 | if [[ -n ${ubootDir} ]] |
867 | then |
868 | if [ -f ${ubootScript} ] |
869 | then |
870 | 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 | fi |
880 | fi |
881 | |
882 | # 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 | if [[ -n ${cfgLilo} ]] && [[ -n ${isx86} ]] |
885 | then |
886 | runLilo=$(${grubby} --bootloader-probe | grep lilo) |
887 | fi |
888 | |
889 | if [[ ${mode} = --install ]] |
890 | then |
891 | install |
892 | elif [[ ${mode} = --remove ]] |
893 | then |
894 | remove |
895 | elif [[ ${mode} = --update ]] |
896 | then |
897 | update |
898 | fi |
899 | |
900 | # if we mounted the U-Boot directory, unmount it. |
901 | [[ -n ${mounted} ]] && umount ${ubootDir} |
902 | |
903 | exit 0 |
Properties
Name | Value |
---|---|
svn:executable | * |