Magellan Linux

Contents of /tags/grubby-8_34/new-kernel-pkg

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *