Contents of /trunk/grubby/new-kernel-pkg
Parent Directory | Revision Log
Revision 3045 -
(show annotations)
(download)
Thu Jul 6 12:17:30 2017 UTC (7 years, 2 months ago) by niro
File size: 26842 byte(s)
Thu Jul 6 12:17:30 2017 UTC (7 years, 2 months ago) by niro
File size: 26842 byte(s)
-fixed typos
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 | ubootScript="/boot/boot.scr" |
83 | |
84 | ARCH=$(uname -m) |
85 | |
86 | if [[ ${ARCH} = ia64 ]] |
87 | then |
88 | liloConfig=/boot/efi/EFI/redhat/elilo.conf |
89 | bootPrefix=/boot/efi/EFI/redhat |
90 | liloFlag=elilo |
91 | isx86="" |
92 | elif [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]] |
93 | then |
94 | liloConfig=/etc/yaboot.conf |
95 | grub2Config=/boot/grub/grub.cfg |
96 | bootPrefix=/boot |
97 | lilo=/sbin/ybin |
98 | liloFlag=yaboot |
99 | runLilo="yes" |
100 | isx86="" |
101 | elif [[ ${ARCH} = sparc ]] || [[ ${ARCH} = sparc64 ]] |
102 | then |
103 | liloConfig=/etc/silo.conf |
104 | bootPrefix=/boot |
105 | liloFlag=silo |
106 | lilo=/sbin/silo |
107 | isx86="" |
108 | elif [[ ${ARCH} = s390 ]] || [[ ${ARCH} = s390x ]] |
109 | then |
110 | liloConfig=/etc/zipl.conf |
111 | bootPrefix=/boot |
112 | liloFlag=zipl |
113 | lilo=/sbin/zipl |
114 | runLilo="yes" |
115 | isx86="" |
116 | elif [[ ${ARCH} =~ armv[5|7].*l ]] |
117 | then |
118 | liloConfig="" |
119 | bootPrefix=/boot |
120 | extlinuxConfig=$(readlink -f /etc/extlinux.conf 2>/dev/null) |
121 | ubootDir=${UBOOT_DIR:-"/boot"} |
122 | ubootScript=$ubootDir/${UBOOT_SCR:-"boot.scr"} |
123 | ubootKList=${UBOOT_KLIST:-"klist.txt"} |
124 | ubootDevice=/dev/${UBOOT_DEVICE:-"mmcblk0p1"} |
125 | ubootDefaultImage=${UBOOT_UIMAGE:-"uImage"} |
126 | ubootDefaultInitrd=${UBOOT_UINITRD:-"uInitrd"} |
127 | ubootAddress=${UBOOT_IMGADDR:-"0x00008000"} |
128 | mounted="" |
129 | liloFlag="" |
130 | isx86="" |
131 | else |
132 | # this leaves i?86 and x86_64 |
133 | liloConfig=/etc/lilo.conf |
134 | grubConfig=/boot/grub/grub.conf |
135 | grub2Config=/boot/grub/grub.cfg |
136 | grub2EfiConfig=/boot/grub/grub-efi.cfg |
137 | extlinuxConfig=/boot/extlinux/extlinux.conf |
138 | bootPrefix=/boot |
139 | liloFlag=lilo |
140 | isx86="yes" |
141 | fi |
142 | |
143 | mode="" |
144 | version="" |
145 | initrd="" |
146 | dracut="" |
147 | dracuthostonly="" |
148 | initrdfile="" |
149 | devtreefile="" |
150 | moddep="" |
151 | verbose="" |
152 | makedefault="" |
153 | package="" |
154 | mbkernel="${HYPERVISOR}" |
155 | mbargs="${HYPERVISOR_ARGS}" |
156 | adddracutargs="" |
157 | addplymouthinitrd="" |
158 | DEBUGARG="systemd.log_level=debug systemd.log_target=kmsg" |
159 | |
160 | usage() |
161 | { |
162 | echo "Usage: $(basename $0) [-v] [--mkinitrd] [--rminitrd] [--dracut]" >&2 |
163 | echo " [--initrdfile=<initrd-image>] [--depmod] [--rmmoddep]" >&2 |
164 | echo " [--kernel-args=<args>] [--remove-args=<args>]" >&2 |
165 | echo " [--banner=<banner>] [--multiboot=multiboot]" >&2 |
166 | echo " [--mbargs=mbargs] [--make-default] [--add-dracut-args]" >&2 |
167 | echo " [--add-plymouth-initrd]" >&2 |
168 | echo " [--host-only] [--devtree=<devicetree.dtb>] [--devtreedir=</devicetree/path/>]" >&2 |
169 | echo " <--install | --remove | --update> <kernel-version>" >&2 |
170 | echo " (ex: $(basename $0) --mkinitrd --depmod --install 2.4.7-2)" >&2 |
171 | exit 1 |
172 | } |
173 | |
174 | rungrubby() |
175 | { |
176 | if [[ $1 == --debug ]] |
177 | then |
178 | [[ ${MAKEDEBUG} != yes ]] && return 0 |
179 | [[ -n ${verbose} ]] && echo "- First, making a debug entry." |
180 | if [[ ${ARCH} = s390 ]] || [[ ${ARCH} = s390x ]] |
181 | then |
182 | declare -x debugtitle="_with_debugging" |
183 | else |
184 | declare -x debugtitle=" with debugging" |
185 | fi |
186 | declare -x debugargs="${DEBUGARG}" |
187 | shift |
188 | else |
189 | [[ -n ${verbose} ]] && echo "- Making a normal entry." |
190 | fi |
191 | $(eval $grubby $@) |
192 | export -n debugargs |
193 | export -n debugtitle |
194 | unset debugargs |
195 | unset debugtitle |
196 | } |
197 | |
198 | set_title() |
199 | { |
200 | if [[ -n ${banner} ]] |
201 | then |
202 | if [[ ${ARCH} = s390 ]] || [[ ${ARCH} = s390x ]] |
203 | then |
204 | title=$(echo ${banner} | sed 's/ /_/g') |
205 | else |
206 | title="${banner} [ ${version} ]" |
207 | fi |
208 | elif [[ ${ARCH} = s390 ]] || [[ ${ARCH} = s390x ]] |
209 | then |
210 | title=$(echo ${version} | sed 's/ /_/g') |
211 | elif [ -f /etc/os-release ] |
212 | then |
213 | title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]" |
214 | elif [ -f /etc/mageversion ] |
215 | then |
216 | title="Magellan Linux $(< /etc/mageversion) [ ${version} ]" |
217 | else |
218 | title="Magellan Linux [ ${version} ]" |
219 | fi |
220 | } |
221 | |
222 | install() |
223 | { |
224 | # XXX kernel should be able to be specified also (or work right on ia64) |
225 | if [ ! -f ${kernelImage} ] |
226 | then |
227 | [[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby" |
228 | return |
229 | fi |
230 | |
231 | INITRD="" |
232 | if [ -f ${initrdfile} ] |
233 | then |
234 | [[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby" |
235 | INITRD="--initrd ${initrdfile}" |
236 | |
237 | if [[ -n ${addplymouthinitrd} ]] |
238 | then |
239 | INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img" |
240 | fi |
241 | fi |
242 | |
243 | DEVTREE="" |
244 | if [[ -n ${devtreefile} ]] && [ -f ${devtreefile} ] |
245 | then |
246 | [[ -n ${verbose} ]] && echo "found ${devtreefile} and using it with grubby" |
247 | DEVTREE="--devtree ${devtreefile}" |
248 | fi |
249 | |
250 | DEVTREEDIR="" |
251 | if [[ -n ${devtreedir} ]] && [ -d ${devtreedir} ] |
252 | then |
253 | [ -n ${verbose} ] && echo "found ${devtreedir} and using it with grubby" |
254 | DEVTREEDIR="--devtreedir ${devtreedir}" |
255 | fi |
256 | |
257 | # FIXME: is this a good heuristic to find out if we're on iSeries? |
258 | if [ -d /proc/iSeries ] |
259 | then |
260 | [[ -n ${verbose} ]] && echo "On an iSeries, just making img file" |
261 | if [[ -z ${initrdfile} ]] |
262 | then |
263 | [[ -n ${verbose} ]] && echo "No initrd, just adding system map" |
264 | /sbin/addSystemMap ${bootPrefix}/System.map-${version} ${kernelImage} ${bootPrefix}/vmlinitrd-${version} |
265 | else |
266 | /sbin/addSystemMap ${bootPrefix}/System.map-${version} ${kernelImage} ${bootPrefix}/vmlinux.sm-${version} |
267 | /sbin/addRamDisk ${initrdfile} ${bootPrefix}/System.map-${version} ${bootPrefix}/vmlinux.sm-${version} ${bootPrefix}/vmlinitrd-${version} 2>/dev/null |
268 | rm ${bootPrefix}/vmlinux.sm-${version} |
269 | fi |
270 | return |
271 | fi |
272 | |
273 | # get the root filesystem to use |
274 | rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab 2>/dev/null) |
275 | if [[ -z $rootdevice ]] |
276 | then |
277 | rootdevice=$(grep -o -P "(?<=root=)\S+" /proc/cmdline) |
278 | fi |
279 | |
280 | if [[ -n ${mbkernel} ]] && [[ -n ${cfgLilo} ]] && [[ ${liloFlag} != elilo ]] |
281 | then |
282 | [[ -n ${verbose} ]] && echo "multiboot specified, not updating lilo.conf" |
283 | cfgLilo="" |
284 | fi |
285 | |
286 | set_title |
287 | |
288 | if [[ -n ${cfgGrub} ]] |
289 | then |
290 | [[ -n ${verbose} ]] && echo "adding ${version} to ${grubConfig}" |
291 | |
292 | ARGS="--grub -c ${grubConfig} --add-kernel=${kernelImage} ${INITRD} \ |
293 | ${mbkernel:+--add-multiboot=\"${mbkernel}\"} \ |
294 | ${mbargs:+--mbargs=\"${mbargs}\"} \ |
295 | --title=\"${title}\${debugtitle}\" --copy-default \ |
296 | --args=\"root=${rootdevice} ${kernargs} \${debugargs}\" \ |
297 | --remove-kernel=\"TITLE=${title}\${debugtitle}\"" |
298 | rungrubby ${ARGS} ${makedefault} |
299 | rungrubby --debug ${ARGS} --set-index=1 |
300 | else |
301 | [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97" |
302 | fi |
303 | if [[ -n ${cfgGrub2} ]] |
304 | then |
305 | [[ -n ${verbose} ]] && echo "adding ${version} to ${grub2Config}" |
306 | |
307 | ARGS="--grub2 -c ${grub2Config} --add-kernel=${kernelImage} ${INITRD} \ |
308 | --copy-default --title \"${title}\${debugtitle}\" \ |
309 | ${mbkernel:+--add-multiboot=\"${mbkernel}\"} \ |
310 | ${mbargs:+--mbargs=\"${mbargs}\"} \ |
311 | --args=\"root=${rootdevice} ${kernargs} \${debugargs}\" \ |
312 | --remove-kernel=\"TITLE=${title}\${debugtitle}\"" |
313 | rungrubby ${ARGS} ${makedefault} |
314 | rungrubby --debug ${ARGS} --set-index=1 |
315 | else |
316 | [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby for grub 2" |
317 | fi |
318 | if [[ -n ${cfgGrub2Efi} ]] |
319 | then |
320 | [[ -n ${verbose} ]] && echo "adding ${version} to ${grub2EfiConfig}" |
321 | |
322 | ARGS="--grub2 -c ${grub2EfiConfig} --efi \ |
323 | --add-kernel=${kernelImage} ${DEVTREE} ${INITRD} \ |
324 | --copy-default --title \"${title}\${debugtitle}\" \ |
325 | ${mbkernel:+--add-multiboot=\"${mbkernel}\"} \ |
326 | ${mbargs:+--mbargs=\"${mbargs}\"} \ |
327 | --args=\"root=${rootdevice} ${kernargs} \${debugargs}\" \ |
328 | --remove-kernel=\"TITLE=${title}\${debugtitle}\"" |
329 | rungrubby ${ARGS} ${makedefault} |
330 | rungrubby --debug ${ARGS} --set-index=1 |
331 | else |
332 | [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby for grub 2 with UEFI" |
333 | fi |
334 | |
335 | if [[ -n ${cfgLilo} ]] |
336 | then |
337 | [[ -n ${verbose} ]] && echo "adding ${version} to ${liloConfig}" |
338 | |
339 | ARGS="--${liloFlag} --add-kernel=${kernelImage} ${INITRD} \ |
340 | --copy-default --title \"${title}\${debugtitle}\" \ |
341 | ${mbkernel:+--add-multiboot=\"${mbkernel}\"} \ |
342 | ${mbargs:+--mbargs=\"${mbargs}\"} \ |
343 | --args=\"root=${rootdevice} ${kernargs} \${debugargs}\" \ |
344 | --remove-kernel=\"TITLE=${version}\"" |
345 | rungrubby ${ARGS} ${makedefault} |
346 | rungrubby --debug ${ARGS} --set-index=1 |
347 | |
348 | if [[ -n ${runLilo} ]] |
349 | then |
350 | [[ -n ${verbose} ]] && echo "running ${lilo}" |
351 | if [ ! -x ${lilo} ] |
352 | then |
353 | [[ -n ${verbose} ]] && echo "${lilo} does not exist" |
354 | else |
355 | ${lilo} > /dev/null |
356 | fi |
357 | fi |
358 | else |
359 | [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
360 | fi |
361 | |
362 | if [[ -n ${cfgExtlinux} ]] |
363 | then |
364 | [[ -n ${verbose} ]] && echo "adding ${version} to ${extlinuxConfig}" |
365 | |
366 | ARGS="--extlinux -c ${extlinuxConfig} --add-kernel=${kernelImage} \ |
367 | ${DEVTREEDIR} ${DEVTREE} \ |
368 | ${INITRD} --copy-default --title \"${title}\${debugtitle}\" \ |
369 | ${mbkernel:+--add-multiboot=\"${mbkernel}\"} \ |
370 | ${mbargs:+--mbargs=\"${mbargs}\"} \ |
371 | --args=\"root=${rootdevice} ${kernargs} \${debugargs}\" \ |
372 | --remove-kernel=\"TITLE=${title}\${debugtitle}\"" |
373 | rungrubby ${ARGS} ${makedefault} |
374 | rungrubby --debug ${ARGS} --set-index=1 |
375 | else |
376 | [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux" |
377 | fi |
378 | } |
379 | |
380 | remove() |
381 | { |
382 | # FIXME: is this a good heuristic to find out if we're on iSeries? |
383 | if [ -d /proc/iSeries ] |
384 | then |
385 | [[ -n ${verbose} ]] && echo "On an iSeries, remove img file" |
386 | rm -f ${kernelImage}.img 2>/dev/null |
387 | return |
388 | fi |
389 | |
390 | if [[ -n ${cfgGrub} ]] |
391 | then |
392 | [[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}" |
393 | ${grubby} --grub -c ${grubConfig} \ |
394 | --remove-kernel=${kernelImage} |
395 | else |
396 | [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97" |
397 | fi |
398 | if [[ -n ${cfgGrub2} ]] |
399 | then |
400 | [[ -n ${verbose} ]] && echo "removing ${version} from ${grub2Config}" |
401 | ${grubby} --grub2 -c ${grub2Config} \ |
402 | --remove-kernel=${kernelImage} |
403 | else |
404 | [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby for grub 2" |
405 | fi |
406 | if [[ -n ${cfgGrub2Efi} ]] |
407 | then |
408 | [[ -n ${verbose} ]] && echo "removing ${version} from ${grub2EfiConfig}" |
409 | ${grubby} --grub2 -c ${grub2EfiConfig} --efi \ |
410 | --remove-kernel=${kernelImage} |
411 | else |
412 | [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby grub 2 with UEFI" |
413 | fi |
414 | |
415 | if [[ -n ${cfgLilo} ]] |
416 | then |
417 | [[ -n ${verbose} ]] && echo "removing ${version} from ${liloConfig}" |
418 | ${grubby} --remove-kernel=${kernelImage} --${liloFlag} |
419 | |
420 | if [[ -n ${runLilo} ]] |
421 | then |
422 | [[ -n ${verbose} ]] && echo "running ${lilo}" |
423 | if [ ! -x ${lilo} ] |
424 | then |
425 | [[ -n ${verbose} ]] && echo "${lilo} does not exist" |
426 | else |
427 | ${lilo} > /dev/null |
428 | fi |
429 | fi |
430 | else |
431 | [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
432 | fi |
433 | |
434 | if [[ -n ${cfguBoot} ]] |
435 | then |
436 | [[ -n ${verbose} ]] && echo "removing ${version} from ${ubootDir}..." |
437 | |
438 | if [ -f ${ubootDir}/${ubootKList} ] |
439 | then |
440 | tmpKList=$(mktemp ${ubootDir}/${ubootKList}.XXXX) |
441 | curversion=$(tail -n1 ${ubootDir}/${ubootKList}) |
442 | sed "/$version$/d" ${ubootDir}/${ubootKList} > ${tmpKList} |
443 | newversion=$(tail -n1 ${tmpKList}) |
444 | if [ -f ${ubootDir}/uImage-${newversion} ] && [ -f ${ubootDir}/uInitrd-${newversion} ] |
445 | then |
446 | if [[ ${curversion} != ${newversion} ]] |
447 | then |
448 | cp -fp ${ubootDir}/uImage-${newversion} ${ubootDir}/${ubootDefaultImage} |
449 | if [ $? -ne 0 ] |
450 | then |
451 | [[ -n ${verbose} ]] && echo "copy uImage-${newversion} error, default kernel not replaced!" && exit |
452 | fi |
453 | cp -fp ${ubootDir}/uInitrd-${newversion} ${ubootDir}/${ubootDefaultInitrd} |
454 | if [ $? -ne 0 ] |
455 | then |
456 | [[ -n ${verbose} ]] && echo "copy uInitrd-${newversion} error, default Initrd not replaced!" && exit |
457 | fi |
458 | fi |
459 | |
460 | [[ -n ${verbose} ]] && echo "removing uImage-${version}" |
461 | if [ -f ${ubootDir}/uImage-${version} ] |
462 | then |
463 | rm -f ${ubootDir}/uImage-${version} |
464 | else |
465 | [[ -n ${verbose} ]] && echo "uImage-${version} did not exist!" |
466 | fi |
467 | |
468 | [[ -n ${verbose} ]] && echo "removing uInitrd-${version}" |
469 | if [ -f ${ubootDir}/uInitrd-${version} ] |
470 | then |
471 | rm -f ${ubootDir}/uInitrd-${version} |
472 | else |
473 | [[ -n ${verbose} ]] && echo "uInitrd-${version} did not exist!" |
474 | fi |
475 | |
476 | mv ${tmpKList} ${ubootDir}/${ubootKList} |
477 | [ -x /sbin/a-b-c ] && /sbin/a-b-c |
478 | else |
479 | [[ -n ${verbose} ]] && echo "uImage ${newversion} does not exist!" |
480 | [ -f ${tmpKList} ] && rm -f ${tmpKList} |
481 | fi |
482 | else |
483 | [[ -n ${verbose} ]] && echo "No previous kernel version. U-Boot images not removed!" |
484 | fi |
485 | else |
486 | [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}" |
487 | fi |
488 | |
489 | if [[ -n ${cfgExtlinux} ]] |
490 | then |
491 | [[ -n ${verbose} ]] && echo "removing ${version} from ${extlinuxConfig}" |
492 | ${grubby} --extlinux -c ${extlinuxConfig} \ |
493 | --remove-kernel=${kernelImage} |
494 | else |
495 | [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux" |
496 | fi |
497 | } |
498 | |
499 | update() |
500 | { |
501 | if [ ! -f ${kernelImage} ] |
502 | then |
503 | [[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby" |
504 | return |
505 | fi |
506 | |
507 | set_title |
508 | |
509 | INITRD="" |
510 | if [ -f ${initrdfile} ] |
511 | then |
512 | [[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby" |
513 | INITRD="--initrd ${initrdfile}" |
514 | |
515 | if [[ -n ${addplymouthinitrd} ]] |
516 | then |
517 | INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img" |
518 | fi |
519 | fi |
520 | |
521 | DEVTREE="" |
522 | if [[ -n ${devtreefile} ]] && [ -f ${devtreefile} ] |
523 | then |
524 | [[ -n ${verbose} ]] && echo "found ${devtreefile} and using it with grubby" |
525 | DEVTREE="--devtree ${devtreefile}" |
526 | fi |
527 | |
528 | DEVTREEDIR="" |
529 | if [[ -n ${devtreedir} ]] && [ -d ${devtreedir} ] |
530 | then |
531 | [[ -n ${verbose} ]] && echo "found ${devtreedir} and using it with grubby" |
532 | DEVTREEDIR="--devtreedir ${devtreedir}" |
533 | fi |
534 | |
535 | if [[ -n ${cfgGrub} ]] |
536 | then |
537 | [[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}" |
538 | ARGS="--grub -c ${grubConfig} --update-kernel=${kernelImage} ${INITRD} \ |
539 | ${kernargs:+--args=\"${kernargs}\"} \ |
540 | ${removeargs:+--remove-args=\"${removeargs}\"} \ |
541 | ${mbkernel:+--add-multiboot=\"${mbkernel}\"} \ |
542 | --title=\"${title}\${debugtitle}\"" |
543 | rungrubby ${ARGS} |
544 | rungrubby --debug ${ARGS} |
545 | else |
546 | [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby" |
547 | fi |
548 | |
549 | if [[ -n ${cfgGrub2} ]] |
550 | then |
551 | [[ -n ${verbose} ]] && echo "updating ${version} from ${grub2Config}" |
552 | ARGS="--grub2 -c ${grub2Config} --update-kernel=${kernelImage} ${INITRD} \ |
553 | ${kernargs:+--args=\"${kernargs}\"} \ |
554 | ${removeargs:+--remove-args=\"${removeargs}\"} \ |
555 | --title=\"${title}\${debugtitle}\"" |
556 | rungrubby ${ARGS} |
557 | rungrubby --debug ${ARGS} |
558 | else |
559 | [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby" |
560 | fi |
561 | |
562 | if [[ -n ${cfgGrub2Efi} ]] |
563 | then |
564 | [[ -n ${verbose} ]] && echo "updating ${version} from ${grub2EfiConfig}" |
565 | ARGS="--grub2 -c ${grub2EfiConfig} --efi --update-kernel=${kernelImage} \ |
566 | ${INITRD} ${kernargs:+--args=\"${kernargs}\"} \ |
567 | ${removeargs:+--remove-args=\"${removeargs}\"} \ |
568 | --title=\"${title}\${debugtitle}\"" |
569 | rungrubby ${ARGS} |
570 | rungrubby --debug ${ARGS} |
571 | else |
572 | [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby" |
573 | fi |
574 | |
575 | if [[ -n ${cfgLilo} ]] |
576 | then |
577 | [[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}" |
578 | ARGS="--${liloFlag} --update-kernel=${kernelImage} ${INITRD} \ |
579 | ${kernargs:+--args=\"${kernargs}\"} \ |
580 | ${removeargs:+--remove-args=\"${removeargs}\"} \ |
581 | --title=\"${title}\${debugtitle}\"" |
582 | rungrubby ${ARGS} |
583 | rungrubby --debug ${ARGS} |
584 | |
585 | if [[ -n ${runLilo} ]] |
586 | then |
587 | [[ -n ${verbose} ]] && echo "running ${lilo}" |
588 | if [ ! -x ${lilo} ] |
589 | then |
590 | [[ -n ${verbose} ]] && echo "${lilo} does not exist" |
591 | else |
592 | ${lilo} > /dev/null |
593 | fi |
594 | fi |
595 | else |
596 | [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
597 | fi |
598 | |
599 | if [[ -n ${cfguBoot} ]] |
600 | then |
601 | [[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..." |
602 | |
603 | [[ -n ${verbose} ]] && echo "creating uImage-${version}" |
604 | mkimage -A arm -O linux -T kernel -C none -a ${ubootAddress} \ |
605 | -e ${ubootAddress} -n ${version} \ |
606 | -d ${kernelImage} ${ubootDir}/uImage-${version} |
607 | |
608 | [[ -n ${verbose} ]] && echo "creating uInitrd-${version}" |
609 | mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 \ |
610 | -n initramfs -d ${initrdfile} ${ubootDir}/uInitrd-${version} |
611 | |
612 | if [ -f ${ubootDir}/uImage-${version} ] && [ -f ${ubootDir}/uInitrd-${version} ] |
613 | then |
614 | cp -fp ${ubootDir}/uImage-${version} ${ubootDir}/${ubootDefaultImage} |
615 | if [ $? -ne 0 ] |
616 | then |
617 | [[ -n ${verbose} ]] && echo "copy uImage-${version} error, kernel not installed!" && exit |
618 | fi |
619 | cp -fp ${ubootDir}/uInitrd-${version} ${ubootDir}/${ubootDefaultInitrd} |
620 | if [ $? -ne 0 ] |
621 | then |
622 | [[ -n ${verbose} ]] && echo "copy uInitrd-${version} error, kernel not installed!" && exit |
623 | fi |
624 | echo ${version} >> ${ubootDir}/${ubootKList} |
625 | [ -x /sbin/a-b-c ] && /sbin/a-b-c |
626 | else |
627 | [[ -n ${verbose} ]] && echo "cannot make ${version} the default" |
628 | fi |
629 | else |
630 | [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not setting up ${ubootDir}" |
631 | fi |
632 | |
633 | if [[ -n ${cfgExtlinux} ]] |
634 | then |
635 | [[ -n ${verbose} ]] && echo "updating ${version} from ${extlinuxConfig}" |
636 | ARGS="--extlinux -c ${extlinuxConfig} --update-kernel=${kernelImage} \ |
637 | ${DEVTREE} ${DEVTREEDIR} ${INITRD} ${kernargs:+--args=\"${kernargs}\"} \ |
638 | ${removeargs:+--remove-args=\"${removeargs}\"} \ |
639 | --title=\"${title}\${debugtitle}\"" |
640 | rungrubby ${ARGS} |
641 | rungrubby --debug ${ARGS} |
642 | else |
643 | [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby" |
644 | fi |
645 | } |
646 | |
647 | makeinitrd() |
648 | { |
649 | if [[ -n ${dracut} ]] |
650 | then |
651 | tool="dracut ${dracuthostonly} -f ${initrdfile} ${version}" |
652 | else |
653 | tool="mkinitrd --allow-missing -f ${initrdfile} ${version}" |
654 | fi |
655 | [[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}" |
656 | ${tool} |
657 | rc=$? |
658 | if [ ${rc} != 0 ] |
659 | then |
660 | echo "mkinitrd failed" >&2 |
661 | exit 1 |
662 | fi |
663 | } |
664 | |
665 | rminitrd() |
666 | { |
667 | [[ -n ${verbose} ]] && echo "removing initrd ${initrdfile}" |
668 | [ -f ${initrdfile} ] && rm -f ${initrdfile} |
669 | } |
670 | |
671 | doDepmod() |
672 | { |
673 | [[ -n ${verbose} ]] && echo "running depmod for ${version}" |
674 | depmod -ae -F /boot/System.map-${version} ${version} |
675 | } |
676 | |
677 | doRmmoddep() |
678 | { |
679 | [[ -n ${verbose} ]] && echo "removing modules.dep info for ${version}" |
680 | if [ -d /lib/modules/${version} ] |
681 | then |
682 | rm -f /lib/modules/${version}/modules.*.bin \ |
683 | /lib/modules/${version}/modules.{alias,dep,devname,symbols,softdep} |
684 | fi |
685 | } |
686 | |
687 | # kernel image for 2.4 is kernel |
688 | if [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]] |
689 | then |
690 | if [[ ${kernelmajor} = 2.4 ]] |
691 | then |
692 | kernelName=kernel |
693 | fi |
694 | fi |
695 | |
696 | while [ $# -gt 0 ] |
697 | do |
698 | case $1 in |
699 | --mkinitrd) |
700 | initrd="make" |
701 | ;; |
702 | |
703 | --rminitrd) |
704 | initrd="remove" |
705 | ;; |
706 | |
707 | --devtree*) |
708 | if [[ $1 == --devtree\=* ]] |
709 | then |
710 | devtreefile="${1#--devtreefile=}" |
711 | else |
712 | devtreefile="$2" |
713 | shift |
714 | fi |
715 | ;; |
716 | |
717 | --devtreedir*) |
718 | if [[ $1 == --devtreedir\=* ]] |
719 | then |
720 | devtreedir=${1#--devtreedir=} |
721 | else |
722 | devtreedir=$2 |
723 | shift |
724 | fi |
725 | ;; |
726 | |
727 | --dracut) |
728 | dracut=--dracut |
729 | ;; |
730 | |
731 | --host-only) |
732 | dracuthostonly=-H |
733 | ;; |
734 | |
735 | --initrdfile*) |
736 | if [[ $1 == --initrdfile\=* ]] |
737 | then |
738 | initrdfile=${1#--initrdfile=} |
739 | else |
740 | initrdfile=$2 |
741 | shift |
742 | fi |
743 | ;; |
744 | |
745 | --kernel-args*) |
746 | if [[ $1 == --kernel-args\=* ]] |
747 | then |
748 | kernargs=${1#--kernel-args=} |
749 | else |
750 | kernargs=$2 |
751 | shift |
752 | fi |
753 | ;; |
754 | |
755 | --remove-args*) |
756 | if [[ $1 == --remove-args\=* ]] |
757 | then |
758 | removeargs=${1#--remove-args=} |
759 | else |
760 | removeargs=$2 |
761 | shift |
762 | fi |
763 | ;; |
764 | |
765 | --banner*) |
766 | if [[ $1 == --banner\=* ]] |
767 | then |
768 | banner=${1#--banner=} |
769 | else |
770 | banner=$2 |
771 | shift |
772 | fi |
773 | ;; |
774 | |
775 | --multiboot*) |
776 | if [[ $1 == --multiboot\=* ]] |
777 | then |
778 | mbkernel=${1#--multiboot=} |
779 | else |
780 | # can't really support having an optional second arg here |
781 | # sorry! |
782 | mbkernel="/boot/xen.gz" |
783 | fi |
784 | ;; |
785 | |
786 | --mbargs*) |
787 | if [[ $1 == --mbargs\=* ]] |
788 | then |
789 | mbargs=${1#--mbargs=} |
790 | else |
791 | mbargs="$2" |
792 | shift |
793 | fi |
794 | ;; |
795 | |
796 | --depmod) |
797 | moddep="make" |
798 | ;; |
799 | |
800 | --rmmoddep) |
801 | moddep="remove" |
802 | ;; |
803 | |
804 | --make-default) |
805 | makedefault="--make-default" |
806 | ;; |
807 | |
808 | --package*) |
809 | if [[ $1 == --package\=* ]] |
810 | then |
811 | package=${1#--package=} |
812 | else |
813 | package=$2 |
814 | shift |
815 | fi |
816 | ;; |
817 | |
818 | --add-dracut-args) |
819 | adddracutargs=--add-dracut-args |
820 | ;; |
821 | |
822 | --add-plymouth-initrd) |
823 | addplymouthinitrd=--add-plymouth-initrd |
824 | ;; |
825 | |
826 | --kernel-image*) |
827 | if [[ $1 == --kernel-image\=* ]] |
828 | then |
829 | kernelImage=${1#--kernel-image=} |
830 | else |
831 | kernelImage="$2" |
832 | shift |
833 | fi |
834 | if ! [[ -f ${kernelImage} ]] |
835 | then |
836 | echo "Can't find kernel image '${kernelImage}'" >&2 |
837 | usage |
838 | exit 1 |
839 | fi |
840 | ;; |
841 | |
842 | --kernel-name*) |
843 | if [[ $1 == --kernel-name\=* ]] |
844 | then |
845 | kernelName=${1#--kernel-name=} |
846 | else |
847 | kernelName="$2" |
848 | shift |
849 | fi |
850 | ;; |
851 | |
852 | -v) |
853 | verbose=-v |
854 | ;; |
855 | |
856 | *) |
857 | if [[ -z ${mode} ]] |
858 | then |
859 | mode=$1 |
860 | elif [[ -z ${version} ]] |
861 | then |
862 | version=$1 |
863 | else |
864 | usage |
865 | fi |
866 | ;; |
867 | esac |
868 | |
869 | shift |
870 | done |
871 | |
872 | # make sure the mode is valid |
873 | if [[ ${mode} != --install ]] && [[ ${mode} != --remove ]] && [[ ${mode} != --update ]] |
874 | then |
875 | usage |
876 | fi |
877 | |
878 | if [[ -z ${version} ]] |
879 | then |
880 | usage |
881 | fi |
882 | |
883 | if [ "${mode}" != "--install" -a "${makedefault}" ] |
884 | then |
885 | usage |
886 | fi |
887 | |
888 | kernelmajor=$(echo ${kernel} | cut -d . -f 1,2) |
889 | |
890 | [[ ${kernelImage} ]] || kernelImage="${bootPrefix}/${kernelName}-${version}" |
891 | |
892 | # set the initrd file based on arch; ia64 is the only currently known oddball |
893 | if [[ -z ${initrdfile} ]] |
894 | then |
895 | INITRD_NAME_PREFIX="initrd" |
896 | if [[ -n ${dracut} ]] |
897 | then |
898 | INITRD_NAME_PREFIX="initramfs" |
899 | fi |
900 | |
901 | if [[ $(uname -m) = ia64 ]] |
902 | then |
903 | initrdfile="/boot/efi/EFI/redhat/${INITRD_NAME_PREFIX}-${version}.img" |
904 | else |
905 | initrdfile="/boot/${INITRD_NAME_PREFIX}-${version}.img" |
906 | fi |
907 | fi |
908 | [[ -n ${verbose} ]] && echo "initrdfile is ${initrdfile}" |
909 | |
910 | if [[ ${ARCH} =~ armv[5|7].*l ]] |
911 | then |
912 | if [[ -z ${SHIPSDTB} ]] || [[ ${SHIPSDTB} != yes ]] |
913 | then |
914 | if [[ -n ${dtbfile} ]] && [ -f ${bootPrefix}/dtb-${version}/${dtbfile} ] |
915 | then |
916 | devtreefile="${bootPrefix}/dtb-${version}/${dtbfile}" |
917 | [[ -n ${verbose} ]] && echo "devtreefile is ${devtreefile}" |
918 | elif [ -d ${bootPrefix}/dtb-${version}/ ] |
919 | then |
920 | devtreedir="${bootPrefix}/dtb-${version}/" |
921 | [[ -n ${verbose} ]] && echo "devtreedir is ${devtreedir}" |
922 | fi |
923 | fi |
924 | fi |
925 | [[ -n ${verbose} ]] && echo "devtreedir is ${devtreedir}" |
926 | |
927 | # add dracut kernel args if requested |
928 | if [[ -n ${dracut} ]] && [[ -n ${adddracutargs} ]] |
929 | then |
930 | [ -r /etc/vconsole.conf ] && . /etc/vconsole.conf |
931 | [ -r /etc/locale.conf ] && . /etc/locale.conf |
932 | |
933 | while read opt rd_opt |
934 | do |
935 | [ -n "${!opt}" ] && kernargs="$kernargs $rd_opt=\"${!opt}\"" |
936 | done <<< 'KEYMAP rd.vconsole.keymap |
937 | FONT rd.vconsole.font |
938 | FONT_MAP rd.vconsole.font.map |
939 | FONT_UNIMAP rd.vconsole.font.unimap |
940 | UNICODE rd.vconsole.font.unicode |
941 | EXT_KEYMAP rd.vconsole.keymap.ext |
942 | LANG rd.locale.LANG |
943 | LC_ALL rd.locale.LC_ALL' |
944 | fi |
945 | |
946 | # set this as the default if we have the package and it matches |
947 | if [[ ${mode} = --install ]] && [[ ${UPDATEDEFAULT} = yes ]] && [[ -n ${package} ]] && [[ -n ${DEFAULTKERNEL} ]] |
948 | then |
949 | if [[ ${package} = ${DEFAULTKERNEL} ]] || [[ ${package}-core = ${DEFAULTKERNEL} ]] |
950 | then |
951 | makedefault="--make-default" |
952 | [[ -n ${verbose} ]] && echo "making it the default based on config" |
953 | fi |
954 | fi |
955 | |
956 | if [[ ${moddep} = make ]] |
957 | then |
958 | doDepmod |
959 | elif [[ ${moddep} = remove ]] |
960 | then |
961 | doRmmoddep |
962 | fi |
963 | |
964 | if [[ ${initrd} = make ]] |
965 | then |
966 | makeinitrd |
967 | elif [[ ${initrd} = remove ]] |
968 | then |
969 | rminitrd |
970 | fi |
971 | |
972 | if [ ! -x ${grubby} ] |
973 | then |
974 | [[ -n ${verbose} ]] && echo "${grubby} does not exist" |
975 | exit 0 |
976 | fi |
977 | |
978 | [[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1 |
979 | [[ -n ${grub2Config} ]] && [ -f ${grub2Config} ] && cfgGrub2=1 |
980 | [[ -n ${grub2EfiConfig} ]] && [ -f ${grub2EfiConfig} ] && cfgGrub2Efi=1 |
981 | [[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1 |
982 | [[ -n ${extlinuxConfig} ]] && [ -f ${extlinuxConfig} ] && cfgExtlinux=1 |
983 | |
984 | # if we have a U-Boot directory, but no boot script, check if the directory |
985 | # is mounted. If not, mount it, and then check if a boot script exists. |
986 | if [[ -n ${ubootDir} ]] |
987 | then |
988 | if [ -f ${ubootScript} ] |
989 | then |
990 | cfguBoot=1 |
991 | else |
992 | mountEntry=$(mount | grep ${ubootDir}) |
993 | if [[ -z ${mountEntry} ]] |
994 | then |
995 | mount ${ubootDevice} ${ubootDir} |
996 | mounted=1 |
997 | fi |
998 | [ -f ${ubootScript} ] && cfguBoot=1 |
999 | fi |
1000 | fi |
1001 | |
1002 | # if we're using U-Boot, check if the default load address should change |
1003 | if [[ -n ${cfguBoot} ]] && [[ -z ${UBOOT_IMGADDR} ]] |
1004 | then |
1005 | [[ ${version} =~ .([^.]*)$ ]] |
1006 | platform=${BASH_REMATCH[1]} |
1007 | # A few platforms use an alternate kernel load address |
1008 | if [[ ${platform} = omap ]] |
1009 | then |
1010 | ubootAddress=0x80008000 |
1011 | elif [[ ${platform} = imx ]] |
1012 | then |
1013 | ubootAddress=0x90008000 |
1014 | fi |
1015 | fi |
1016 | |
1017 | # if we have a lilo config on an x86 box, see if the default boot loader |
1018 | # is lilo to determine if it should be run |
1019 | if [[ -n ${cfgLilo} ]] && [[ -n ${isx86} ]] |
1020 | then |
1021 | runLilo=$(${grubby} --bootloader-probe | grep lilo) |
1022 | fi |
1023 | |
1024 | if [[ ${mode} = --install ]] |
1025 | then |
1026 | install |
1027 | elif [[ ${mode} = --remove ]] |
1028 | then |
1029 | remove |
1030 | elif [[ ${mode} = --update ]] |
1031 | then |
1032 | update |
1033 | fi |
1034 | |
1035 | # if we mounted the U-Boot directory, unmount it. |
1036 | [[ -n ${mounted} ]] && umount ${ubootDir} |
1037 | |
1038 | # make sure changes make it to the disk. |
1039 | # if /boot is a mountpoint, force the meta data on disk |
1040 | # to by-pass writeback delay. |
1041 | # PPC64LE-only to deal with Petitboot issues |
1042 | if [[ ${ARCH} = ppc64le ]] |
1043 | then |
1044 | sync && mountpoint -q /boot && fsfreeze -f /boot && fsfreeze -u /boot |
1045 | fi |
1046 | |
1047 | exit 0 |
Properties
Name | Value |
---|---|
svn:executable | * |