Contents of /tags/mkinitrd-6_3_0/grubby/new-kernel-pkg
Parent Directory
|
Revision Log
Revision 1139 -
(show annotations)
(download)
Thu Aug 19 10:14:02 2010 UTC (13 years, 9 months ago) by niro
File size: 11655 byte(s)
Thu Aug 19 10:14:02 2010 UTC (13 years, 9 months ago) by niro
File size: 11655 byte(s)
tagged 'mkinitrd-6_3_0'
1 | #!/bin/bash |
2 | # $Id$ |
3 | # |
4 | # new-kernel-pkg |
5 | # Invoked upon installation or removal of a kernel package, the following |
6 | # tasks are/can be done here: |
7 | # creation/removal of initrd |
8 | # run of depmod/removal of depmod generated files |
9 | # addition/removal of kernel images from grub/lilo configuration (via grubby) |
10 | # |
11 | # Copyright 2002-2008 Red Hat, Inc. All rights reserved. |
12 | # modified for Magellan-Linux by Niels Rogalla <niro@magellan-linux.de> |
13 | # |
14 | # This program is free software; you can redistribute it and/or modify |
15 | # it under the terms of the GNU General Public License as published by |
16 | # the Free Software Foundation; either version 2 of the License, or |
17 | # (at your option) any later version. |
18 | # |
19 | # This program is distributed in the hope that it will be useful, |
20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | # GNU General Public License for more details. |
23 | # |
24 | # You should have received a copy of the GNU General Public License |
25 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
26 | # |
27 | |
28 | PATH=/sbin:/bin:$PATH |
29 | |
30 | lilo=/sbin/lilo |
31 | |
32 | # some defaults that are sane for most arches |
33 | kernelName=kernel |
34 | |
35 | if [ -x ./grubby ] |
36 | then |
37 | grubby=./grubby |
38 | else |
39 | grubby=/sbin/grubby |
40 | fi |
41 | |
42 | [ -f /etc/conf.d/grubby ] && . /etc/conf.d/grubby |
43 | |
44 | cfgGrub="" |
45 | cfgLilo="" |
46 | runLilo="" |
47 | grubConfig="" |
48 | |
49 | ARCH=$(uname -m) |
50 | |
51 | if [[ ${ARCH} = ia64 ]] |
52 | then |
53 | liloConfig=/boot/efi/EFI/redhat/elilo.conf |
54 | bootPrefix=/boot/efi/EFI/redhat |
55 | liloFlag=elilo |
56 | isx86="" |
57 | elif [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]] |
58 | then |
59 | liloConfig=/etc/yaboot.conf |
60 | bootPrefix=/boot |
61 | lilo=/sbin/ybin |
62 | liloFlag=yaboot |
63 | runLilo="yes" |
64 | isx86="" |
65 | elif [[ ${ARCH} = sparc ]] || [[ ${ARCH} = sparc64 ]] |
66 | then |
67 | liloConfig=/etc/silo.conf |
68 | bootPrefix=/boot |
69 | liloFlag=silo |
70 | lilo=/sbin/silo |
71 | isx86="" |
72 | elif [[ ${ARCH} = s390 ]] || [[ ${ARCH} = s390x ]] |
73 | then |
74 | liloConfig=/etc/zipl.conf |
75 | bootPrefix=/boot |
76 | liloFlag=zipl |
77 | lilo=/sbin/zipl |
78 | runLilo="yes" |
79 | isx86="" |
80 | else |
81 | # this leaves i?86 and x86_64 |
82 | liloConfig=/etc/lilo.conf |
83 | grubConfig=/boot/grub/grub.conf |
84 | bootPrefix=/boot |
85 | liloFlag=lilo |
86 | isx86="yes" |
87 | fi |
88 | |
89 | mode="" |
90 | version="" |
91 | initrd="" |
92 | initrdfile="" |
93 | moddep="" |
94 | verbose="" |
95 | makedefault="" |
96 | package="" |
97 | mbkernel="" |
98 | mbargs="" |
99 | |
100 | usage() |
101 | { |
102 | echo "Usage: $(basename $0) [-v] [--mkinitrd] [--rminitrd]" >&2 |
103 | echo " [--initrdfile=<initrd-image>] [--depmod] [--rmmoddep]" >&2 |
104 | echo " [--kernel-args=<args>] [--remove-args=<args>]" >&2 |
105 | echo " [--banner=<banner>] [--multiboot=multiboot]" >&2 |
106 | echo " [--mbargs=mbargs] [--make-default]" >&2 |
107 | echo " <--install | --remove | --update> <kernel-version>" >&2 |
108 | echo " (ex: $(basename $0) --mkinitrd --depmod --install 2.4.7-2)" >&2 |
109 | exit 1 |
110 | } |
111 | |
112 | install() |
113 | { |
114 | # XXX kernel should be able to be specified also (or work right on ia64) |
115 | if [ ! -f ${bootPrefix}/${kernelName}-${version} ] |
116 | then |
117 | [[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby" |
118 | return |
119 | fi |
120 | |
121 | INITRD="" |
122 | if [ -f ${initrdfile} ] |
123 | then |
124 | [[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby" |
125 | INITRD="--initrd ${initrdfile}" |
126 | fi |
127 | |
128 | # FIXME: is this a good heuristic to find out if we're on iSeries? |
129 | if [ -d /proc/iSeries ] |
130 | then |
131 | [[ -n ${verbose} ]] && echo "On an iSeries, just making img file" |
132 | if [[ -z ${initrdfile} ]] |
133 | then |
134 | [[ -n ${verbose} ]] && echo "No initrd, just adding system map" |
135 | /sbin/addSystemMap ${bootPrefix}/System.map-${version} ${bootPrefix}/${kernelName}-${version} ${bootPrefix}/vmlinitrd-${version} |
136 | else |
137 | /sbin/addSystemMap ${bootPrefix}/System.map-${version} ${bootPrefix}/${kernelName}-${version} ${bootPrefix}/vmlinux.sm-${version} |
138 | /sbin/addRamDisk ${initrdfile} ${bootPrefix}/System.map-${version} ${bootPrefix}/vmlinux.sm-${version} ${bootPrefix}/vmlinitrd-${version} 2>/dev/null |
139 | rm ${bootPrefix}/vmlinux.sm-${version} |
140 | fi |
141 | return |
142 | fi |
143 | |
144 | # get the root filesystem to use |
145 | rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab) |
146 | |
147 | if [[ -n ${mbkernel} ]] && [[ -n ${cfgLilo} ]] && [[ ${liloFlag} != elilo ]] |
148 | then |
149 | [[ -n ${verbose} ]] && echo "multiboot specified, not updating lilo.conf" |
150 | cfgLilo="" |
151 | fi |
152 | |
153 | if [[ -n ${cfgGrub} ]] |
154 | then |
155 | [[ -n ${verbose} ]] && echo "adding ${version} to ${grubConfig}" |
156 | |
157 | if [[ -n ${banner} ]] |
158 | then |
159 | title="${banner} (${version})" |
160 | elif [ -f /etc/mageversion ] |
161 | then |
162 | title="Magellan Linux $(< /etc/mageversion) (${version})" |
163 | else |
164 | title="Magellan Linux (${version})" |
165 | fi |
166 | ${grubby} --add-kernel=${bootPrefix}/${kernelName}-${version} \ |
167 | ${INITRD} --copy-default ${makedefault} --title "${title}" \ |
168 | ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \ |
169 | --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}" |
170 | else |
171 | [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby" |
172 | fi |
173 | |
174 | if [[ -n ${cfgLilo} ]] |
175 | then |
176 | [[ -n ${verbose} ]] && echo "adding ${version} to ${liloConfig}" |
177 | |
178 | ${grubby} --add-kernel=${bootPrefix}/${kernelName}-${version} ${INITRD} \ |
179 | --copy-default ${makedefault} --title ${version} \ |
180 | ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \ |
181 | --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${version}" \ |
182 | --${liloFlag} |
183 | |
184 | if [[ -n ${runLilo} ]] |
185 | then |
186 | [[ -n ${verbose} ]] && echo "running ${lilo}" |
187 | if [ ! -x $lilo ] |
188 | then |
189 | [[ -n ${verbose} ]] && echo "${lilo} does not exist" |
190 | else |
191 | ${lilo} > /dev/null |
192 | fi |
193 | fi |
194 | else |
195 | [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
196 | fi |
197 | } |
198 | |
199 | remove() |
200 | { |
201 | # FIXME: is this a good heuristic to find out if we're on iSeries? |
202 | if [ -d /proc/iSeries ] |
203 | then |
204 | [[ -n ${verbose} ]] && echo "On an iSeries, remove img file" |
205 | rm -f ${bootPrefix}/${kernelName}-${version}.img 2>/dev/null |
206 | return |
207 | fi |
208 | |
209 | if [[ -n ${cfgGrub} ]] |
210 | then |
211 | [[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}" |
212 | ${grubby} --remove-kernel=${bootPrefix}/${kernelName}-${version} |
213 | else |
214 | [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby" |
215 | fi |
216 | |
217 | if [[ -n ${cfgLilo} ]] |
218 | then |
219 | [[ -n ${verbose} ]] && echo "removing ${version} from ${liloConfig}" |
220 | ${grubby} --remove-kernel=${bootPrefix}/${kernelName}-${version} \ |
221 | --${liloFlag} |
222 | |
223 | if [[ -n ${runLilo} ]] |
224 | then |
225 | [[ -n ${verbose} ]] && echo "running ${lilo}" |
226 | if [ ! -x ${lilo} ] |
227 | then |
228 | [[ -n ${verbose} ]] && echo "${lilo} does not exist" |
229 | else |
230 | ${lilo} > /dev/null |
231 | fi |
232 | fi |
233 | else |
234 | [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
235 | fi |
236 | } |
237 | |
238 | update() |
239 | { |
240 | if [[ -n ${cfgGrub} ]] |
241 | then |
242 | [[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}" |
243 | ${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \ |
244 | ${kernargs:+--args="${kernargs}"} \ |
245 | ${removeargs:+--remove-args="${removeargs}"} |
246 | else |
247 | [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby" |
248 | fi |
249 | |
250 | if [[ -n ${cfgLilo} ]] |
251 | then |
252 | [[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}" |
253 | ${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \ |
254 | ${kernargs:+--args="${kernargs}"} \ |
255 | ${removeargs:+--remove-args="${removeargs}"} \ |
256 | --${liloFlag} |
257 | |
258 | if [[ -n ${runLilo} ]] |
259 | then |
260 | [[ -n ${verbose} ]] && echo "running ${lilo}" |
261 | if [ ! -x ${lilo} ] |
262 | then |
263 | [[ -n ${verbose} ]] && echo "${lilo} does not exist" |
264 | else |
265 | ${lilo} > /dev/null |
266 | fi |
267 | fi |
268 | else |
269 | [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
270 | fi |
271 | } |
272 | |
273 | mkinitrd() |
274 | { |
275 | [[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}" |
276 | /sbin/mkinitrd --allow-missing -f ${initrdfile} ${version} |
277 | rc=$? |
278 | if [ ${rc} != 0 ] |
279 | then |
280 | echo "mkinitrd failed" >&2 |
281 | exit 1 |
282 | fi |
283 | } |
284 | |
285 | rminitrd() |
286 | { |
287 | [[ -n ${verbose} ]] && echo "removing initrd ${initrdfile}" |
288 | [ -f ${initrdfile} ] && rm -f ${initrdfile} |
289 | } |
290 | |
291 | doDepmod() |
292 | { |
293 | [[ -n ${verbose} ]] && echo "running depmod for ${version}" |
294 | depmod -ae -F /boot/System.map-${version} ${version} |
295 | } |
296 | |
297 | doRmmoddep() |
298 | { |
299 | [[ -n ${verbose} ]] && echo "removing modules.dep info for ${version}" |
300 | [ -d /lib/modules/${version} ] && rm -f /lib/modules/${version}/modules.* |
301 | } |
302 | |
303 | |
304 | while [ $# -gt 0 ] |
305 | do |
306 | case $1 in |
307 | --mkinitrd) |
308 | initrd="make" |
309 | ;; |
310 | |
311 | --rminitrd) |
312 | initrd="remove" |
313 | ;; |
314 | |
315 | --initrdfile*) |
316 | if echo $1 | grep '=' >/dev/null |
317 | then |
318 | initrdfile=$(echo $1 | sed 's/^--initrdfile=//') |
319 | else |
320 | initrdfile=$2 |
321 | shift |
322 | fi |
323 | ;; |
324 | |
325 | --kernel-args*) |
326 | if echo $1 | grep '=' >/dev/null |
327 | then |
328 | kernargs=$(echo $1 | sed 's/^--kernel-args=//') |
329 | else |
330 | kernargs=$2 |
331 | shift |
332 | fi |
333 | ;; |
334 | |
335 | --remove-args*) |
336 | if echo $1 | grep '=' >/dev/null |
337 | then |
338 | removeargs=$(echo $1 | sed 's/^--remove-args=//') |
339 | else |
340 | removeargs=$2 |
341 | shift |
342 | fi |
343 | ;; |
344 | |
345 | --banner*) |
346 | if echo $1 | grep '=' >/dev/null |
347 | then |
348 | banner=$(echo $1 | sed 's/^--banner=//') |
349 | else |
350 | banner=$2 |
351 | shift |
352 | fi |
353 | ;; |
354 | |
355 | --multiboot*) |
356 | if echo $1 |grep '=' >/dev/null |
357 | then |
358 | mbkernel=$(echo $1 | sed 's/^--multiboot=//') |
359 | else |
360 | # can't really support having an optional second arg here |
361 | # sorry! |
362 | mbkernel="/boot/xen.gz" |
363 | fi |
364 | ;; |
365 | |
366 | --mbargs*) |
367 | if echo $1 |grep '=' >/dev/null |
368 | then |
369 | mbargs=$(echo $1 | sed 's/^--mbargs=//') |
370 | else |
371 | mbargs="$2" |
372 | shift |
373 | fi |
374 | ;; |
375 | |
376 | --depmod) |
377 | moddep="make" |
378 | ;; |
379 | |
380 | --rmmoddep) |
381 | moddep="remove" |
382 | ;; |
383 | |
384 | --make-default) |
385 | makedefault="--make-default" |
386 | ;; |
387 | |
388 | --package) |
389 | if echo $1 | grep '=' >/dev/null |
390 | then |
391 | package=$(echo $1 | sed 's/^--package=//') |
392 | else |
393 | package=$2 |
394 | shift |
395 | fi |
396 | ;; |
397 | |
398 | -v) |
399 | verbose=-v |
400 | ;; |
401 | |
402 | *) |
403 | if [[ -z ${mode} ]] |
404 | then |
405 | mode=$1 |
406 | elif [[ -z ${version} ]] |
407 | then |
408 | version=$1 |
409 | else |
410 | usage |
411 | fi |
412 | ;; |
413 | esac |
414 | |
415 | shift |
416 | done |
417 | |
418 | # make sure the mode is valid |
419 | if [[ ${mode} != --install ]] && [[ ${mode} != --remove ]] && [[ ${mode} != --update ]] |
420 | then |
421 | usage |
422 | fi |
423 | |
424 | if [[ -z ${version} ]] |
425 | then |
426 | usage |
427 | fi |
428 | |
429 | if [ "${mode}" != "--install" -a "${makedefault}" ] |
430 | then |
431 | usage |
432 | fi |
433 | |
434 | kernelmajor=$(echo ${kernel} | cut -d . -f 1,2) |
435 | |
436 | # kernel image for 2.4 is vmlinux |
437 | if [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]] |
438 | then |
439 | if [[ ${kernelmajor} = 2.4 ]] |
440 | then |
441 | kernelName=kernel |
442 | fi |
443 | fi |
444 | |
445 | # set the initrd file based on arch; ia64 is the only currently known oddball |
446 | if [[ -z ${initrdfile} ]] |
447 | then |
448 | INITRD_NAME_PREFIX="initrd" |
449 | |
450 | if [[ $(uname -m) = ia64 ]] |
451 | then |
452 | initrdfile="/boot/efi/EFI/redhat/${INITRD_NAME_PREFIX}-${version}.img" |
453 | else |
454 | initrdfile="/boot/${INITRD_NAME_PREFIX}-${version}.img" |
455 | fi |
456 | fi |
457 | [[ -n ${verbose} ]] && echo "initrdfile is ${initrdfile}" |
458 | |
459 | # set this as the default if we have the package and it matches |
460 | if [[ ${mode} = --install ]] && [[ ${UPDATEDEFAULT} = yes ]] && [[ -n ${package} ]] && |
461 | [[ -n ${DEFAULTKERNEL} ]] && [[ ${package} = ${DEFAULTKERNEL} ]] |
462 | then |
463 | makedefault="--make-default" |
464 | [[ -n ${verbose} ]] && echo "making it the default based on config" |
465 | fi |
466 | |
467 | if [[ ${moddep} = make ]] |
468 | then |
469 | doDepmod |
470 | elif [[ ${moddep} = remove ]] |
471 | then |
472 | doRmmoddep |
473 | fi |
474 | |
475 | if [[ ${initrd} = make ]] |
476 | then |
477 | mkinitrd |
478 | elif [[ ${initrd} = remove ]] |
479 | then |
480 | rminitrd |
481 | fi |
482 | |
483 | if [ ! -x ${grubby} ] |
484 | then |
485 | [[ -n ${verbose} ]] && echo "${grubby} does not exist" |
486 | exit 0 |
487 | fi |
488 | |
489 | [[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1 |
490 | [[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1 |
491 | |
492 | # if we have a lilo config on an x86 box, see if the default boot loader |
493 | # is lilo to determine if it should be run |
494 | if [[ -n ${cfgLilo} ]] && [[ -n ${isx86} ]] |
495 | then |
496 | runLilo=$(${grubby} --bootloader-probe | grep lilo) |
497 | fi |
498 | |
499 | if [[ ${mode} = --install ]] |
500 | then |
501 | install |
502 | elif [[ ${mode} = --remove ]] |
503 | then |
504 | remove |
505 | elif [[ ${mode} = --update ]] |
506 | then |
507 | update |
508 | fi |
509 | |
510 | exit 0 |
Properties
Name | Value |
---|---|
svn:executable | * |