Magellan Linux

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