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