Magellan Linux

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

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