40 |
fi |
fi |
41 |
|
|
42 |
[ -f /etc/conf.d/grubby ] && . /etc/conf.d/grubby |
[ -f /etc/conf.d/grubby ] && . /etc/conf.d/grubby |
43 |
|
[ -f /etc/conf.d/grubby-uboot ] && . /etc/conf.d/grubby-uboot |
44 |
|
|
45 |
cfgGrub="" |
cfgGrub="" |
46 |
cfgLilo="" |
cfgLilo="" |
47 |
|
cfguBoot="" |
48 |
runLilo="" |
runLilo="" |
49 |
grubConfig="" |
grubConfig="" |
50 |
|
|
79 |
lilo=/sbin/zipl |
lilo=/sbin/zipl |
80 |
runLilo="yes" |
runLilo="yes" |
81 |
isx86="" |
isx86="" |
82 |
|
elif [[ ${ARCH} = armv7l ]] |
83 |
|
then |
84 |
|
liloConfig="" |
85 |
|
bootPrefix=/boot |
86 |
|
ubootDir=${UBOOT_DIR:-"/boot/uboot"} |
87 |
|
ubootScript=$ubootDir/${UBOOT_SCR:-"boot.scr"} |
88 |
|
ubootKList=${UBOOT_KLIST:-"klist.txt"} |
89 |
|
ubootDevice=/dev/${UBOOT_DEVICE:-"mmcblk0p1"} |
90 |
|
ubootDefaultImage=${UBOOT_UIMAGE:-"uImage"} |
91 |
|
ubootDefaultInitrd=${UBOOT_UINITRD:-"uInitrd"} |
92 |
|
mounted="" |
93 |
|
liloFlag="" |
94 |
|
isx86="" |
95 |
else |
else |
96 |
# this leaves i?86 and x86_64 |
# this leaves i?86 and x86_64 |
97 |
liloConfig=/etc/lilo.conf |
liloConfig=/etc/lilo.conf |
104 |
mode="" |
mode="" |
105 |
version="" |
version="" |
106 |
initrd="" |
initrd="" |
107 |
|
dracut="" |
108 |
|
dracuthostonly="" |
109 |
initrdfile="" |
initrdfile="" |
110 |
moddep="" |
moddep="" |
111 |
verbose="" |
verbose="" |
113 |
package="" |
package="" |
114 |
mbkernel="" |
mbkernel="" |
115 |
mbargs="" |
mbargs="" |
116 |
|
adddracutargs="" |
117 |
|
addplymouthinitrd="" |
118 |
|
|
119 |
usage() |
usage() |
120 |
{ |
{ |
121 |
echo "Usage: $(basename $0) [-v] [--mkinitrd] [--rminitrd]" >&2 |
echo "Usage: $(basename $0) [-v] [--mkinitrd] [--rminitrd] [--dracut]" >&2 |
122 |
echo " [--initrdfile=<initrd-image>] [--depmod] [--rmmoddep]" >&2 |
echo " [--initrdfile=<initrd-image>] [--depmod] [--rmmoddep]" >&2 |
123 |
echo " [--kernel-args=<args>] [--remove-args=<args>]" >&2 |
echo " [--kernel-args=<args>] [--remove-args=<args>]" >&2 |
124 |
echo " [--banner=<banner>] [--multiboot=multiboot]" >&2 |
echo " [--banner=<banner>] [--multiboot=multiboot]" >&2 |
125 |
echo " [--mbargs=mbargs] [--make-default]" >&2 |
echo " [--mbargs=mbargs] [--make-default] [--add-dracut-args]" >&2 |
126 |
|
echo " [--add-plymouth-initrd]" >&2 |
127 |
|
echo " [--host-only]" >&2 |
128 |
echo " <--install | --remove | --update> <kernel-version>" >&2 |
echo " <--install | --remove | --update> <kernel-version>" >&2 |
129 |
echo " (ex: $(basename $0) --mkinitrd --depmod --install 2.4.7-2)" >&2 |
echo " (ex: $(basename $0) --mkinitrd --depmod --install 2.4.7-2)" >&2 |
130 |
exit 1 |
exit 1 |
131 |
} |
} |
132 |
|
|
133 |
|
run_grub2() |
134 |
|
{ |
135 |
|
if [ -d /boot/grub -a -x /sbin/grub-mkconfig ] |
136 |
|
then |
137 |
|
cp /boot/grub/grub.cfg /boot/grub/grub.cfg.old |
138 |
|
/sbin/grub-mkconfig -o /boot/grub/grub.cfg |
139 |
|
fi |
140 |
|
} |
141 |
|
|
142 |
install() |
install() |
143 |
{ |
{ |
144 |
# XXX kernel should be able to be specified also (or work right on ia64) |
# XXX kernel should be able to be specified also (or work right on ia64) |
153 |
then |
then |
154 |
[[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby" |
[[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby" |
155 |
INITRD="--initrd ${initrdfile}" |
INITRD="--initrd ${initrdfile}" |
156 |
|
|
157 |
|
if [[ -n ${addplymouthinitrd} ]] |
158 |
|
then |
159 |
|
INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img" |
160 |
|
fi |
161 |
fi |
fi |
162 |
|
|
163 |
# FIXME: is this a good heuristic to find out if we're on iSeries? |
# FIXME: is this a good heuristic to find out if we're on iSeries? |
176 |
return |
return |
177 |
fi |
fi |
178 |
|
|
179 |
|
# Run grub2's configuration update in parallel, if it is installed |
180 |
|
run_grub2 |
181 |
|
|
182 |
# get the root filesystem to use |
# get the root filesystem to use |
183 |
rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab) |
rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab) |
184 |
|
|
222 |
if [[ -n ${runLilo} ]] |
if [[ -n ${runLilo} ]] |
223 |
then |
then |
224 |
[[ -n ${verbose} ]] && echo "running ${lilo}" |
[[ -n ${verbose} ]] && echo "running ${lilo}" |
225 |
if [ ! -x $lilo ] |
if [ ! -x ${lilo} ] |
226 |
then |
then |
227 |
[[ -n ${verbose} ]] && echo "${lilo} does not exist" |
[[ -n ${verbose} ]] && echo "${lilo} does not exist" |
228 |
else |
else |
244 |
return |
return |
245 |
fi |
fi |
246 |
|
|
247 |
|
# Run grub2's configuration update in parallel, if it is installed |
248 |
|
run_grub2 |
249 |
|
|
250 |
if [[ -n ${cfgGrub} ]] |
if [[ -n ${cfgGrub} ]] |
251 |
then |
then |
252 |
[[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}" |
[[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}" |
258 |
if [[ -n ${cfgLilo} ]] |
if [[ -n ${cfgLilo} ]] |
259 |
then |
then |
260 |
[[ -n ${verbose} ]] && echo "removing ${version} from ${liloConfig}" |
[[ -n ${verbose} ]] && echo "removing ${version} from ${liloConfig}" |
261 |
${grubby} --remove-kernel=${bootPrefix}/${kernelName}-${version} \ |
${grubby} --remove-kernel=${bootPrefix}/${kernelName}-${version} --${liloFlag} |
|
--${liloFlag} |
|
262 |
|
|
263 |
if [[ -n ${runLilo} ]] |
if [[ -n ${runLilo} ]] |
264 |
then |
then |
273 |
else |
else |
274 |
[[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
[[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
275 |
fi |
fi |
276 |
|
|
277 |
|
if [[ -n ${cfguBoot} ]] |
278 |
|
then |
279 |
|
[[ -n ${verbose} ]] && echo "removing ${version} from ${ubootDir}..." |
280 |
|
|
281 |
|
if [ -f ${ubootDir}/${ubootKList} ] |
282 |
|
then |
283 |
|
tmpKList=$(mktemp ${ubootDir}/${ubootKList}.XXXX) |
284 |
|
curversion=$(tail -n1 ${ubootDir}/${ubootKList}) |
285 |
|
sed "/${version}/d" ${ubootDir}/${ubootKList} > ${tmpKList} |
286 |
|
newversion=$(tail -n1 ${tmpKList}) |
287 |
|
if [ -f ${ubootDir}/uImage-${newversion} ] && [ -f ${ubootDir}/uInitrd-${newversion} ] |
288 |
|
then |
289 |
|
if [[ ${curversion} != ${newversion} ]] |
290 |
|
then |
291 |
|
cp -fp ${ubootDir}/uImage-${newversion} ${ubootDir}/${ubootDefaultImage} |
292 |
|
if [ $? -ne 0 ] |
293 |
|
then |
294 |
|
[[ -n ${verbose} ]] && echo "copy uImage-${newversion} error, default kernel not replaced!" && exit |
295 |
|
fi |
296 |
|
cp -fp ${ubootDir}/uInitrd-${newversion} ${ubootDir}/${ubootDefaultInitrd} |
297 |
|
if [ $? -ne 0 ] |
298 |
|
then |
299 |
|
[[ -n ${verbose} ]] && echo "copy uInitrd-${newversion} error, default Initrd not replaced!" && exit |
300 |
|
fi |
301 |
|
fi |
302 |
|
|
303 |
|
[[ -n ${verbose} ]] && echo "removing uImage-${version}" |
304 |
|
if [ -f ${ubootDir}/uImage-${version} ] |
305 |
|
then |
306 |
|
rm -f ${ubootDir}/uImage-${version} |
307 |
|
else |
308 |
|
[[ -n ${verbose} ]] && echo "uImage-${version} did not exist!" |
309 |
|
fi |
310 |
|
|
311 |
|
[[ -n ${verbose} ]] && echo "removing uInitrd-${version}" |
312 |
|
if [ -f ${ubootDir}/uInitrd-${version} ] |
313 |
|
then |
314 |
|
rm -f ${ubootDir}/uInitrd-${version} |
315 |
|
else |
316 |
|
[[ -n ${verbose} ]] && echo "uInitrd-${version} did not exist!" |
317 |
|
fi |
318 |
|
|
319 |
|
mv ${tmpKList} ${ubootDir}/${ubootKList} |
320 |
|
else |
321 |
|
[[ -n ${verbose} ]] && echo "uImage ${newversion} does not exist!" |
322 |
|
[ -f ${tmpKList} ] && rm -f ${tmpKList} |
323 |
|
fi |
324 |
|
else |
325 |
|
[[ -n ${verbose} ]] && echo "No previous kernel version. uBoot images not removed!" |
326 |
|
fi |
327 |
|
else |
328 |
|
[[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}" |
329 |
|
fi |
330 |
} |
} |
331 |
|
|
332 |
update() |
update() |
333 |
{ |
{ |
334 |
|
if [ ! -f ${bootPrefix}/${kernelName}-${version} ] |
335 |
|
then |
336 |
|
[[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby" |
337 |
|
return |
338 |
|
fi |
339 |
|
|
340 |
|
INITRD="" |
341 |
|
if [ -f ${initrdfile} ] |
342 |
|
then |
343 |
|
[[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby" |
344 |
|
INITRD="--initrd ${initrdfile}" |
345 |
|
|
346 |
|
if [[ -n ${addplymouthinitrd} ]] |
347 |
|
then |
348 |
|
INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img" |
349 |
|
fi |
350 |
|
fi |
351 |
|
|
352 |
|
# Run grub2's configuration update in parallel, if it is installed |
353 |
|
run_grub2 |
354 |
|
|
355 |
if [[ -n ${cfgGrub} ]] |
if [[ -n ${cfgGrub} ]] |
356 |
then |
then |
357 |
[[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}" |
[[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}" |
358 |
${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \ |
${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \ |
359 |
|
${INITRD} \ |
360 |
${kernargs:+--args="${kernargs}"} \ |
${kernargs:+--args="${kernargs}"} \ |
361 |
${removeargs:+--remove-args="${removeargs}"} |
${removeargs:+--remove-args="${removeargs}"} |
362 |
else |
else |
367 |
then |
then |
368 |
[[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}" |
[[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}" |
369 |
${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \ |
${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \ |
370 |
|
${INITRD} \ |
371 |
${kernargs:+--args="${kernargs}"} \ |
${kernargs:+--args="${kernargs}"} \ |
372 |
${removeargs:+--remove-args="${removeargs}"} \ |
${removeargs:+--remove-args="${removeargs}"} \ |
373 |
--${liloFlag} |
--${liloFlag} |
385 |
else |
else |
386 |
[[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
[[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
387 |
fi |
fi |
388 |
|
|
389 |
|
if [[ -n ${cfguBoot} ]] |
390 |
|
then |
391 |
|
[[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..." |
392 |
|
|
393 |
|
[[ -n ${verbose} ]] && echo "creating uImage-${version}" |
394 |
|
mkimage -A arm -O linux -T kernel -C none -a 0x80008000 -e 0x80008000 \ |
395 |
|
-n ${version} -d ${bootPrefix}/${kernelName}-${version} ${ubootDir}/uImage-${version} |
396 |
|
|
397 |
|
[[ -n ${verbose} ]] && echo "creating uInitrd-${version}" |
398 |
|
mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 \ |
399 |
|
-n initramfs -d ${initrdfile} ${ubootDir}/uInitrd-${version} |
400 |
|
|
401 |
|
if [ -f ${ubootDir}/uImage-${version} ] && [ -f ${ubootDir}/uInitrd-${version} ] |
402 |
|
then |
403 |
|
cp -fp ${ubootDir}/uImage-${version} ${ubootDir}/${ubootDefaultImage} |
404 |
|
if [ $? -ne 0 ] |
405 |
|
then |
406 |
|
[[ -n ${verbose} ]] && echo "copy uImage-${version} error, kernel not installed!" && exit |
407 |
|
fi |
408 |
|
cp -fp ${ubootDir}/uInitrd-${version} ${ubootDir}/${ubootDefaultInitrd} |
409 |
|
if [ $? -ne 0 ] |
410 |
|
then |
411 |
|
[[ -n ${verbose} ]] && echo "copy uInitrd-${version} error, kernel not installed!" && exit |
412 |
|
fi |
413 |
|
echo ${version} >> ${ubootDir}/${ubootKList} |
414 |
|
else |
415 |
|
[[ -n ${verbose} ]] && echo "cannot make ${version} the default" |
416 |
|
fi |
417 |
|
else |
418 |
|
[[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not setting up ${ubootDir}" |
419 |
|
fi |
420 |
} |
} |
421 |
|
|
422 |
mkinitrd() |
mkinitrd() |
423 |
{ |
{ |
424 |
|
if [[ -n ${dracut} ]] |
425 |
|
then |
426 |
|
tool="/sbin/dracut ${dracuthostonly} -f ${initrdfile} ${version}" |
427 |
|
else |
428 |
|
tool="/sbin/mkinitrd --allow-missing -f ${initrdfile} ${version}" |
429 |
|
fi |
430 |
[[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}" |
[[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}" |
431 |
/sbin/mkinitrd --allow-missing -f ${initrdfile} ${version} |
${tool} |
432 |
rc=$? |
rc=$? |
433 |
if [ ${rc} != 0 ] |
if [ ${rc} != 0 ] |
434 |
then |
then |
467 |
initrd="remove" |
initrd="remove" |
468 |
;; |
;; |
469 |
|
|
470 |
|
--dracut) |
471 |
|
dracut=--dracut |
472 |
|
;; |
473 |
|
|
474 |
|
--host-only) |
475 |
|
dracuthostonly=-H |
476 |
|
;; |
477 |
|
|
478 |
--initrdfile*) |
--initrdfile*) |
479 |
if echo $1 | grep '=' >/dev/null |
if echo $1 | grep '=' >/dev/null |
480 |
then |
then |
498 |
--remove-args*) |
--remove-args*) |
499 |
if echo $1 | grep '=' >/dev/null |
if echo $1 | grep '=' >/dev/null |
500 |
then |
then |
501 |
removeargs=$(echo $1 | sed 's/^--remove-args=//') |
removeargs=$(echo $1 | sed 's/^--remove-args=//') |
502 |
else |
else |
503 |
removeargs=$2 |
removeargs=$2 |
504 |
shift |
shift |
558 |
fi |
fi |
559 |
;; |
;; |
560 |
|
|
561 |
|
--add-dracut-args) |
562 |
|
adddracutargs=--add-dracut-args |
563 |
|
;; |
564 |
|
|
565 |
|
--add-plymouth-initrd) |
566 |
|
addplymouthinitrd=--add-plymouth-initrd |
567 |
|
;; |
568 |
|
|
569 |
-v) |
-v) |
570 |
verbose=-v |
verbose=-v |
571 |
;; |
;; |
604 |
|
|
605 |
kernelmajor=$(echo ${kernel} | cut -d . -f 1,2) |
kernelmajor=$(echo ${kernel} | cut -d . -f 1,2) |
606 |
|
|
607 |
# kernel image for 2.4 is vmlinux |
# kernel image for 2.4 is kernel |
608 |
if [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]] |
if [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]] |
609 |
then |
then |
610 |
if [[ ${kernelmajor} = 2.4 ]] |
if [[ ${kernelmajor} = 2.4 ]] |
617 |
if [[ -z ${initrdfile} ]] |
if [[ -z ${initrdfile} ]] |
618 |
then |
then |
619 |
INITRD_NAME_PREFIX="initrd" |
INITRD_NAME_PREFIX="initrd" |
620 |
|
if [[ -n ${dracut} ]] |
621 |
|
then |
622 |
|
INITRD_NAME_PREFIX="initramfs" |
623 |
|
fi |
624 |
|
|
625 |
if [[ $(uname -m) = ia64 ]] |
if [[ $(uname -m) = ia64 ]] |
626 |
then |
then |
631 |
fi |
fi |
632 |
[[ -n ${verbose} ]] && echo "initrdfile is ${initrdfile}" |
[[ -n ${verbose} ]] && echo "initrdfile is ${initrdfile}" |
633 |
|
|
634 |
|
# add dracut i18n, keyboard and plymouth kernel args if requested |
635 |
|
if [[ -n ${dracut} ]] || [[ -n ${adddracutargs} ]] |
636 |
|
then |
637 |
|
[ -r /etc/conf.d/keymap ] && . /etc/conf.d/keymap |
638 |
|
[ -r /etc/conf.d/consolefont ] && . /etc/conf.d/consolefont |
639 |
|
|
640 |
|
if [[ -n ${KEYMAP} ]] |
641 |
|
then |
642 |
|
kernargs="${kernargs} KEYTABLE=${KEYMAP}" |
643 |
|
fi |
644 |
|
|
645 |
|
if [[ -n ${CONSOLEFONT} ]] |
646 |
|
then |
647 |
|
kernargs="${kernargs} SYSFONT=${CONSOLEFONT}" |
648 |
|
fi |
649 |
|
fi |
650 |
|
|
651 |
# set this as the default if we have the package and it matches |
# set this as the default if we have the package and it matches |
652 |
if [[ ${mode} = --install ]] && [[ ${UPDATEDEFAULT} = yes ]] && [[ -n ${package} ]] && |
if [[ ${mode} = --install ]] && [[ ${UPDATEDEFAULT} = yes ]] && [[ -n ${package} ]] && |
653 |
[[ -n ${DEFAULTKERNEL} ]] && [[ ${package} = ${DEFAULTKERNEL} ]] |
[[ -n ${DEFAULTKERNEL} ]] && [[ ${package} = ${DEFAULTKERNEL} ]] |
681 |
[[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1 |
[[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1 |
682 |
[[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1 |
[[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1 |
683 |
|
|
684 |
|
# if we have a uBoot directory, check if it is mounted. |
685 |
|
# if not, mount it. Then check if a boot script exists. |
686 |
|
if [[ -n ${ubootDir} ]] |
687 |
|
then |
688 |
|
mountEntry=$(mount | grep ${ubootDir}) |
689 |
|
if [[ -z ${mountEntry} ]] |
690 |
|
then |
691 |
|
mount ${ubootDevice} ${ubootDir} |
692 |
|
mounted=1 |
693 |
|
fi |
694 |
|
[ -f ${ubootScript} ] && cfguBoot=1 |
695 |
|
fi |
696 |
|
|
697 |
# 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 |
698 |
# is lilo to determine if it should be run |
# is lilo to determine if it should be run |
699 |
if [[ -n ${cfgLilo} ]] && [[ -n ${isx86} ]] |
if [[ -n ${cfgLilo} ]] && [[ -n ${isx86} ]] |