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