Magellan Linux

Diff of /tags/grubby-8_21/new-kernel-pkg

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.532  
changed lines
  Added in v.1848