Magellan Linux

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

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