Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *