25 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
26 |
# |
# |
27 |
|
|
28 |
|
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 |
PATH=/sbin:/bin:$PATH |
PATH=/sbin:/bin:$PATH |
55 |
|
|
56 |
lilo=/sbin/lilo |
lilo=/sbin/lilo |
66 |
fi |
fi |
67 |
|
|
68 |
[ -f /etc/conf.d/grubby ] && . /etc/conf.d/grubby |
[ -f /etc/conf.d/grubby ] && . /etc/conf.d/grubby |
69 |
|
[ -f /etc/conf.d/grubby-uboot ] && . /etc/conf.d/grubby-uboot |
70 |
|
|
71 |
|
cfgGrub2="" |
72 |
|
cfgGrub2Efi="" |
73 |
cfgGrub="" |
cfgGrub="" |
74 |
cfgLilo="" |
cfgLilo="" |
75 |
|
cfgExtlinux="" |
76 |
|
cfguBoot="" |
77 |
runLilo="" |
runLilo="" |
78 |
grubConfig="" |
grubConfig="" |
79 |
|
grub2Config="" |
80 |
|
grub2EfiConfig="" |
81 |
|
extlinuxConfig="" |
82 |
|
|
83 |
ARCH=$(uname -m) |
ARCH=$(uname -m) |
84 |
|
|
91 |
elif [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]] |
elif [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]] |
92 |
then |
then |
93 |
liloConfig=/etc/yaboot.conf |
liloConfig=/etc/yaboot.conf |
94 |
|
grub2Config=/boot/grub/grub.cfg |
95 |
bootPrefix=/boot |
bootPrefix=/boot |
96 |
lilo=/sbin/ybin |
lilo=/sbin/ybin |
97 |
liloFlag=yaboot |
liloFlag=yaboot |
112 |
lilo=/sbin/zipl |
lilo=/sbin/zipl |
113 |
runLilo="yes" |
runLilo="yes" |
114 |
isx86="" |
isx86="" |
115 |
|
elif [[ ${ARCH} =~ armv[5|7].*l ]] |
116 |
|
then |
117 |
|
liloConfig="" |
118 |
|
bootPrefix=/boot |
119 |
|
extlinuxConfig=$(readlink -f /etc/extlinux.conf 2>/dev/null) |
120 |
|
ubootDir=${UBOOT_DIR:-"/boot"} |
121 |
|
ubootScript=$ubootDir/${UBOOT_SCR:-"boot.scr"} |
122 |
|
ubootKList=${UBOOT_KLIST:-"klist.txt"} |
123 |
|
ubootDevice=/dev/${UBOOT_DEVICE:-"mmcblk0p1"} |
124 |
|
ubootDefaultImage=${UBOOT_UIMAGE:-"uImage"} |
125 |
|
ubootDefaultInitrd=${UBOOT_UINITRD:-"uInitrd"} |
126 |
|
ubootAddress=${UBOOT_IMGADDR:-"0x00008000"} |
127 |
|
mounted="" |
128 |
|
liloFlag="" |
129 |
|
isx86="" |
130 |
else |
else |
131 |
# this leaves i?86 and x86_64 |
# this leaves i?86 and x86_64 |
132 |
liloConfig=/etc/lilo.conf |
liloConfig=/etc/lilo.conf |
133 |
grubConfig=/boot/grub/grub.conf |
grubConfig=/boot/grub/grub.conf |
134 |
|
grub2Config=/boot/grub/grub.cfg |
135 |
|
grub2EfiConfig=/boot/grub/grub-efi.cfg |
136 |
|
extlinuxConfig=/boot/extlinux/extlinux.conf |
137 |
bootPrefix=/boot |
bootPrefix=/boot |
138 |
liloFlag=lilo |
liloFlag=lilo |
139 |
isx86="yes" |
isx86="yes" |
142 |
mode="" |
mode="" |
143 |
version="" |
version="" |
144 |
initrd="" |
initrd="" |
145 |
|
dracut="" |
146 |
|
dracuthostonly="" |
147 |
initrdfile="" |
initrdfile="" |
148 |
|
devtreefile="" |
149 |
moddep="" |
moddep="" |
150 |
verbose="" |
verbose="" |
151 |
makedefault="" |
makedefault="" |
152 |
package="" |
package="" |
153 |
mbkernel="" |
mbkernel="${HYPERVISOR}" |
154 |
mbargs="" |
mbargs="${HYPERVISOR_ARGS}" |
155 |
|
adddracutargs="" |
156 |
|
addplymouthinitrd="" |
157 |
|
|
158 |
usage() |
usage() |
159 |
{ |
{ |
160 |
echo "Usage: $(basename $0) [-v] [--mkinitrd] [--rminitrd]" >&2 |
echo "Usage: $(basename $0) [-v] [--mkinitrd] [--rminitrd] [--dracut]" >&2 |
161 |
echo " [--initrdfile=<initrd-image>] [--depmod] [--rmmoddep]" >&2 |
echo " [--initrdfile=<initrd-image>] [--depmod] [--rmmoddep]" >&2 |
162 |
echo " [--kernel-args=<args>] [--remove-args=<args>]" >&2 |
echo " [--kernel-args=<args>] [--remove-args=<args>]" >&2 |
163 |
echo " [--banner=<banner>] [--multiboot=multiboot]" >&2 |
echo " [--banner=<banner>] [--multiboot=multiboot]" >&2 |
164 |
echo " [--mbargs=mbargs] [--make-default]" >&2 |
echo " [--mbargs=mbargs] [--make-default] [--add-dracut-args]" >&2 |
165 |
|
echo " [--add-plymouth-initrd]" >&2 |
166 |
|
echo " [--host-only] [--devtree=<devicetree.dtb>]" >&2 |
167 |
echo " <--install | --remove | --update> <kernel-version>" >&2 |
echo " <--install | --remove | --update> <kernel-version>" >&2 |
168 |
echo " (ex: $(basename $0) --mkinitrd --depmod --install 2.4.7-2)" >&2 |
echo " (ex: $(basename $0) --mkinitrd --depmod --install 2.4.7-2)" >&2 |
169 |
exit 1 |
exit 1 |
172 |
install() |
install() |
173 |
{ |
{ |
174 |
# 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) |
175 |
if [ ! -f ${bootPrefix}/${kernelName}-${version} ] |
if [ ! -f ${kernelImage} ] |
176 |
then |
then |
177 |
[[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby" |
[[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby" |
178 |
return |
return |
183 |
then |
then |
184 |
[[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby" |
[[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby" |
185 |
INITRD="--initrd ${initrdfile}" |
INITRD="--initrd ${initrdfile}" |
186 |
|
|
187 |
|
if [[ -n ${addplymouthinitrd} ]] |
188 |
|
then |
189 |
|
INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img" |
190 |
|
fi |
191 |
|
fi |
192 |
|
|
193 |
|
DEVTREE="" |
194 |
|
if [ -f ${devtreefile} ] |
195 |
|
then |
196 |
|
[[ -n ${verbose} ]] && echo "found ${devtreefile} and using it with grubby" |
197 |
|
DEVTREE="--devtree ${devtreefile}" |
198 |
fi |
fi |
199 |
|
|
200 |
# 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? |
204 |
if [[ -z ${initrdfile} ]] |
if [[ -z ${initrdfile} ]] |
205 |
then |
then |
206 |
[[ -n ${verbose} ]] && echo "No initrd, just adding system map" |
[[ -n ${verbose} ]] && echo "No initrd, just adding system map" |
207 |
/sbin/addSystemMap ${bootPrefix}/System.map-${version} ${bootPrefix}/${kernelName}-${version} ${bootPrefix}/vmlinitrd-${version} |
/sbin/addSystemMap ${bootPrefix}/System.map-${version} ${kernelImage} ${bootPrefix}/vmlinitrd-${version} |
208 |
else |
else |
209 |
/sbin/addSystemMap ${bootPrefix}/System.map-${version} ${bootPrefix}/${kernelName}-${version} ${bootPrefix}/vmlinux.sm-${version} |
/sbin/addSystemMap ${bootPrefix}/System.map-${version} ${kernelImage} ${bootPrefix}/vmlinux.sm-${version} |
210 |
/sbin/addRamDisk ${initrdfile} ${bootPrefix}/System.map-${version} ${bootPrefix}/vmlinux.sm-${version} ${bootPrefix}/vmlinitrd-${version} 2>/dev/null |
/sbin/addRamDisk ${initrdfile} ${bootPrefix}/System.map-${version} ${bootPrefix}/vmlinux.sm-${version} ${bootPrefix}/vmlinitrd-${version} 2>/dev/null |
211 |
rm ${bootPrefix}/vmlinux.sm-${version} |
rm ${bootPrefix}/vmlinux.sm-${version} |
212 |
fi |
fi |
214 |
fi |
fi |
215 |
|
|
216 |
# get the root filesystem to use |
# get the root filesystem to use |
217 |
rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab) |
rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab 2>/dev/null) |
218 |
|
if [[ -z $rootdevice ]] |
219 |
|
then |
220 |
|
rootdevice=$(grep -o -P "(?<=root=)\S+" /proc/cmdline) |
221 |
|
fi |
222 |
|
|
223 |
if [[ -n ${mbkernel} ]] && [[ -n ${cfgLilo} ]] && [[ ${liloFlag} != elilo ]] |
if [[ -n ${mbkernel} ]] && [[ -n ${cfgLilo} ]] && [[ ${liloFlag} != elilo ]] |
224 |
then |
then |
226 |
cfgLilo="" |
cfgLilo="" |
227 |
fi |
fi |
228 |
|
|
229 |
if [[ -n ${cfgGrub} ]] |
if [[ -n ${banner} ]] |
230 |
then |
then |
231 |
[[ -n ${verbose} ]] && echo "adding ${version} to ${grubConfig}" |
if [[ ${ARCH} = s390 ]] || [[ ${ARCH} = s390x ]] |
|
|
|
|
if [[ -n ${banner} ]] |
|
232 |
then |
then |
233 |
title="${banner} (${version})" |
title=$(echo ${banner} | sed 's/ /_/g') |
|
elif [ -f /etc/mageversion ] |
|
|
then |
|
|
title="Magellan Linux $(< /etc/mageversion) (${version})" |
|
234 |
else |
else |
235 |
title="Magellan Linux (${version})" |
title="${banner} [ ${version} ]" |
236 |
fi |
fi |
237 |
${grubby} --add-kernel=${bootPrefix}/${kernelName}-${version} \ |
elif [[ ${ARCH} = s390 ]] || [[ ${ARCH} = s390x ]] |
238 |
|
then |
239 |
|
title=$(echo ${version} | sed 's/ /_/g') |
240 |
|
elif [ -f /etc/os-release ] |
241 |
|
then |
242 |
|
title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]" |
243 |
|
elif [ -f /etc/mageversion ] |
244 |
|
then |
245 |
|
title="Magellan Linux $(< /etc/mageversion) [ ${version} ]" |
246 |
|
else |
247 |
|
title="Magellan Linux [ ${version} ]" |
248 |
|
fi |
249 |
|
|
250 |
|
if [[ -n ${cfgGrub} ]] |
251 |
|
then |
252 |
|
[[ -n ${verbose} ]] && echo "adding ${version} to ${grubConfig}" |
253 |
|
|
254 |
|
${grubby} --grub -c ${grubConfig} \ |
255 |
|
--add-kernel=${kernelImage} \ |
256 |
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
257 |
${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \ |
${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \ |
258 |
--args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}" |
--args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}" |
259 |
else |
else |
260 |
[[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby" |
[[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97" |
261 |
|
fi |
262 |
|
if [[ -n ${cfgGrub2} ]] |
263 |
|
then |
264 |
|
[[ -n ${verbose} ]] && echo "adding ${version} to ${grub2Config}" |
265 |
|
|
266 |
|
${grubby} --grub2 -c ${grub2Config} \ |
267 |
|
--add-kernel=${kernelImage} \ |
268 |
|
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
269 |
|
${mbkernel:+--add-multiboot="${mbkernel}"} \ |
270 |
|
${mbargs:+--mbargs="${mbargs}"} \ |
271 |
|
--args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}" |
272 |
|
else |
273 |
|
[[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby for grub 2" |
274 |
|
fi |
275 |
|
if [[ -n ${cfgGrub2Efi} ]] |
276 |
|
then |
277 |
|
[[ -n ${verbose} ]] && echo "adding ${version} to ${grub2EfiConfig}" |
278 |
|
|
279 |
|
${grubby} --grub2 -c ${grub2EfiConfig} --efi \ |
280 |
|
--add-kernel=${kernelImage} ${DEVTREE} \ |
281 |
|
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
282 |
|
${mbkernel:+--add-multiboot="${mbkernel}"} \ |
283 |
|
${mbargs:+--mbargs="${mbargs}"} \ |
284 |
|
--args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}" |
285 |
|
else |
286 |
|
[[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby for grub 2 with UEFI" |
287 |
fi |
fi |
288 |
|
|
289 |
if [[ -n ${cfgLilo} ]] |
if [[ -n ${cfgLilo} ]] |
290 |
then |
then |
291 |
[[ -n ${verbose} ]] && echo "adding ${version} to ${liloConfig}" |
[[ -n ${verbose} ]] && echo "adding ${version} to ${liloConfig}" |
292 |
|
|
293 |
${grubby} --add-kernel=${bootPrefix}/${kernelName}-${version} ${INITRD} \ |
${grubby} --add-kernel=${kernelImage} ${INITRD} \ |
294 |
--copy-default ${makedefault} --title ${version} \ |
--copy-default ${makedefault} --title "${title}" \ |
295 |
${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \ |
${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \ |
296 |
--args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${version}" \ |
--args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${version}" \ |
297 |
--${liloFlag} |
--${liloFlag} |
299 |
if [[ -n ${runLilo} ]] |
if [[ -n ${runLilo} ]] |
300 |
then |
then |
301 |
[[ -n ${verbose} ]] && echo "running ${lilo}" |
[[ -n ${verbose} ]] && echo "running ${lilo}" |
302 |
if [ ! -x $lilo ] |
if [ ! -x ${lilo} ] |
303 |
then |
then |
304 |
[[ -n ${verbose} ]] && echo "${lilo} does not exist" |
[[ -n ${verbose} ]] && echo "${lilo} does not exist" |
305 |
else |
else |
309 |
else |
else |
310 |
[[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
[[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
311 |
fi |
fi |
312 |
|
|
313 |
|
if [[ -n ${cfgExtlinux} ]] |
314 |
|
then |
315 |
|
[[ -n ${verbose} ]] && echo "adding ${version} to ${extlinuxConfig}" |
316 |
|
|
317 |
|
${grubby} --extlinux -c ${extlinuxConfig} \ |
318 |
|
--add-kernel=${kernelImage} \ |
319 |
|
${INITRD} --copy-default ${makedefault} --title "${title}" \ |
320 |
|
${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \ |
321 |
|
--args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}" |
322 |
|
else |
323 |
|
[[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux" |
324 |
|
fi |
325 |
} |
} |
326 |
|
|
327 |
remove() |
remove() |
330 |
if [ -d /proc/iSeries ] |
if [ -d /proc/iSeries ] |
331 |
then |
then |
332 |
[[ -n ${verbose} ]] && echo "On an iSeries, remove img file" |
[[ -n ${verbose} ]] && echo "On an iSeries, remove img file" |
333 |
rm -f ${bootPrefix}/${kernelName}-${version}.img 2>/dev/null |
rm -f ${kernelImage}.img 2>/dev/null |
334 |
return |
return |
335 |
fi |
fi |
336 |
|
|
337 |
if [[ -n ${cfgGrub} ]] |
if [[ -n ${cfgGrub} ]] |
338 |
then |
then |
339 |
[[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}" |
[[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}" |
340 |
${grubby} --remove-kernel=${bootPrefix}/${kernelName}-${version} |
${grubby} --grub -c ${grubConfig} \ |
341 |
|
--remove-kernel=${kernelImage} |
342 |
else |
else |
343 |
[[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby" |
[[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97" |
344 |
|
fi |
345 |
|
if [[ -n ${cfgGrub2} ]] |
346 |
|
then |
347 |
|
[[ -n ${verbose} ]] && echo "removing ${version} from ${grub2Config}" |
348 |
|
${grubby} --grub2 -c ${grub2Config} \ |
349 |
|
--remove-kernel=${kernelImage} |
350 |
|
else |
351 |
|
[[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby for grub 2" |
352 |
|
fi |
353 |
|
if [[ -n ${cfgGrub2Efi} ]] |
354 |
|
then |
355 |
|
[[ -n ${verbose} ]] && echo "removing ${version} from ${grub2EfiConfig}" |
356 |
|
${grubby} --grub2 -c ${grub2EfiConfig} --efi \ |
357 |
|
--remove-kernel=${kernelImage} |
358 |
|
else |
359 |
|
[[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby grub 2 with UEFI" |
360 |
fi |
fi |
361 |
|
|
362 |
if [[ -n ${cfgLilo} ]] |
if [[ -n ${cfgLilo} ]] |
363 |
then |
then |
364 |
[[ -n ${verbose} ]] && echo "removing ${version} from ${liloConfig}" |
[[ -n ${verbose} ]] && echo "removing ${version} from ${liloConfig}" |
365 |
${grubby} --remove-kernel=${bootPrefix}/${kernelName}-${version} \ |
${grubby} --remove-kernel=${kernelImage} --${liloFlag} |
|
--${liloFlag} |
|
366 |
|
|
367 |
if [[ -n ${runLilo} ]] |
if [[ -n ${runLilo} ]] |
368 |
then |
then |
377 |
else |
else |
378 |
[[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
[[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
379 |
fi |
fi |
380 |
|
|
381 |
|
if [[ -n ${cfguBoot} ]] |
382 |
|
then |
383 |
|
[[ -n ${verbose} ]] && echo "removing ${version} from ${ubootDir}..." |
384 |
|
|
385 |
|
if [ -f ${ubootDir}/${ubootKList} ] |
386 |
|
then |
387 |
|
tmpKList=$(mktemp ${ubootDir}/${ubootKList}.XXXX) |
388 |
|
curversion=$(tail -n1 ${ubootDir}/${ubootKList}) |
389 |
|
sed "/$version$/d" ${ubootDir}/${ubootKList} > ${tmpKList} |
390 |
|
newversion=$(tail -n1 ${tmpKList}) |
391 |
|
if [ -f ${ubootDir}/uImage-${newversion} ] && [ -f ${ubootDir}/uInitrd-${newversion} ] |
392 |
|
then |
393 |
|
if [[ ${curversion} != ${newversion} ]] |
394 |
|
then |
395 |
|
cp -fp ${ubootDir}/uImage-${newversion} ${ubootDir}/${ubootDefaultImage} |
396 |
|
if [ $? -ne 0 ] |
397 |
|
then |
398 |
|
[[ -n ${verbose} ]] && echo "copy uImage-${newversion} error, default kernel not replaced!" && exit |
399 |
|
fi |
400 |
|
cp -fp ${ubootDir}/uInitrd-${newversion} ${ubootDir}/${ubootDefaultInitrd} |
401 |
|
if [ $? -ne 0 ] |
402 |
|
then |
403 |
|
[[ -n ${verbose} ]] && echo "copy uInitrd-${newversion} error, default Initrd not replaced!" && exit |
404 |
|
fi |
405 |
|
fi |
406 |
|
|
407 |
|
[[ -n ${verbose} ]] && echo "removing uImage-${version}" |
408 |
|
if [ -f ${ubootDir}/uImage-${version} ] |
409 |
|
then |
410 |
|
rm -f ${ubootDir}/uImage-${version} |
411 |
|
else |
412 |
|
[[ -n ${verbose} ]] && echo "uImage-${version} did not exist!" |
413 |
|
fi |
414 |
|
|
415 |
|
[[ -n ${verbose} ]] && echo "removing uInitrd-${version}" |
416 |
|
if [ -f ${ubootDir}/uInitrd-${version} ] |
417 |
|
then |
418 |
|
rm -f ${ubootDir}/uInitrd-${version} |
419 |
|
else |
420 |
|
[[ -n ${verbose} ]] && echo "uInitrd-${version} did not exist!" |
421 |
|
fi |
422 |
|
|
423 |
|
mv ${tmpKList} ${ubootDir}/${ubootKList} |
424 |
|
[ -x /sbin/a-b-c ] && /sbin/a-b-c |
425 |
|
else |
426 |
|
[[ -n ${verbose} ]] && echo "uImage ${newversion} does not exist!" |
427 |
|
[ -f ${tmpKList} ] && rm -f ${tmpKList} |
428 |
|
fi |
429 |
|
else |
430 |
|
[[ -n ${verbose} ]] && echo "No previous kernel version. U-Boot images not removed!" |
431 |
|
fi |
432 |
|
else |
433 |
|
[[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}" |
434 |
|
fi |
435 |
|
|
436 |
|
if [[ -n ${cfgExtlinux} ]] |
437 |
|
then |
438 |
|
[[ -n ${verbose} ]] && echo "removing ${version} from ${extlinuxConfig}" |
439 |
|
${grubby} --extlinux -c ${extlinuxConfig} \ |
440 |
|
--remove-kernel=${kernelImage} |
441 |
|
else |
442 |
|
[[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux" |
443 |
|
fi |
444 |
} |
} |
445 |
|
|
446 |
update() |
update() |
447 |
{ |
{ |
448 |
|
if [ ! -f ${kernelImage} ] |
449 |
|
then |
450 |
|
[[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby" |
451 |
|
return |
452 |
|
fi |
453 |
|
|
454 |
|
INITRD="" |
455 |
|
if [ -f ${initrdfile} ] |
456 |
|
then |
457 |
|
[[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby" |
458 |
|
INITRD="--initrd ${initrdfile}" |
459 |
|
|
460 |
|
if [[ -n ${addplymouthinitrd} ]] |
461 |
|
then |
462 |
|
INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img" |
463 |
|
fi |
464 |
|
fi |
465 |
|
|
466 |
if [[ -n ${cfgGrub} ]] |
if [[ -n ${cfgGrub} ]] |
467 |
then |
then |
468 |
[[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}" |
[[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}" |
469 |
${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \ |
${grubby} --grub -c ${grubConfig} \ |
470 |
|
--update-kernel=${kernelImage} \ |
471 |
|
${INITRD} \ |
472 |
${kernargs:+--args="${kernargs}"} \ |
${kernargs:+--args="${kernargs}"} \ |
473 |
${removeargs:+--remove-args="${removeargs}"} |
${removeargs:+--remove-args="${removeargs}"} \ |
474 |
|
${mbkernel:+--add-multiboot="${mbkernel}"} |
475 |
else |
else |
476 |
[[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby" |
[[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby" |
477 |
fi |
fi |
478 |
|
|
479 |
|
if [[ -n ${cfgGrub2} ]] |
480 |
|
then |
481 |
|
[[ -n ${verbose} ]] && echo "updating ${version} from ${grub2Config}" |
482 |
|
${grubby} --grub2 -c ${grub2Config} \ |
483 |
|
--update-kernel=${kernelImage} \ |
484 |
|
${INITRD} \ |
485 |
|
${kernargs:+--args="${kernargs}"} \ |
486 |
|
${removeargs:+--remove-args="${removeargs}"} |
487 |
|
else |
488 |
|
[[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby" |
489 |
|
fi |
490 |
|
|
491 |
|
if [[ -n ${cfgGrub2Efi} ]] |
492 |
|
then |
493 |
|
[[ -n ${verbose} ]] && echo "updating ${version} from ${grub2EfiConfig}" |
494 |
|
${grubby} --grub2 -c ${grub2EfiConfig} --efi \ |
495 |
|
--update-kernel=${kernelImage} \ |
496 |
|
${INITRD} \ |
497 |
|
${kernargs:+--args="${kernargs}"} \ |
498 |
|
${removeargs:+--remove-args="${removeargs}"} |
499 |
|
else |
500 |
|
[[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby" |
501 |
|
fi |
502 |
|
|
503 |
if [[ -n ${cfgLilo} ]] |
if [[ -n ${cfgLilo} ]] |
504 |
then |
then |
505 |
[[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}" |
[[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}" |
506 |
${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \ |
${grubby} --update-kernel=${kernelImage} \ |
507 |
|
${INITRD} \ |
508 |
${kernargs:+--args="${kernargs}"} \ |
${kernargs:+--args="${kernargs}"} \ |
509 |
${removeargs:+--remove-args="${removeargs}"} \ |
${removeargs:+--remove-args="${removeargs}"} \ |
510 |
--${liloFlag} |
--${liloFlag} |
522 |
else |
else |
523 |
[[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
[[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby" |
524 |
fi |
fi |
525 |
|
|
526 |
|
if [[ -n ${cfguBoot} ]] |
527 |
|
then |
528 |
|
[[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..." |
529 |
|
|
530 |
|
[[ -n ${verbose} ]] && echo "creating uImage-${version}" |
531 |
|
mkimage -A arm -O linux -T kernel -C none -a ${ubootAddress} \ |
532 |
|
-e ${ubootAddress} -n ${version} \ |
533 |
|
-d ${kernelImage} ${ubootDir}/uImage-${version} |
534 |
|
|
535 |
|
[[ -n ${verbose} ]] && echo "creating uInitrd-${version}" |
536 |
|
mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 \ |
537 |
|
-n initramfs -d ${initrdfile} ${ubootDir}/uInitrd-${version} |
538 |
|
|
539 |
|
if [ -f ${ubootDir}/uImage-${version} ] && [ -f ${ubootDir}/uInitrd-${version} ] |
540 |
|
then |
541 |
|
cp -fp ${ubootDir}/uImage-${version} ${ubootDir}/${ubootDefaultImage} |
542 |
|
if [ $? -ne 0 ] |
543 |
|
then |
544 |
|
[[ -n ${verbose} ]] && echo "copy uImage-${version} error, kernel not installed!" && exit |
545 |
|
fi |
546 |
|
cp -fp ${ubootDir}/uInitrd-${version} ${ubootDir}/${ubootDefaultInitrd} |
547 |
|
if [ $? -ne 0 ] |
548 |
|
then |
549 |
|
[[ -n ${verbose} ]] && echo "copy uInitrd-${version} error, kernel not installed!" && exit |
550 |
|
fi |
551 |
|
echo ${version} >> ${ubootDir}/${ubootKList} |
552 |
|
[ -x /sbin/a-b-c ] && /sbin/a-b-c |
553 |
|
else |
554 |
|
[[ -n ${verbose} ]] && echo "cannot make ${version} the default" |
555 |
|
fi |
556 |
|
else |
557 |
|
[[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not setting up ${ubootDir}" |
558 |
|
fi |
559 |
|
|
560 |
|
if [[ -n ${cfgExtlinux} ]] |
561 |
|
then |
562 |
|
[[ -n ${verbose} ]] && echo "updating ${version} from ${extlinuxConfig}" |
563 |
|
${grubby} --extlinux -c ${extlinuxConfig} \ |
564 |
|
--update-kernel=${kernelImage} \ |
565 |
|
${INITRD} \ |
566 |
|
${kernargs:+--args="${kernargs}"} \ |
567 |
|
${removeargs:+--remove-args="${removeargs}"} |
568 |
|
else |
569 |
|
[[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby" |
570 |
|
fi |
571 |
} |
} |
572 |
|
|
573 |
mkinitrd() |
makeinitrd() |
574 |
{ |
{ |
575 |
|
if [[ -n ${dracut} ]] |
576 |
|
then |
577 |
|
tool="dracut ${dracuthostonly} -f ${initrdfile} ${version}" |
578 |
|
else |
579 |
|
tool="mkinitrd --allow-missing -f ${initrdfile} ${version}" |
580 |
|
fi |
581 |
[[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}" |
[[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}" |
582 |
/sbin/mkinitrd --allow-missing -f ${initrdfile} ${version} |
${tool} |
583 |
rc=$? |
rc=$? |
584 |
if [ ${rc} != 0 ] |
if [ ${rc} != 0 ] |
585 |
then |
then |
603 |
doRmmoddep() |
doRmmoddep() |
604 |
{ |
{ |
605 |
[[ -n ${verbose} ]] && echo "removing modules.dep info for ${version}" |
[[ -n ${verbose} ]] && echo "removing modules.dep info for ${version}" |
606 |
[ -d /lib/modules/${version} ] && rm -f /lib/modules/${version}/modules.* |
if [ -d /lib/modules/${version} ] |
607 |
|
then |
608 |
|
rm -f /lib/modules/${version}/modules.*.bin \ |
609 |
|
/lib/modules/${version}/modules.{alias,dep,devname,symbols,softdep} |
610 |
|
fi |
611 |
} |
} |
612 |
|
|
613 |
|
|
622 |
initrd="remove" |
initrd="remove" |
623 |
;; |
;; |
624 |
|
|
625 |
|
--devtree*) |
626 |
|
if [[ $1 == --devtree\=* ]] |
627 |
|
then |
628 |
|
devtreefile="${1#--devtreefile=}" |
629 |
|
else |
630 |
|
devtreefile="$2" |
631 |
|
shift |
632 |
|
fi |
633 |
|
;; |
634 |
|
|
635 |
|
--dracut) |
636 |
|
dracut=--dracut |
637 |
|
;; |
638 |
|
|
639 |
|
--host-only) |
640 |
|
dracuthostonly=-H |
641 |
|
;; |
642 |
|
|
643 |
--initrdfile*) |
--initrdfile*) |
644 |
if echo $1 | grep '=' >/dev/null |
if [[ $1 == --initrdfile\=* ]] |
645 |
then |
then |
646 |
initrdfile=$(echo $1 | sed 's/^--initrdfile=//') |
initrdfile=${1#--initrdfile=} |
647 |
else |
else |
648 |
initrdfile=$2 |
initrdfile=$2 |
649 |
shift |
shift |
651 |
;; |
;; |
652 |
|
|
653 |
--kernel-args*) |
--kernel-args*) |
654 |
if echo $1 | grep '=' >/dev/null |
if [[ $1 == --kernel-args\=* ]] |
655 |
then |
then |
656 |
kernargs=$(echo $1 | sed 's/^--kernel-args=//') |
kernargs=${1#--kernel-args=} |
657 |
else |
else |
658 |
kernargs=$2 |
kernargs=$2 |
659 |
shift |
shift |
661 |
;; |
;; |
662 |
|
|
663 |
--remove-args*) |
--remove-args*) |
664 |
if echo $1 | grep '=' >/dev/null |
if [[ $1 == --remove-args\=* ]] |
665 |
then |
then |
666 |
removeargs=$(echo $1 | sed 's/^--remove-args=//') |
removeargs=${1#--remove-args=} |
667 |
else |
else |
668 |
removeargs=$2 |
removeargs=$2 |
669 |
shift |
shift |
671 |
;; |
;; |
672 |
|
|
673 |
--banner*) |
--banner*) |
674 |
if echo $1 | grep '=' >/dev/null |
if [[ $1 == --banner\=* ]] |
675 |
then |
then |
676 |
banner=$(echo $1 | sed 's/^--banner=//') |
banner=${1#--banner=} |
677 |
else |
else |
678 |
banner=$2 |
banner=$2 |
679 |
shift |
shift |
681 |
;; |
;; |
682 |
|
|
683 |
--multiboot*) |
--multiboot*) |
684 |
if echo $1 |grep '=' >/dev/null |
if [[ $1 == --multiboot\=* ]] |
685 |
then |
then |
686 |
mbkernel=$(echo $1 | sed 's/^--multiboot=//') |
mbkernel=${1#--multiboot=} |
687 |
else |
else |
688 |
# can't really support having an optional second arg here |
# can't really support having an optional second arg here |
689 |
# sorry! |
# sorry! |
692 |
;; |
;; |
693 |
|
|
694 |
--mbargs*) |
--mbargs*) |
695 |
if echo $1 |grep '=' >/dev/null |
if [[ $1 == --mbargs\=* ]] |
696 |
then |
then |
697 |
mbargs=$(echo $1 | sed 's/^--mbargs=//') |
mbargs=${1#--mbargs=} |
698 |
else |
else |
699 |
mbargs="$2" |
mbargs="$2" |
700 |
shift |
shift |
713 |
makedefault="--make-default" |
makedefault="--make-default" |
714 |
;; |
;; |
715 |
|
|
716 |
--package) |
--package*) |
717 |
if echo $1 | grep '=' >/dev/null |
if [[ $1 == --package\=* ]] |
718 |
then |
then |
719 |
package=$(echo $1 | sed 's/^--package=//') |
package=${1#--package=} |
720 |
else |
else |
721 |
package=$2 |
package=$2 |
722 |
shift |
shift |
723 |
fi |
fi |
724 |
;; |
;; |
725 |
|
|
726 |
|
--add-dracut-args) |
727 |
|
adddracutargs=--add-dracut-args |
728 |
|
;; |
729 |
|
|
730 |
|
--add-plymouth-initrd) |
731 |
|
addplymouthinitrd=--add-plymouth-initrd |
732 |
|
;; |
733 |
|
|
734 |
|
--kernel-image*) |
735 |
|
if [[ $1 == --kernel-image\=* ]] |
736 |
|
then |
737 |
|
kernelImage=${1#--kernel-image=} |
738 |
|
else |
739 |
|
kernelImage="$2" |
740 |
|
shift |
741 |
|
fi |
742 |
|
if ! [[ -f ${kernelImage} ]] |
743 |
|
then |
744 |
|
echo "Can't find kernel image '${kernelImage}'" >&2 |
745 |
|
usage |
746 |
|
exit 1 |
747 |
|
fi |
748 |
|
;; |
749 |
|
|
750 |
-v) |
-v) |
751 |
verbose=-v |
verbose=-v |
752 |
;; |
;; |
785 |
|
|
786 |
kernelmajor=$(echo ${kernel} | cut -d . -f 1,2) |
kernelmajor=$(echo ${kernel} | cut -d . -f 1,2) |
787 |
|
|
788 |
# kernel image for 2.4 is vmlinux |
# kernel image for 2.4 is kernel |
789 |
if [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]] |
if [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]] |
790 |
then |
then |
791 |
if [[ ${kernelmajor} = 2.4 ]] |
if [[ ${kernelmajor} = 2.4 ]] |
794 |
fi |
fi |
795 |
fi |
fi |
796 |
|
|
797 |
|
[[ ${kernelImage} ]] || kernelImage="${bootPrefix}/${kernelName}-${version}" |
798 |
|
|
799 |
# 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 |
800 |
if [[ -z ${initrdfile} ]] |
if [[ -z ${initrdfile} ]] |
801 |
then |
then |
802 |
INITRD_NAME_PREFIX="initrd" |
INITRD_NAME_PREFIX="initrd" |
803 |
|
if [[ -n ${dracut} ]] |
804 |
|
then |
805 |
|
INITRD_NAME_PREFIX="initramfs" |
806 |
|
fi |
807 |
|
|
808 |
if [[ $(uname -m) = ia64 ]] |
if [[ $(uname -m) = ia64 ]] |
809 |
then |
then |
814 |
fi |
fi |
815 |
[[ -n ${verbose} ]] && echo "initrdfile is ${initrdfile}" |
[[ -n ${verbose} ]] && echo "initrdfile is ${initrdfile}" |
816 |
|
|
817 |
|
# add dracut i18n, keyboard and plymouth kernel args if requested |
818 |
|
if [[ -n ${dracut} ]] || [[ -n ${adddracutargs} ]] |
819 |
|
then |
820 |
|
if [ -r /etc/vconsole.conf ] |
821 |
|
then |
822 |
|
. /etc/vconsole.conf |
823 |
|
|
824 |
|
for i in SYSFONT SYSFONTACM UNIMAP KEYTABLE |
825 |
|
do |
826 |
|
val=$(eval echo \$$i) |
827 |
|
[[ -n ${val} ]] && kernargs="${kernargs} ${i}=${val}" |
828 |
|
done |
829 |
|
else |
830 |
|
if [ -r /etc/conf.d/consolefont ] |
831 |
|
then |
832 |
|
. /etc/conf.d/consolefont |
833 |
|
|
834 |
|
if [[ -n ${CONSOLEFONT} ]] |
835 |
|
then |
836 |
|
kernargs="${kernargs} SYSFONT=${CONSOLEFONT}" |
837 |
|
fi |
838 |
|
fi |
839 |
|
|
840 |
|
if [ -r /etc/conf.d/keymap ] |
841 |
|
then |
842 |
|
. /etc/conf.d/keymap |
843 |
|
|
844 |
|
if [[ -n ${KEYMAP} ]] |
845 |
|
then |
846 |
|
kernargs="${kernargs} KEYTABLE=${KEYMAP}" |
847 |
|
fi |
848 |
|
fi |
849 |
|
fi |
850 |
|
|
851 |
|
if [ -r /etc/locale.conf ] |
852 |
|
then |
853 |
|
. /etc/locale.conf |
854 |
|
|
855 |
|
if [[ -n ${LANG} ]] |
856 |
|
then |
857 |
|
kernargs="${kernargs} LANG=${LANG}" |
858 |
|
fi |
859 |
|
fi |
860 |
|
fi |
861 |
|
|
862 |
# 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 |
863 |
if [[ ${mode} = --install ]] && [[ ${UPDATEDEFAULT} = yes ]] && [[ -n ${package} ]] && |
if [[ ${mode} = --install ]] && [[ ${UPDATEDEFAULT} = yes ]] && [[ -n ${package} ]] && |
864 |
[[ -n ${DEFAULTKERNEL} ]] && [[ ${package} = ${DEFAULTKERNEL} ]] |
[[ -n ${DEFAULTKERNEL} ]] && [[ ${package} = ${DEFAULTKERNEL} ]] |
877 |
|
|
878 |
if [[ ${initrd} = make ]] |
if [[ ${initrd} = make ]] |
879 |
then |
then |
880 |
mkinitrd |
makeinitrd |
881 |
elif [[ ${initrd} = remove ]] |
elif [[ ${initrd} = remove ]] |
882 |
then |
then |
883 |
rminitrd |
rminitrd |
890 |
fi |
fi |
891 |
|
|
892 |
[[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1 |
[[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1 |
893 |
|
[[ -n ${grub2Config} ]] && [ -f ${grub2Config} ] && cfgGrub2=1 |
894 |
|
[[ -n ${grub2EfiConfig} ]] && [ -f ${grub2EfiConfig} ] && cfgGrub2Efi=1 |
895 |
[[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1 |
[[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1 |
896 |
|
[[ -n ${extlinuxConfig} ]] && [ -f ${extlinuxConfig} ] && cfgExtlinux=1 |
897 |
|
|
898 |
|
# if we have a U-Boot directory, but no boot script, check if the directory |
899 |
|
# is mounted. If not, mount it, and then check if a boot script exists. |
900 |
|
if [[ -n ${ubootDir} ]] |
901 |
|
then |
902 |
|
if [ -f ${ubootScript} ] |
903 |
|
then |
904 |
|
cfguBoot=1 |
905 |
|
else |
906 |
|
mountEntry=$(mount | grep ${ubootDir}) |
907 |
|
if [[ -z ${mountEntry} ]] |
908 |
|
then |
909 |
|
mount ${ubootDevice} ${ubootDir} |
910 |
|
mounted=1 |
911 |
|
fi |
912 |
|
[ -f ${ubootScript} ] && cfguBoot=1 |
913 |
|
fi |
914 |
|
fi |
915 |
|
|
916 |
|
# if we're using U-Boot, check if the default load address should change |
917 |
|
if [[ -n ${cfguBoot} ]] && [[ -z ${UBOOT_IMGADDR} ]] |
918 |
|
then |
919 |
|
[[ ${version} =~ .([^.]*)$ ]] |
920 |
|
platform=${BASH_REMATCH[1]} |
921 |
|
# A few platforms use an alternate kernel load address |
922 |
|
if [[ ${platform} = omap ]] |
923 |
|
then |
924 |
|
ubootAddress=0x80008000 |
925 |
|
elif [[ ${platform} = imx ]] |
926 |
|
then |
927 |
|
ubootAddress=0x90008000 |
928 |
|
fi |
929 |
|
fi |
930 |
|
|
931 |
# 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 |
932 |
# is lilo to determine if it should be run |
# is lilo to determine if it should be run |
946 |
update |
update |
947 |
fi |
fi |
948 |
|
|
949 |
|
# if we mounted the U-Boot directory, unmount it. |
950 |
|
[[ -n ${mounted} ]] && umount ${ubootDir} |
951 |
|
|
952 |
exit 0 |
exit 0 |