Magellan Linux

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

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