1 |
#!/bin/bash |
#!/bin/bash |
2 |
|
# $Id$ |
3 |
# |
# |
4 |
|
# new-kernel-pkg |
5 |
# Invoked upon installation or removal of a kernel package, the following |
# Invoked upon installation or removal of a kernel package, the following |
6 |
# tasks are/can be done here: |
# tasks are/can be done here: |
7 |
# creation/removal of initrd |
# creation/removal of initrd |
8 |
# run of depmod/removal of depmod generated files |
# run of depmod/removal of depmod generated files |
9 |
# addition/removal of kernel images from grub/lilo configuration (via grubby) |
# addition/removal of kernel images from grub/lilo configuration (via grubby) |
10 |
# |
# |
11 |
# Copyright (C) 2002-2005 Red Hat, Inc. |
# Copyright 2002-2008 Red Hat, Inc. All rights reserved. |
|
# |
|
12 |
# modified for Magellan-Linux by Niels Rogalla <niro@magellan-linux.de> |
# 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 |
PATH=/sbin:/bin:$PATH |
29 |
|
|
32 |
# some defaults that are sane for most arches |
# some defaults that are sane for most arches |
33 |
kernelName=kernel |
kernelName=kernel |
34 |
|
|
35 |
if [ -x ./grubby ]; then |
if [ -x ./grubby ] |
36 |
grubby=./grubby |
then |
37 |
|
grubby=./grubby |
38 |
else |
else |
39 |
grubby=/sbin/grubby |
grubby=/sbin/grubby |
40 |
fi |
fi |
41 |
|
|
42 |
[ -f /etc/sysconfig/kernel ] && . /etc/sysconfig/kernel |
[ -f /etc/conf.d/grubby ] && . /etc/conf.d/grubby |
43 |
|
|
44 |
cfgGrub="" |
cfgGrub="" |
45 |
cfgLilo="" |
cfgLilo="" |
48 |
|
|
49 |
ARCH=$(uname -m) |
ARCH=$(uname -m) |
50 |
|
|
51 |
if [ $ARCH = 'ia64' ]; then |
if [[ ${ARCH} = ia64 ]] |
52 |
liloConfig=/boot/efi/EFI/redhat/elilo.conf |
then |
53 |
bootPrefix=/boot/efi/EFI/redhat |
liloConfig=/boot/efi/EFI/redhat/elilo.conf |
54 |
liloFlag=elilo |
bootPrefix=/boot/efi/EFI/redhat |
55 |
isx86="" |
liloFlag=elilo |
56 |
elif [ $ARCH = 'ppc64' -o $ARCH = 'ppc' ]; then |
isx86="" |
57 |
liloConfig=/etc/yaboot.conf |
elif [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]] |
58 |
bootPrefix=/boot |
then |
59 |
lilo=/sbin/ybin |
liloConfig=/etc/yaboot.conf |
60 |
liloFlag=yaboot |
bootPrefix=/boot |
61 |
runLilo="yes" |
lilo=/sbin/ybin |
62 |
isx86="" |
liloFlag=yaboot |
63 |
elif [ $ARCH = 'sparc' -o $ARCH = 'sparc64' ]; then |
runLilo="yes" |
64 |
liloConfig=/etc/silo.conf |
isx86="" |
65 |
bootPrefix=/boot |
elif [[ ${ARCH} = sparc ]] || [[ ${ARCH} = sparc64 ]] |
66 |
liloFlag=silo |
then |
67 |
lilo=/sbin/silo |
liloConfig=/etc/silo.conf |
68 |
isx86="" |
bootPrefix=/boot |
69 |
elif [ $ARCH = 's390' -o $ARCH = 's390x' ]; then |
liloFlag=silo |
70 |
liloConfig=/etc/zipl.conf |
lilo=/sbin/silo |
71 |
bootPrefix=/boot |
isx86="" |
72 |
liloFlag=zipl |
elif [[ ${ARCH} = s390 ]] || [[ ${ARCH} = s390x ]] |
73 |
lilo=/sbin/zipl |
then |
74 |
runLilo="yes" |
liloConfig=/etc/zipl.conf |
75 |
isx86="" |
bootPrefix=/boot |
76 |
|
liloFlag=zipl |
77 |
|
lilo=/sbin/zipl |
78 |
|
runLilo="yes" |
79 |
|
isx86="" |
80 |
else |
else |
81 |
# this leaves i?86 and x86_64 |
# this leaves i?86 and x86_64 |
82 |
liloConfig=/etc/lilo.conf |
liloConfig=/etc/lilo.conf |
83 |
grubConfig=/boot/grub/grub.conf |
grubConfig=/boot/grub/grub.conf |
84 |
bootPrefix=/boot |
bootPrefix=/boot |
85 |
liloFlag=lilo |
liloFlag=lilo |
86 |
isx86="yes" |
isx86="yes" |
87 |
fi |
fi |
88 |
|
|
89 |
mode="" |
mode="" |
90 |
version="" |
version="" |
91 |
initrd="" |
initrd="" |
92 |
|
dracut="" |
93 |
|
dracuthostonly="" |
94 |
initrdfile="" |
initrdfile="" |
95 |
moddep="" |
moddep="" |
96 |
verbose="" |
verbose="" |
98 |
package="" |
package="" |
99 |
mbkernel="" |
mbkernel="" |
100 |
mbargs="" |
mbargs="" |
101 |
|
adddracutargs="" |
102 |
|
addplymouthinitrd="" |
103 |
|
|
104 |
usage() { |
usage() |
105 |
echo "Usage: `basename $0` [-v] [--mkinitrd] [--rminitrd]" >&2 |
{ |
106 |
echo " [--initrdfile=<initrd-image>] [--depmod] [--rmmoddep]" >&2 |
echo "Usage: $(basename $0) [-v] [--mkinitrd] [--rminitrd] [--dracut]" >&2 |
107 |
echo " [--kernel-args=<args>] [--banner=<banner>]" >&2 |
echo " [--initrdfile=<initrd-image>] [--depmod] [--rmmoddep]" >&2 |
108 |
echo " [--multiboot=multiboot] [--mbargs=mbargs]" >&2 |
echo " [--kernel-args=<args>] [--remove-args=<args>]" >&2 |
109 |
echo " [--make-default] <--install | --remove> <kernel-version>" >&2 |
echo " [--banner=<banner>] [--multiboot=multiboot]" >&2 |
110 |
echo " (ex: `basename $0` --mkinitrd --depmod --install 2.4.7-2)" >&2 |
echo " [--mbargs=mbargs] [--make-default] [--add-dracut-args]" >&2 |
111 |
exit 1 |
echo " [--add-plymouth-initrd]" >&2 |
112 |
|
echo " [--host-only]" >&2 |
113 |
|
echo " <--install | --remove | --update> <kernel-version>" >&2 |
114 |
|
echo " (ex: $(basename $0) --mkinitrd --depmod --install 2.4.7-2)" >&2 |
115 |
|
exit 1 |
116 |
|
} |
117 |
|
|
118 |
|
run_grub2() |
119 |
|
{ |
120 |
|
if [ -d /boot/grub2 -a -x /sbin/grub2-mkconfig ] |
121 |
|
then |
122 |
|
cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.old |
123 |
|
/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg |
124 |
|
fi |
125 |
} |
} |
126 |
|
|
127 |
install() { |
install() |
128 |
# XXX kernel should be able to be specified also (or work right on ia64) |
{ |
129 |
if [ ! -f $bootPrefix/$kernelName-$version ] ; then |
# XXX kernel should be able to be specified also (or work right on ia64) |
130 |
[ -n "$verbose" ] && echo "kernel for $version does not exist, not running grubby" |
if [ ! -f ${bootPrefix}/${kernelName}-${version} ] |
131 |
return |
then |
132 |
fi |
[[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby" |
133 |
|
return |
134 |
INITRD="" |
fi |
135 |
if [ -f $initrdfile ]; then |
|
136 |
[ -n "$verbose" ] && echo "found $initrdfile and using it with grubby" |
INITRD="" |
137 |
INITRD="--initrd $initrdfile" |
if [ -f ${initrdfile} ] |
138 |
fi |
then |
139 |
|
[[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby" |
140 |
# FIXME: is this a good heuristic to find out if we're on iSeries? |
INITRD="--initrd ${initrdfile}" |
141 |
if [ -d /proc/iSeries ]; then |
|
142 |
[ -n "$verbose" ] && echo "On an iSeries, just making img file" |
if [[ -n ${addplymouthinitrd} ]] |
143 |
if [ -z $initrdfile ]; then |
then |
144 |
[ -n "$verbose" ] && echo "No initrd, just adding system map" |
INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img" |
145 |
/sbin/addSystemMap $bootPrefix/System.map-$version $bootPrefix/$kernelName-$version $bootPrefix/vmlinitrd-$version |
fi |
146 |
|
fi |
147 |
|
|
148 |
|
# FIXME: is this a good heuristic to find out if we're on iSeries? |
149 |
|
if [ -d /proc/iSeries ] |
150 |
|
then |
151 |
|
[[ -n ${verbose} ]] && echo "On an iSeries, just making img file" |
152 |
|
if [[ -z ${initrdfile} ]] |
153 |
|
then |
154 |
|
[[ -n ${verbose} ]] && echo "No initrd, just adding system map" |
155 |
|
/sbin/addSystemMap ${bootPrefix}/System.map-${version} ${bootPrefix}/${kernelName}-${version} ${bootPrefix}/vmlinitrd-${version} |
156 |
|
else |
157 |
|
/sbin/addSystemMap ${bootPrefix}/System.map-${version} ${bootPrefix}/${kernelName}-${version} ${bootPrefix}/vmlinux.sm-${version} |
158 |
|
/sbin/addRamDisk ${initrdfile} ${bootPrefix}/System.map-${version} ${bootPrefix}/vmlinux.sm-${version} ${bootPrefix}/vmlinitrd-${version} 2>/dev/null |
159 |
|
rm ${bootPrefix}/vmlinux.sm-${version} |
160 |
|
fi |
161 |
|
return |
162 |
|
fi |
163 |
|
|
164 |
|
# Run grub2's configuration update in parallel, if it is installed |
165 |
|
run_grub2 |
166 |
|
|
167 |
|
# get the root filesystem to use |
168 |
|
rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab) |
169 |
|
|
170 |
|
if [[ -n ${mbkernel} ]] && [[ -n ${cfgLilo} ]] && [[ ${liloFlag} != elilo ]] |
171 |
|
then |
172 |
|
[[ -n ${verbose} ]] && echo "multiboot specified, not updating lilo.conf" |
173 |
|
cfgLilo="" |
174 |
|
fi |
175 |
|
|
176 |
|
if [[ -n ${cfgGrub} ]] |
177 |
|
then |
178 |
|
[[ -n ${verbose} ]] && echo "adding ${version} to ${grubConfig}" |
179 |
|
|
180 |
|
if [[ -n ${banner} ]] |
181 |
|
then |
182 |
|
title="${banner} (${version})" |
183 |
|
elif [ -f /etc/mageversion ] |
184 |
|
then |
185 |
|
title="Magellan Linux $(< /etc/mageversion) (${version})" |
186 |
|
else |
187 |
|
title="Magellan Linux (${version})" |
188 |
|
fi |
189 |
|
${grubby} --add-kernel=${bootPrefix}/${kernelName}-${version} \ |
190 |
|
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
191 |
|
${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \ |
192 |
|
--args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}" |
193 |
else |
else |
194 |
/sbin/addSystemMap $bootPrefix/System.map-$version $bootPrefix/$kernelName-$version $bootPrefix/vmlinux.sm-$version |
[[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby" |
195 |
/sbin/addRamDisk $initrdfile $bootPrefix/System.map-$version $bootPrefix/vmlinux.sm-$version $bootPrefix/vmlinitrd-$version 2>/dev/null |
fi |
196 |
rm $bootPrefix/vmlinux.sm-$version |
|
197 |
fi |
if [[ -n ${cfgLilo} ]] |
198 |
return |
then |
199 |
fi |
[[ -n ${verbose} ]] && echo "adding ${version} to ${liloConfig}" |
200 |
|
|
201 |
# get the root filesystem to use; if it's on a label make sure it's |
${grubby} --add-kernel=${bootPrefix}/${kernelName}-${version} ${INITRD} \ |
202 |
# been configured. if not, get the root device from mount |
--copy-default ${makedefault} --title ${version} \ |
203 |
rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab) |
${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \ |
204 |
short=$(echo $rootdevice | cut -d= -f1) |
--args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${version}" \ |
205 |
if [ "$short" == "LABEL" ]; then |
--${liloFlag} |
206 |
label=$(echo $rootdevice | cut -d= -f2 |head -n 1) |
|
207 |
device=$(echo "showlabels" | /sbin/nash --force --quiet | |
if [[ -n ${runLilo} ]] |
208 |
awk '$2 == "'$label'" {print $1}') |
then |
209 |
if [ -z "$device" ]; then |
[[ -n ${verbose} ]] && echo "running ${lilo}" |
210 |
rootdevice=$(mount | awk '$3 == "/" { print $1 }') |
if [ ! -x ${lilo} ] |
211 |
fi |
then |
212 |
fi |
[[ -n ${verbose} ]] && echo "${lilo} does not exist" |
213 |
|
else |
214 |
if [ -n "$mbkernel" ]; then |
${lilo} > /dev/null |
215 |
mb="--add-multiboot=$mbkernel" |
fi |
216 |
if [ -n "$mbargs" ]; then |
fi |
|
mb="$mb --mbargs=$mbargs" |
|
|
fi |
|
|
[ -n "$verbose" ] && echo "multiboot specified, not updating lilo.conf" |
|
|
cfgLilo="" |
|
|
fi |
|
|
|
|
|
if [ -n "$cfgGrub" ]; then |
|
|
[ -n "$verbose" ] && echo "adding $version to $grubConfig" |
|
|
|
|
|
if [ -n "$banner" ]; then |
|
|
title="$banner ($version)" |
|
|
elif [ -f /etc/mageversion ]; then |
|
|
title="Magellan Linux $(< /etc/mageversion) ($version)" |
|
217 |
else |
else |
218 |
title="Magellan Linux ($version)" |
[[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
219 |
fi |
fi |
220 |
/sbin/grubby --add-kernel=$bootPrefix/$kernelName-$version $INITRD \ |
} |
|
--copy-default $makedefault $mb --title "$title" \ |
|
|
--args="root=$rootdevice $kernargs" \ |
|
|
--remove-kernel="TITLE=$title" |
|
|
else |
|
|
[ -n "$verbose" ] && echo "$grubConfig does not exist, not running grubby" |
|
|
fi |
|
|
|
|
|
if [ -n "$cfgLilo" ]; then |
|
|
[ -n "$verbose" ] && echo "adding $version to $liloConfig" |
|
|
|
|
|
/sbin/grubby --add-kernel=$bootPrefix/$kernelName-$version $INITRD \ |
|
|
--copy-default $makedefault --title $version \ |
|
|
--args="root=$rootdevice $kernargs" \ |
|
|
--remove-kernel="TITLE=$version" \ |
|
|
--$liloFlag |
|
|
|
|
|
if [ -n "$runLilo" ]; then |
|
|
[ -n "$verbose" ] && echo "running $lilo" |
|
|
if [ ! -x $lilo ] ; then |
|
|
[ -n "$verbose" ] && echo "$lilo does not exist" |
|
|
else |
|
|
$lilo > /dev/null |
|
|
fi |
|
|
fi |
|
|
else |
|
|
[ -n "$verbose" ] && echo "$liloConfig does not exist, not running grubby" |
|
|
fi |
|
221 |
|
|
222 |
|
remove() |
223 |
|
{ |
224 |
|
# FIXME: is this a good heuristic to find out if we're on iSeries? |
225 |
|
if [ -d /proc/iSeries ] |
226 |
|
then |
227 |
|
[[ -n ${verbose} ]] && echo "On an iSeries, remove img file" |
228 |
|
rm -f ${bootPrefix}/${kernelName}-${version}.img 2>/dev/null |
229 |
|
return |
230 |
|
fi |
231 |
|
|
232 |
|
# Run grub2's configuration update in parallel, if it is installed |
233 |
|
run_grub2 |
234 |
|
|
235 |
|
if [[ -n ${cfgGrub} ]] |
236 |
|
then |
237 |
|
[[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}" |
238 |
|
${grubby} --remove-kernel=${bootPrefix}/${kernelName}-${version} |
239 |
|
else |
240 |
|
[[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby" |
241 |
|
fi |
242 |
|
|
243 |
|
if [[ -n ${cfgLilo} ]] |
244 |
|
then |
245 |
|
[[ -n ${verbose} ]] && echo "removing ${version} from ${liloConfig}" |
246 |
|
${grubby} --remove-kernel=${bootPrefix}/${kernelName}-${version} --${liloFlag} |
247 |
|
|
248 |
|
if [[ -n ${runLilo} ]] |
249 |
|
then |
250 |
|
[[ -n ${verbose} ]] && echo "running ${lilo}" |
251 |
|
if [ ! -x ${lilo} ] |
252 |
|
then |
253 |
|
[[ -n ${verbose} ]] && echo "${lilo} does not exist" |
254 |
|
else |
255 |
|
${lilo} > /dev/null |
256 |
|
fi |
257 |
|
fi |
258 |
|
else |
259 |
|
[[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
260 |
|
fi |
261 |
} |
} |
262 |
|
|
263 |
remove() { |
update() |
264 |
# FIXME: is this a good heuristic to find out if we're on iSeries? |
{ |
265 |
if [ -d /proc/iSeries ]; then |
if [ ! -f ${bootPrefix}/${kernelName}-${version} ] |
266 |
[ -n "$verbose" ] && echo "On an iSeries, remove img file" |
then |
267 |
rm -f $bootPrefix/$kernelName-$version.img 2>/dev/null |
[[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby" |
268 |
return |
return |
269 |
fi |
fi |
270 |
|
|
271 |
if [ -n "$cfgGrub" ]; then |
INITRD="" |
272 |
[ -n "$verbose" ] && echo "removing $version from $grubConfig" |
if [ -f ${initrdfile} ] |
273 |
/sbin/grubby --remove-kernel=$bootPrefix/$kernelName-$version |
then |
274 |
else |
[[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby" |
275 |
[ -n "$verbose" ] && echo "$grubConfig does not exist, not running grubby" |
INITRD="--initrd ${initrdfile}" |
276 |
fi |
|
277 |
|
if [[ -n ${addplymouthinitrd} ]] |
278 |
if [ -n "$cfgLilo" ]; then |
then |
279 |
[ -n "$verbose" ] && echo "removing $version from $liloConfig" |
INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img" |
280 |
/sbin/grubby --remove-kernel=$bootPrefix/$kernelName-$version \ |
fi |
281 |
--$liloFlag |
fi |
282 |
|
|
283 |
if [ -n "$runLilo" ]; then |
# Run grub2's configuration update in parallel, if it is installed |
284 |
[ -n "$verbose" ] && echo "running $lilo" |
run_grub2 |
285 |
if [ ! -x $lilo ] ; then |
|
286 |
[ -n "$verbose" ] && echo "$lilo does not exist" |
if [[ -n ${cfgGrub} ]] |
287 |
else |
then |
288 |
$lilo > /dev/null |
[[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}" |
289 |
fi |
${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \ |
290 |
fi |
${INITRD} \ |
291 |
else |
${kernargs:+--args="${kernargs}"} \ |
292 |
[ -n "$verbose" ] && echo "$liloConfig does not exist, not running grubby" |
${removeargs:+--remove-args="${removeargs}"} |
293 |
fi |
else |
294 |
|
[[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby" |
295 |
|
fi |
296 |
|
|
297 |
|
if [[ -n ${cfgLilo} ]] |
298 |
|
then |
299 |
|
[[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}" |
300 |
|
${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \ |
301 |
|
${INITRD} \ |
302 |
|
${kernargs:+--args="${kernargs}"} \ |
303 |
|
${removeargs:+--remove-args="${removeargs}"} \ |
304 |
|
--${liloFlag} |
305 |
|
|
306 |
|
if [[ -n ${runLilo} ]] |
307 |
|
then |
308 |
|
[[ -n ${verbose} ]] && echo "running ${lilo}" |
309 |
|
if [ ! -x ${lilo} ] |
310 |
|
then |
311 |
|
[[ -n ${verbose} ]] && echo "${lilo} does not exist" |
312 |
|
else |
313 |
|
${lilo} > /dev/null |
314 |
|
fi |
315 |
|
fi |
316 |
|
else |
317 |
|
[[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
318 |
|
fi |
319 |
} |
} |
320 |
|
|
321 |
mkinitrd() { |
mkinitrd() |
322 |
[ -n "$verbose" ] && echo "creating initrd $initrdfile using $version" |
{ |
323 |
/sbin/mkinitrd --allow-missing -f $initrdfile $version |
if [[ -n ${dracut} ]] |
324 |
rc=$? |
then |
325 |
if [ $rc != 0 ]; then |
tool="/sbin/dracut ${dracuthostonly} -f ${initrdfile} ${version}" |
326 |
echo "mkinitrd failed" >&2 |
else |
327 |
exit 1 |
tool="/sbin/mkinitrd --allow-missing -f ${initrdfile} ${version}" |
328 |
fi |
fi |
329 |
|
[[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}" |
330 |
|
${tool} |
331 |
|
rc=$? |
332 |
|
if [ ${rc} != 0 ] |
333 |
|
then |
334 |
|
echo "mkinitrd failed" >&2 |
335 |
|
exit 1 |
336 |
|
fi |
337 |
} |
} |
338 |
|
|
339 |
rminitrd() { |
rminitrd() |
340 |
[ -n "$verbose" ] && echo "removing initrd $initrdfile" |
{ |
341 |
[ -f $initrdfile ] && rm -f $initrdfile |
[[ -n ${verbose} ]] && echo "removing initrd ${initrdfile}" |
342 |
|
[ -f ${initrdfile} ] && rm -f ${initrdfile} |
343 |
} |
} |
344 |
|
|
345 |
doDepmod() { |
doDepmod() |
346 |
[ -n "$verbose" ] && echo "running depmod for $version" |
{ |
347 |
depmod -ae -F /boot/System.map-$version $version |
[[ -n ${verbose} ]] && echo "running depmod for ${version}" |
348 |
|
depmod -ae -F /boot/System.map-${version} ${version} |
349 |
} |
} |
350 |
|
|
351 |
doRmmoddep() { |
doRmmoddep() |
352 |
[ -n "$verbose" ] && echo "removing modules.dep info for $version" |
{ |
353 |
[ -d /lib/modules/$version ] && rm -f /lib/modules/$version/modules.* |
[[ -n ${verbose} ]] && echo "removing modules.dep info for ${version}" |
354 |
|
[ -d /lib/modules/${version} ] && rm -f /lib/modules/${version}/modules.* |
355 |
} |
} |
356 |
|
|
357 |
|
|
358 |
while [ $# -gt 0 ]; do |
while [ $# -gt 0 ] |
359 |
case $1 in |
do |
360 |
--mkinitrd) |
case $1 in |
361 |
initrd="make" |
--mkinitrd) |
362 |
;; |
initrd="make" |
363 |
|
;; |
364 |
--rminitrd) |
|
365 |
initrd="remove" |
--rminitrd) |
366 |
;; |
initrd="remove" |
367 |
|
;; |
368 |
--initrdfile*) |
|
369 |
if echo $1 | grep '=' >/dev/null ; then |
--dracut) |
370 |
initrdfile=`echo $1 | sed 's/^--initrdfile=//'` |
dracut=--dracut |
371 |
else |
;; |
372 |
initrdfile=$2 |
|
373 |
shift |
--host-only) |
374 |
fi |
dracuthostonly=-H |
375 |
;; |
;; |
376 |
|
|
377 |
--kernel-args*) |
--initrdfile*) |
378 |
if echo $1 | grep '=' >/dev/null ; then |
if echo $1 | grep '=' >/dev/null |
379 |
kernargs=`echo $1 | sed 's/^--kernel-args=//'` |
then |
380 |
else |
initrdfile=$(echo $1 | sed 's/^--initrdfile=//') |
381 |
kernargs=$2 |
else |
382 |
shift |
initrdfile=$2 |
383 |
fi |
shift |
384 |
;; |
fi |
385 |
|
;; |
386 |
--banner*) |
|
387 |
if echo $1 | grep '=' >/dev/null ; then |
--kernel-args*) |
388 |
banner=`echo $1 | sed 's/^--banner=//'` |
if echo $1 | grep '=' >/dev/null |
389 |
else |
then |
390 |
banner=$2 |
kernargs=$(echo $1 | sed 's/^--kernel-args=//') |
391 |
shift |
else |
392 |
fi |
kernargs=$2 |
393 |
;; |
shift |
394 |
|
fi |
395 |
--multiboot*) |
;; |
396 |
if echo $1 |grep '=' >/dev/null; then |
|
397 |
mbkernel=`echo $1 | sed 's/^--multiboot=//'` |
--remove-args*) |
398 |
else |
if echo $1 | grep '=' >/dev/null |
399 |
# can't really support having an optional second arg here |
then |
400 |
# sorry! |
removeargs=$(echo $1 | sed 's/^--remove-args=//') |
401 |
mbkernel="/boot/xen.gz" |
else |
402 |
fi |
removeargs=$2 |
403 |
;; |
shift |
404 |
|
fi |
405 |
--mbargs*) |
;; |
406 |
if echo $1 |grep '=' >/dev/null; then |
|
407 |
mbargs=`echo $1 | sed 's/^--mbargs=//'` |
--banner*) |
408 |
else |
if echo $1 | grep '=' >/dev/null |
409 |
mbargs=$2 |
then |
410 |
shift |
banner=$(echo $1 | sed 's/^--banner=//') |
411 |
fi |
else |
412 |
;; |
banner=$2 |
413 |
|
shift |
414 |
--depmod) |
fi |
415 |
moddep="make" |
;; |
416 |
;; |
|
417 |
|
--multiboot*) |
418 |
--rmmoddep) |
if echo $1 |grep '=' >/dev/null |
419 |
moddep="remove" |
then |
420 |
;; |
mbkernel=$(echo $1 | sed 's/^--multiboot=//') |
421 |
|
else |
422 |
--make-default) |
# can't really support having an optional second arg here |
423 |
makedefault="--make-default" |
# sorry! |
424 |
;; |
mbkernel="/boot/xen.gz" |
425 |
|
fi |
426 |
--package) |
;; |
427 |
if echo $1 | grep '=' >/dev/null ; then |
|
428 |
package=`echo $1 | sed 's/^--package=//'` |
--mbargs*) |
429 |
else |
if echo $1 |grep '=' >/dev/null |
430 |
package=$2 |
then |
431 |
shift |
mbargs=$(echo $1 | sed 's/^--mbargs=//') |
432 |
fi |
else |
433 |
;; |
mbargs="$2" |
434 |
|
shift |
435 |
-v) |
fi |
436 |
verbose=-v |
;; |
437 |
;; |
|
438 |
|
--depmod) |
439 |
*) |
moddep="make" |
440 |
if [ -z "$mode" ]; then |
;; |
441 |
mode=$1 |
|
442 |
elif [ -z "$version" ]; then |
--rmmoddep) |
443 |
version=$1 |
moddep="remove" |
444 |
else |
;; |
445 |
usage |
|
446 |
fi |
--make-default) |
447 |
;; |
makedefault="--make-default" |
448 |
esac |
;; |
449 |
|
|
450 |
|
--package) |
451 |
|
if echo $1 | grep '=' >/dev/null |
452 |
|
then |
453 |
|
package=$(echo $1 | sed 's/^--package=//') |
454 |
|
else |
455 |
|
package=$2 |
456 |
|
shift |
457 |
|
fi |
458 |
|
;; |
459 |
|
|
460 |
|
--add-dracut-args) |
461 |
|
adddracutargs=--add-dracut-args |
462 |
|
;; |
463 |
|
|
464 |
|
--add-plymouth-initrd) |
465 |
|
addplymouthinitrd=--add-plymouth-initrd |
466 |
|
;; |
467 |
|
|
468 |
|
-v) |
469 |
|
verbose=-v |
470 |
|
;; |
471 |
|
|
472 |
|
*) |
473 |
|
if [[ -z ${mode} ]] |
474 |
|
then |
475 |
|
mode=$1 |
476 |
|
elif [[ -z ${version} ]] |
477 |
|
then |
478 |
|
version=$1 |
479 |
|
else |
480 |
|
usage |
481 |
|
fi |
482 |
|
;; |
483 |
|
esac |
484 |
|
|
485 |
shift |
shift |
486 |
done |
done |
487 |
|
|
488 |
# make sure the mode is valid |
# make sure the mode is valid |
489 |
if [ "$mode" != "--install" -a "$mode" != "--remove" ] ; then |
if [[ ${mode} != --install ]] && [[ ${mode} != --remove ]] && [[ ${mode} != --update ]] |
490 |
usage |
then |
491 |
|
usage |
492 |
fi |
fi |
493 |
|
|
494 |
if [ -z "$version" ]; then |
if [[ -z ${version} ]] |
495 |
usage |
then |
496 |
|
usage |
497 |
fi |
fi |
498 |
|
|
499 |
if [ "$mode" != "--install" -a "$makedefault" ]; then |
if [ "${mode}" != "--install" -a "${makedefault}" ] |
500 |
usage |
then |
501 |
|
usage |
502 |
fi |
fi |
503 |
|
|
504 |
# make sure that /dev/loop exist |
kernelmajor=$(echo ${kernel} | cut -d . -f 1,2) |
|
[[ ! -e /dev/loop ]] && modprobe loop |
|
|
|
|
|
kernelmajor=`echo $kernel | cut -d . -f 1,2` |
|
505 |
|
|
506 |
# kernel image for 2.4 is vmlinux |
# kernel image for 2.4 is kernel |
507 |
if [ $ARCH = 'ppc64' -o $ARCH = 'ppc' ]; then |
if [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]] |
508 |
if [ "$kernelmajor" == "2.4" ]; then |
then |
509 |
kernelName=vmlinux |
if [[ ${kernelmajor} = 2.4 ]] |
510 |
fi |
then |
511 |
|
kernelName=kernel |
512 |
|
fi |
513 |
fi |
fi |
514 |
|
|
|
|
|
515 |
# set the initrd file based on arch; ia64 is the only currently known oddball |
# set the initrd file based on arch; ia64 is the only currently known oddball |
516 |
if [ -z "$initrdfile" ]; then |
if [[ -z ${initrdfile} ]] |
517 |
if [ `uname -m` = "ia64" ]; then |
then |
518 |
initrdfile="/boot/efi/EFI/redhat/initrd-$version.img" |
INITRD_NAME_PREFIX="initrd" |
519 |
else |
if [[ -n ${dracut} ]] |
520 |
initrdfile="/boot/initrd-$version.img" |
then |
521 |
fi |
INITRD_NAME_PREFIX="initramfs" |
522 |
|
fi |
523 |
|
|
524 |
|
if [[ $(uname -m) = ia64 ]] |
525 |
|
then |
526 |
|
initrdfile="/boot/efi/EFI/redhat/${INITRD_NAME_PREFIX}-${version}.img" |
527 |
|
else |
528 |
|
initrdfile="/boot/${INITRD_NAME_PREFIX}-${version}.img" |
529 |
|
fi |
530 |
fi |
fi |
531 |
[ -n "$verbose" ] && echo "initrdfile is $initrdfile" |
[[ -n ${verbose} ]] && echo "initrdfile is ${initrdfile}" |
532 |
|
|
533 |
# set this as the default if we have the package and it matches |
# add dracut i18n, keyboard and plymouth kernel args if requested |
534 |
if [ "$mode" == "--install" -a "$UPDATEDEFAULT" == "yes" -a -n "$package" -a -n "$DEFAULTKERNEL" -a "$package" == "$DEFAULTKERNEL" ]; then |
if [[ -n ${dracut} ]] || [[ -n ${adddracutargs} ]] |
535 |
makedefault="--make-default" |
then |
536 |
[ -n "$verbose" ] && echo "making it the default based on config" |
[ -r /etc/conf.d/keymap ] && . /etc/conf.d/keymap |
537 |
|
[ -r /etc/conf.d/consolefont ] && . /etc/conf.d/consolefont |
538 |
|
|
539 |
|
if [[ -n ${KEYMAP} ]] |
540 |
|
then |
541 |
|
kernargs="${kernargs} KEYTABLE=${KEYMAP}" |
542 |
|
fi |
543 |
|
|
544 |
|
if [[ -n ${CONSOLEFONT} ]] |
545 |
|
then |
546 |
|
kernargs="${kernargs} SYSFONT=${CONSOLEFONT}" |
547 |
|
fi |
548 |
fi |
fi |
549 |
|
|
550 |
if [ "$moddep" == "make" ]; then |
# set this as the default if we have the package and it matches |
551 |
doDepmod |
if [[ ${mode} = --install ]] && [[ ${UPDATEDEFAULT} = yes ]] && [[ -n ${package} ]] && |
552 |
elif [ "$moddep" == "remove" ]; then |
[[ -n ${DEFAULTKERNEL} ]] && [[ ${package} = ${DEFAULTKERNEL} ]] |
553 |
doRmmoddep |
then |
554 |
|
makedefault="--make-default" |
555 |
|
[[ -n ${verbose} ]] && echo "making it the default based on config" |
556 |
fi |
fi |
557 |
|
|
558 |
if [ "$initrd" == "make" ]; then |
if [[ ${moddep} = make ]] |
559 |
mkinitrd |
then |
560 |
elif [ "$initrd" == "remove" ]; then |
doDepmod |
561 |
rminitrd |
elif [[ ${moddep} = remove ]] |
562 |
|
then |
563 |
|
doRmmoddep |
564 |
fi |
fi |
565 |
|
|
566 |
if [ ! -x $grubby ] ; then |
if [[ ${initrd} = make ]] |
567 |
[ -n "$verbose" ] && echo "$grubby does not exist" |
then |
568 |
exit 0 |
mkinitrd |
569 |
|
elif [[ ${initrd} = remove ]] |
570 |
|
then |
571 |
|
rminitrd |
572 |
fi |
fi |
573 |
|
|
574 |
|
if [ ! -x ${grubby} ] |
575 |
|
then |
576 |
|
[[ -n ${verbose} ]] && echo "${grubby} does not exist" |
577 |
|
exit 0 |
578 |
|
fi |
579 |
|
|
580 |
[ -n "$grubConfig" ] && [ -f "$grubConfig" ] && cfgGrub=1; |
[[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1 |
581 |
[ -n "$liloConfig" ] && [ -f "$liloConfig" ] && cfgLilo=1; |
[[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1 |
582 |
|
|
583 |
# if we have a lilo config on an x86 box, see if the default boot loader |
# if we have a lilo config on an x86 box, see if the default boot loader |
584 |
# is lilo to determine if it should be run |
# is lilo to determine if it should be run |
585 |
if [ -n "$cfgLilo" -a -n "$isx86" ]; then |
if [[ -n ${cfgLilo} ]] && [[ -n ${isx86} ]] |
586 |
runLilo=$($grubby --bootloader-probe | grep lilo) |
then |
587 |
|
runLilo=$(${grubby} --bootloader-probe | grep lilo) |
588 |
fi |
fi |
589 |
|
|
590 |
if [ "$mode" == "--install" ]; then |
if [[ ${mode} = --install ]] |
591 |
install |
then |
592 |
elif [ "$mode" == "--remove" ]; then |
install |
593 |
remove |
elif [[ ${mode} = --remove ]] |
594 |
|
then |
595 |
|
remove |
596 |
|
elif [[ ${mode} = --update ]] |
597 |
|
then |
598 |
|
update |
599 |
fi |
fi |
600 |
|
|
601 |
exit 0 |
exit 0 |