Magellan Linux

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

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