Magellan Linux

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

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