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