Magellan Linux

Annotation of /tags/grubby-8_40_20170706/new-kernel-pkg

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2704 - (hide annotations) (download)
Wed Jul 16 10:54:46 2014 UTC (9 years, 9 months ago) by niro
Original Path: trunk/grubby/new-kernel-pkg
File size: 23677 byte(s)
Actually do a fix for rhbz#1082318 that fixes the issue there.
1 niro 532 #!/bin/bash
2 niro 924 # $Id$
3 niro 532 #
4 niro 923 # new-kernel-pkg
5 niro 532 # 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 niro 923 # Copyright 2002-2008 Red Hat, Inc. All rights reserved.
12 niro 532 # modified for Magellan-Linux by Niels Rogalla <niro@magellan-linux.de>
13     #
14 niro 923 # 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 niro 532
28 niro 1778 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 niro 532 PATH=/sbin:/bin:$PATH
55    
56     lilo=/sbin/lilo
57    
58     # some defaults that are sane for most arches
59     kernelName=kernel
60    
61 niro 924 if [ -x ./grubby ]
62     then
63     grubby=./grubby
64 niro 532 else
65 niro 924 grubby=/sbin/grubby
66 niro 532 fi
67    
68 niro 925 [ -f /etc/conf.d/grubby ] && . /etc/conf.d/grubby
69 niro 1691 [ -f /etc/conf.d/grubby-uboot ] && . /etc/conf.d/grubby-uboot
70 niro 532
71 niro 1697 cfgGrub2=""
72     cfgGrub2Efi=""
73 niro 532 cfgGrub=""
74     cfgLilo=""
75 niro 1716 cfgExtlinux=""
76 niro 1691 cfguBoot=""
77 niro 532 runLilo=""
78     grubConfig=""
79 niro 1702 grub2Config=""
80     grub2EfiConfig=""
81 niro 1716 extlinuxConfig=""
82 niro 532
83     ARCH=$(uname -m)
84    
85 niro 924 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 niro 1803 grub2Config=/boot/grub/grub.cfg
95 niro 924 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 niro 1848 elif [[ ${ARCH} =~ armv[5|7].*l ]]
116 niro 1691 then
117     liloConfig=""
118     bootPrefix=/boot
119 niro 2259 extlinuxConfig=$(readlink -f /etc/extlinux.conf 2>/dev/null)
120 niro 1847 ubootDir=${UBOOT_DIR:-"/boot"}
121 niro 1691 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 niro 1937 ubootAddress=${UBOOT_IMGADDR:-"0x00008000"}
127 niro 1691 mounted=""
128     liloFlag=""
129     isx86=""
130 niro 532 else
131 niro 924 # this leaves i?86 and x86_64
132     liloConfig=/etc/lilo.conf
133     grubConfig=/boot/grub/grub.conf
134 niro 1697 grub2Config=/boot/grub/grub.cfg
135     grub2EfiConfig=/boot/grub/grub-efi.cfg
136 niro 1716 extlinuxConfig=/boot/extlinux/extlinux.conf
137 niro 924 bootPrefix=/boot
138     liloFlag=lilo
139     isx86="yes"
140 niro 532 fi
141    
142     mode=""
143     version=""
144     initrd=""
145 niro 1334 dracut=""
146     dracuthostonly=""
147 niro 532 initrdfile=""
148 niro 2685 devtreefile=""
149 niro 532 moddep=""
150     verbose=""
151     makedefault=""
152     package=""
153 niro 1706 mbkernel="${HYPERVISOR}"
154     mbargs="${HYPERVISOR_ARGS}"
155 niro 1334 adddracutargs=""
156     addplymouthinitrd=""
157 niro 532
158 niro 924 usage()
159     {
160 niro 1334 echo "Usage: $(basename $0) [-v] [--mkinitrd] [--rminitrd] [--dracut]" >&2
161 niro 924 echo " [--initrdfile=<initrd-image>] [--depmod] [--rmmoddep]" >&2
162 niro 1305 echo " [--kernel-args=<args>] [--remove-args=<args>]" >&2
163 niro 924 echo " [--banner=<banner>] [--multiboot=multiboot]" >&2
164 niro 1334 echo " [--mbargs=mbargs] [--make-default] [--add-dracut-args]" >&2
165     echo " [--add-plymouth-initrd]" >&2
166 niro 2685 echo " [--host-only] [--devtree=<devicetree.dtb>]" >&2
167 niro 924 echo " <--install | --remove | --update> <kernel-version>" >&2
168     echo " (ex: $(basename $0) --mkinitrd --depmod --install 2.4.7-2)" >&2
169     exit 1
170 niro 532 }
171    
172 niro 924 install()
173     {
174     # XXX kernel should be able to be specified also (or work right on ia64)
175 niro 2241 if [ ! -f ${kernelImage} ]
176 niro 924 then
177     [[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby"
178     return
179     fi
180 niro 923
181 niro 924 INITRD=""
182     if [ -f ${initrdfile} ]
183     then
184     [[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby"
185     INITRD="--initrd ${initrdfile}"
186 niro 1334
187     if [[ -n ${addplymouthinitrd} ]]
188     then
189     INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img"
190     fi
191 niro 924 fi
192 niro 532
193 niro 2685 DEVTREE=""
194 niro 2704 if [[ x${devtreefile} != x ]] && [ -f "${devtreefile}" ]
195 niro 2685 then
196     [[ -n ${verbose} ]] && echo "found ${devtreefile} and using it with grubby"
197     DEVTREE="--devtree ${devtreefile}"
198     fi
199    
200 niro 924 # 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 niro 2241 /sbin/addSystemMap ${bootPrefix}/System.map-${version} ${kernelImage} ${bootPrefix}/vmlinitrd-${version}
208 niro 924 else
209 niro 2241 /sbin/addSystemMap ${bootPrefix}/System.map-${version} ${kernelImage} ${bootPrefix}/vmlinux.sm-${version}
210 niro 924 /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 niro 532 fi
215    
216 niro 924 # get the root filesystem to use
217 niro 2238 rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab 2>/dev/null)
218 niro 2237 if [[ -z $rootdevice ]]
219     then
220     rootdevice=$(grep -o -P "(?<=root=)\S+" /proc/cmdline)
221     fi
222 niro 532
223 niro 924 if [[ -n ${mbkernel} ]] && [[ -n ${cfgLilo} ]] && [[ ${liloFlag} != elilo ]]
224     then
225     [[ -n ${verbose} ]] && echo "multiboot specified, not updating lilo.conf"
226     cfgLilo=""
227     fi
228 niro 532
229 niro 2239 if [[ -n ${banner} ]]
230     then
231 niro 2684 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 niro 2681 elif [ -f /etc/os-release ]
241 niro 2239 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 niro 924 if [[ -n ${cfgGrub} ]]
251     then
252     [[ -n ${verbose} ]] && echo "adding ${version} to ${grubConfig}"
253 niro 532
254 niro 1710 ${grubby} --grub -c ${grubConfig} \
255 niro 2241 --add-kernel=${kernelImage} \
256 niro 924 ${INITRD} --copy-default ${makedefault} --title "${title}" \
257     ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \
258     --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
259 niro 532 else
260 niro 1697 [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97"
261 niro 532 fi
262 niro 1697 if [[ -n ${cfgGrub2} ]]
263     then
264     [[ -n ${verbose} ]] && echo "adding ${version} to ${grub2Config}"
265 niro 532
266 niro 1702 ${grubby} --grub2 -c ${grub2Config} \
267 niro 2241 --add-kernel=${kernelImage} \
268 niro 1697 ${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 niro 1940 ${grubby} --grub2 -c ${grub2EfiConfig} --efi \
280 niro 2686 --add-kernel=${kernelImage} ${DEVTREE} \
281 niro 1697 ${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 niro 924 if [[ -n ${cfgLilo} ]]
290     then
291     [[ -n ${verbose} ]] && echo "adding ${version} to ${liloConfig}"
292 niro 532
293 niro 2241 ${grubby} --add-kernel=${kernelImage} ${INITRD} \
294 niro 2684 --copy-default ${makedefault} --title "${title}" \
295 niro 924 ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \
296     --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${version}" \
297     --${liloFlag}
298 niro 532
299 niro 924 if [[ -n ${runLilo} ]]
300     then
301     [[ -n ${verbose} ]] && echo "running ${lilo}"
302 niro 1305 if [ ! -x ${lilo} ]
303 niro 924 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 niro 532 fi
312 niro 1716
313     if [[ -n ${cfgExtlinux} ]]
314     then
315     [[ -n ${verbose} ]] && echo "adding ${version} to ${extlinuxConfig}"
316    
317     ${grubby} --extlinux -c ${extlinuxConfig} \
318 niro 2241 --add-kernel=${kernelImage} \
319 niro 1716 ${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 niro 532 }
326    
327 niro 924 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 niro 2241 rm -f ${kernelImage}.img 2>/dev/null
334 niro 924 return
335     fi
336 niro 532
337 niro 924 if [[ -n ${cfgGrub} ]]
338     then
339     [[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}"
340 niro 1710 ${grubby} --grub -c ${grubConfig} \
341 niro 2241 --remove-kernel=${kernelImage}
342 niro 924 else
343 niro 1697 [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97"
344 niro 924 fi
345 niro 1697 if [[ -n ${cfgGrub2} ]]
346     then
347     [[ -n ${verbose} ]] && echo "removing ${version} from ${grub2Config}"
348     ${grubby} --grub2 -c ${grub2Config} \
349 niro 2241 --remove-kernel=${kernelImage}
350 niro 1697 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 niro 2051 ${grubby} --grub2 -c ${grub2EfiConfig} --efi \
357 niro 2241 --remove-kernel=${kernelImage}
358 niro 1697 else
359     [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby grub 2 with UEFI"
360     fi
361 niro 532
362 niro 924 if [[ -n ${cfgLilo} ]]
363     then
364     [[ -n ${verbose} ]] && echo "removing ${version} from ${liloConfig}"
365 niro 2241 ${grubby} --remove-kernel=${kernelImage} --${liloFlag}
366 niro 532
367 niro 924 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 niro 532 fi
380 niro 1691
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 niro 1847 sed "/$version$/d" ${ubootDir}/${ubootKList} > ${tmpKList}
390 niro 1691 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 niro 2248 [ -x /sbin/a-b-c ] && /sbin/a-b-c
425 niro 1691 else
426     [[ -n ${verbose} ]] && echo "uImage ${newversion} does not exist!"
427     [ -f ${tmpKList} ] && rm -f ${tmpKList}
428     fi
429     else
430 niro 1752 [[ -n ${verbose} ]] && echo "No previous kernel version. U-Boot images not removed!"
431 niro 1691 fi
432     else
433     [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}"
434     fi
435 niro 1716
436     if [[ -n ${cfgExtlinux} ]]
437     then
438     [[ -n ${verbose} ]] && echo "removing ${version} from ${extlinuxConfig}"
439     ${grubby} --extlinux -c ${extlinuxConfig} \
440 niro 2241 --remove-kernel=${kernelImage}
441 niro 1716 else
442     [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux"
443     fi
444 niro 532 }
445    
446 niro 924 update()
447     {
448 niro 2241 if [ ! -f ${kernelImage} ]
449 niro 1305 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 niro 1334
460     if [[ -n ${addplymouthinitrd} ]]
461     then
462     INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img"
463     fi
464 niro 1305 fi
465    
466 niro 924 if [[ -n ${cfgGrub} ]]
467     then
468     [[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}"
469 niro 1710 ${grubby} --grub -c ${grubConfig} \
470 niro 2241 --update-kernel=${kernelImage} \
471 niro 1305 ${INITRD} \
472 niro 924 ${kernargs:+--args="${kernargs}"} \
473 niro 2263 ${removeargs:+--remove-args="${removeargs}"} \
474     ${mbkernel:+--add-multiboot="${mbkernel}"}
475 niro 924 else
476     [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"
477     fi
478 niro 923
479 niro 1697 if [[ -n ${cfgGrub2} ]]
480     then
481     [[ -n ${verbose} ]] && echo "updating ${version} from ${grub2Config}"
482     ${grubby} --grub2 -c ${grub2Config} \
483 niro 2241 --update-kernel=${kernelImage} \
484 niro 1697 ${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 niro 2051 ${grubby} --grub2 -c ${grub2EfiConfig} --efi \
495 niro 2241 --update-kernel=${kernelImage} \
496 niro 1697 ${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 niro 924 if [[ -n ${cfgLilo} ]]
504     then
505     [[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}"
506 niro 2241 ${grubby} --update-kernel=${kernelImage} \
507 niro 1305 ${INITRD} \
508 niro 924 ${kernargs:+--args="${kernargs}"} \
509     ${removeargs:+--remove-args="${removeargs}"} \
510     --${liloFlag}
511 niro 923
512 niro 924 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 niro 923 fi
525 niro 1691
526     if [[ -n ${cfguBoot} ]]
527     then
528     [[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..."
529    
530     [[ -n ${verbose} ]] && echo "creating uImage-${version}"
531 niro 1752 mkimage -A arm -O linux -T kernel -C none -a ${ubootAddress} \
532     -e ${ubootAddress} -n ${version} \
533 niro 2241 -d ${kernelImage} ${ubootDir}/uImage-${version}
534 niro 1691
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 niro 2248 [ -x /sbin/a-b-c ] && /sbin/a-b-c
553 niro 1691 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 niro 1716
560     if [[ -n ${cfgExtlinux} ]]
561     then
562     [[ -n ${verbose} ]] && echo "updating ${version} from ${extlinuxConfig}"
563     ${grubby} --extlinux -c ${extlinuxConfig} \
564 niro 2241 --update-kernel=${kernelImage} \
565 niro 1716 ${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 niro 923 }
572    
573 niro 1756 makeinitrd()
574 niro 924 {
575 niro 1334 if [[ -n ${dracut} ]]
576     then
577 niro 1728 tool="dracut ${dracuthostonly} -f ${initrdfile} ${version}"
578 niro 1334 else
579 niro 1749 tool="mkinitrd --allow-missing -f ${initrdfile} ${version}"
580 niro 1334 fi
581 niro 924 [[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}"
582 niro 1334 ${tool}
583 niro 924 rc=$?
584     if [ ${rc} != 0 ]
585     then
586     echo "mkinitrd failed" >&2
587     exit 1
588     fi
589 niro 532 }
590    
591 niro 924 rminitrd()
592     {
593     [[ -n ${verbose} ]] && echo "removing initrd ${initrdfile}"
594     [ -f ${initrdfile} ] && rm -f ${initrdfile}
595 niro 532 }
596    
597 niro 924 doDepmod()
598     {
599     [[ -n ${verbose} ]] && echo "running depmod for ${version}"
600     depmod -ae -F /boot/System.map-${version} ${version}
601 niro 532 }
602    
603 niro 924 doRmmoddep()
604     {
605     [[ -n ${verbose} ]] && echo "removing modules.dep info for ${version}"
606 niro 2242 if [ -d /lib/modules/${version} ]
607     then
608     rm -f /lib/modules/${version}/modules.*.bin \
609 niro 2244 /lib/modules/${version}/modules.{alias,dep,devname,symbols,softdep}
610 niro 2242 fi
611 niro 532 }
612    
613    
614 niro 924 while [ $# -gt 0 ]
615     do
616     case $1 in
617     --mkinitrd)
618     initrd="make"
619     ;;
620 niro 532
621 niro 924 --rminitrd)
622     initrd="remove"
623     ;;
624 niro 532
625 niro 2685 --devtree*)
626     if [[ $1 == --devtree\=* ]]
627     then
628     devtreefile="${1#--devtreefile=}"
629     else
630     devtreefile="$2"
631     shift
632     fi
633     ;;
634    
635 niro 1334 --dracut)
636     dracut=--dracut
637     ;;
638    
639     --host-only)
640     dracuthostonly=-H
641     ;;
642    
643 niro 924 --initrdfile*)
644 niro 2240 if [[ $1 == --initrdfile\=* ]]
645 niro 924 then
646 niro 2240 initrdfile=${1#--initrdfile=}
647 niro 924 else
648     initrdfile=$2
649     shift
650     fi
651     ;;
652 niro 532
653 niro 924 --kernel-args*)
654 niro 2240 if [[ $1 == --kernel-args\=* ]]
655 niro 924 then
656 niro 2240 kernargs=${1#--kernel-args=}
657 niro 924 else
658     kernargs=$2
659     shift
660     fi
661     ;;
662 niro 532
663 niro 924 --remove-args*)
664 niro 2240 if [[ $1 == --remove-args\=* ]]
665 niro 924 then
666 niro 2240 removeargs=${1#--remove-args=}
667 niro 924 else
668     removeargs=$2
669     shift
670     fi
671     ;;
672 niro 923
673 niro 924 --banner*)
674 niro 2240 if [[ $1 == --banner\=* ]]
675 niro 924 then
676 niro 2240 banner=${1#--banner=}
677 niro 924 else
678     banner=$2
679     shift
680     fi
681     ;;
682 niro 532
683 niro 924 --multiboot*)
684 niro 2240 if [[ $1 == --multiboot\=* ]]
685 niro 924 then
686 niro 2240 mbkernel=${1#--multiboot=}
687 niro 924 else
688     # can't really support having an optional second arg here
689     # sorry!
690     mbkernel="/boot/xen.gz"
691     fi
692     ;;
693 niro 532
694 niro 924 --mbargs*)
695 niro 2240 if [[ $1 == --mbargs\=* ]]
696 niro 924 then
697 niro 2240 mbargs=${1#--mbargs=}
698 niro 924 else
699     mbargs="$2"
700     shift
701     fi
702     ;;
703 niro 532
704 niro 924 --depmod)
705     moddep="make"
706     ;;
707 niro 532
708 niro 924 --rmmoddep)
709     moddep="remove"
710     ;;
711 niro 532
712 niro 924 --make-default)
713     makedefault="--make-default"
714     ;;
715 niro 532
716 niro 2240 --package*)
717     if [[ $1 == --package\=* ]]
718 niro 924 then
719 niro 2240 package=${1#--package=}
720 niro 924 else
721     package=$2
722     shift
723     fi
724     ;;
725 niro 532
726 niro 1334 --add-dracut-args)
727     adddracutargs=--add-dracut-args
728     ;;
729    
730     --add-plymouth-initrd)
731     addplymouthinitrd=--add-plymouth-initrd
732     ;;
733    
734 niro 2241 --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 niro 924 -v)
751     verbose=-v
752     ;;
753 niro 532
754 niro 924 *)
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 niro 532
767 niro 924 shift
768 niro 532 done
769    
770     # make sure the mode is valid
771 niro 924 if [[ ${mode} != --install ]] && [[ ${mode} != --remove ]] && [[ ${mode} != --update ]]
772     then
773     usage
774 niro 532 fi
775    
776 niro 924 if [[ -z ${version} ]]
777     then
778     usage
779 niro 532 fi
780    
781 niro 924 if [ "${mode}" != "--install" -a "${makedefault}" ]
782     then
783     usage
784 niro 532 fi
785    
786 niro 924 kernelmajor=$(echo ${kernel} | cut -d . -f 1,2)
787 niro 532
788 niro 1305 # kernel image for 2.4 is kernel
789 niro 924 if [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]]
790     then
791     if [[ ${kernelmajor} = 2.4 ]]
792     then
793     kernelName=kernel
794     fi
795 niro 532 fi
796    
797 niro 2241 [[ ${kernelImage} ]] || kernelImage="${bootPrefix}/${kernelName}-${version}"
798    
799 niro 532 # set the initrd file based on arch; ia64 is the only currently known oddball
800 niro 924 if [[ -z ${initrdfile} ]]
801     then
802     INITRD_NAME_PREFIX="initrd"
803 niro 1334 if [[ -n ${dracut} ]]
804     then
805     INITRD_NAME_PREFIX="initramfs"
806     fi
807 niro 923
808 niro 924 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 niro 532 fi
815 niro 924 [[ -n ${verbose} ]] && echo "initrdfile is ${initrdfile}"
816 niro 532
817 niro 1334 # add dracut i18n, keyboard and plymouth kernel args if requested
818     if [[ -n ${dracut} ]] || [[ -n ${adddracutargs} ]]
819     then
820 niro 2059 if [ -r /etc/vconsole.conf ]
821     then
822     . /etc/vconsole.conf
823 niro 1334
824 niro 2059 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 niro 1334 fi
850    
851 niro 2059 if [ -r /etc/locale.conf ]
852 niro 1334 then
853 niro 2059 . /etc/locale.conf
854    
855     if [[ -n ${LANG} ]]
856     then
857     kernargs="${kernargs} LANG=${LANG}"
858     fi
859 niro 1334 fi
860     fi
861    
862 niro 532 # set this as the default if we have the package and it matches
863 niro 924 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 niro 532 fi
869    
870 niro 924 if [[ ${moddep} = make ]]
871     then
872     doDepmod
873     elif [[ ${moddep} = remove ]]
874     then
875     doRmmoddep
876 niro 532 fi
877    
878 niro 924 if [[ ${initrd} = make ]]
879     then
880 niro 1756 makeinitrd
881 niro 924 elif [[ ${initrd} = remove ]]
882     then
883     rminitrd
884 niro 532 fi
885    
886 niro 924 if [ ! -x ${grubby} ]
887     then
888     [[ -n ${verbose} ]] && echo "${grubby} does not exist"
889     exit 0
890 niro 532 fi
891    
892 niro 924 [[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1
893 niro 1697 [[ -n ${grub2Config} ]] && [ -f ${grub2Config} ] && cfgGrub2=1
894     [[ -n ${grub2EfiConfig} ]] && [ -f ${grub2EfiConfig} ] && cfgGrub2Efi=1
895 niro 924 [[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1
896 niro 1716 [[ -n ${extlinuxConfig} ]] && [ -f ${extlinuxConfig} ] && cfgExtlinux=1
897 niro 532
898 niro 1752 # 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 niro 1691 if [[ -n ${ubootDir} ]]
901     then
902 niro 1752 if [ -f ${ubootScript} ]
903 niro 1691 then
904 niro 1752 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 niro 1691 fi
914     fi
915    
916 niro 1937 # 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 niro 532 # 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 niro 924 if [[ -n ${cfgLilo} ]] && [[ -n ${isx86} ]]
934     then
935     runLilo=$(${grubby} --bootloader-probe | grep lilo)
936 niro 532 fi
937    
938 niro 924 if [[ ${mode} = --install ]]
939     then
940     install
941     elif [[ ${mode} = --remove ]]
942     then
943     remove
944     elif [[ ${mode} = --update ]]
945     then
946     update
947 niro 532 fi
948    
949 niro 1752 # if we mounted the U-Boot directory, unmount it.
950     [[ -n ${mounted} ]] && umount ${ubootDir}
951    
952 niro 532 exit 0

Properties

Name Value
svn:executable *