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

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