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 924 by niro, Wed Oct 28 13:26:45 2009 UTC trunk/grubby/new-kernel-pkg revision 2972 by niro, Thu Jun 30 10:17:00 2016 UTC
# Line 25  Line 25 
25  # along with this program.  If not, see <http://www.gnu.org/licenses/>.  # 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    
56  lilo=/sbin/lilo  lilo=/sbin/lilo
# Line 39  else Line 65  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    ubootScript="/boot/boot.scr"
83    
84  ARCH=$(uname -m)  ARCH=$(uname -m)
85    
# Line 57  then Line 92  then
92  elif [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]]  elif [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]]
93  then  then
94   liloConfig=/etc/yaboot.conf   liloConfig=/etc/yaboot.conf
95     grub2Config=/boot/grub/grub.cfg
96   bootPrefix=/boot   bootPrefix=/boot
97   lilo=/sbin/ybin   lilo=/sbin/ybin
98   liloFlag=yaboot   liloFlag=yaboot
# Line 77  then Line 113  then
113   lilo=/sbin/zipl   lilo=/sbin/zipl
114   runLilo="yes"   runLilo="yes"
115   isx86=""   isx86=""
116    elif [[ ${ARCH} =~ armv[5|7].*l ]]
117    then
118     liloConfig=""
119     bootPrefix=/boot
120     extlinuxConfig=$(readlink -f /etc/extlinux.conf 2>/dev/null)
121     ubootDir=${UBOOT_DIR:-"/boot"}
122     ubootScript=$ubootDir/${UBOOT_SCR:-"boot.scr"}
123     ubootKList=${UBOOT_KLIST:-"klist.txt"}
124     ubootDevice=/dev/${UBOOT_DEVICE:-"mmcblk0p1"}
125     ubootDefaultImage=${UBOOT_UIMAGE:-"uImage"}
126     ubootDefaultInitrd=${UBOOT_UINITRD:-"uInitrd"}
127     ubootAddress=${UBOOT_IMGADDR:-"0x00008000"}
128     mounted=""
129     liloFlag=""
130     isx86=""
131  else  else
132   # this leaves i?86 and x86_64   # this leaves i?86 and x86_64
133   liloConfig=/etc/lilo.conf   liloConfig=/etc/lilo.conf
134   grubConfig=/boot/grub/grub.conf   grubConfig=/boot/grub/grub.conf
135     grub2Config=/boot/grub/grub.cfg
136     grub2EfiConfig=/boot/grub/grub-efi.cfg
137     extlinuxConfig=/boot/extlinux/extlinux.conf
138   bootPrefix=/boot   bootPrefix=/boot
139   liloFlag=lilo   liloFlag=lilo
140   isx86="yes"   isx86="yes"
# Line 89  fi Line 143  fi
143  mode=""  mode=""
144  version=""  version=""
145  initrd=""  initrd=""
146    dracut=""
147    dracuthostonly=""
148  initrdfile=""  initrdfile=""
149    devtreefile=""
150  moddep=""  moddep=""
151  verbose=""  verbose=""
152  makedefault=""  makedefault=""
153  package=""  package=""
154  mbkernel=""  mbkernel="${HYPERVISOR}"
155  mbargs=""  mbargs="${HYPERVISOR_ARGS}"
156    adddracutargs=""
157    addplymouthinitrd=""
158    DEBUGARG="systemd.debug"
159    
160  usage()  usage()
161  {  {
162   echo "Usage: $(basename $0) [-v] [--mkinitrd] [--rminitrd]" >&2   echo "Usage: $(basename $0) [-v] [--mkinitrd] [--rminitrd] [--dracut]" >&2
163   echo "       [--initrdfile=<initrd-image>] [--depmod] [--rmmoddep]" >&2   echo "       [--initrdfile=<initrd-image>] [--depmod] [--rmmoddep]" >&2
164   echo "       [--kernel-args=<args>] [--remove-args=<args>]" >&2   echo "       [--kernel-args=<args>] [--remove-args=<args>]" >&2
165   echo "       [--banner=<banner>] [--multiboot=multiboot]" >&2   echo "       [--banner=<banner>] [--multiboot=multiboot]" >&2
166   echo "       [--mbargs=mbargs] [--make-default]" >&2   echo "       [--mbargs=mbargs] [--make-default] [--add-dracut-args]" >&2
167     echo "       [--add-plymouth-initrd]" >&2
168     echo "       [--host-only] [--devtree=<devicetree.dtb>] [--devtreedir=</devicetree/path/>]" >&2
169   echo "       <--install | --remove | --update> <kernel-version>" >&2   echo "       <--install | --remove | --update> <kernel-version>" >&2
170   echo "       (ex: $(basename $0) --mkinitrd --depmod --install 2.4.7-2)" >&2   echo "       (ex: $(basename $0) --mkinitrd --depmod --install 2.4.7-2)" >&2
171   exit 1   exit 1
172  }  }
173    
174    rungrubby()
175    {
176     if [[ $1 == --debug ]]
177     then
178     [[ ${MAKEDEBUG} != yes ]] && return 0
179     [[ -n ${verbose} ]] && echo "- First, making a debug entry."
180     declare -x debugtitle=" with debugging"
181     declare -x debugargs="${DEBUGARG}"
182     shift
183     else
184     [[ -n ${verbose} ] && echo "- Making a normal entry."
185     fi
186     $(eval $grubby $@)
187     export -n debugargs
188     export -n debugtitle
189     unset debugargs
190     unset debugtitle
191    }
192    
193    set_title()
194    {
195     if [[ -n ${banner} ]]
196     then
197     if [[ ${ARCH} = s390 ]] || [[ ${ARCH} = s390x ]]
198     then
199     title=$(echo ${banner} | sed 's/ /_/g')
200     else
201     title="${banner} [ ${version} ]"
202     fi
203     elif [[ ${ARCH} = s390 ]] || [[ ${ARCH} = s390x ]]
204     then
205     title=$(echo ${version} | sed 's/ /_/g')
206     elif [ -f /etc/os-release ]
207     then
208     title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]"
209     elif [ -f /etc/mageversion ]
210     then
211     title="Magellan Linux $(< /etc/mageversion) [ ${version} ]"
212     else
213     title="Magellan Linux [ ${version} ]"
214     fi
215    }
216    
217  install()  install()
218  {  {
219   # XXX kernel should be able to be specified also (or work right on ia64)   # XXX kernel should be able to be specified also (or work right on ia64)
220   if [ ! -f ${bootPrefix}/${kernelName}-${version} ]   if [ ! -f ${kernelImage} ]
221   then   then
222   [[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby"
223   return   return
# Line 123  install() Line 228  install()
228   then   then
229   [[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby"   [[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby"
230   INITRD="--initrd ${initrdfile}"   INITRD="--initrd ${initrdfile}"
231    
232     if [[ -n ${addplymouthinitrd} ]]
233     then
234     INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img"
235     fi
236     fi
237    
238     DEVTREE=""
239     if [[ -n ${devtreefile} ]] && [ -f ${devtreefile} ]
240     then
241     [[ -n ${verbose} ]] && echo "found ${devtreefile} and using it with grubby"
242     DEVTREE="--devtree ${devtreefile}"
243     fi
244    
245     DEVTREEDIR=""
246     if [[ -n ${devtreedir} ]] && [ -d ${devtreedir} ]
247     then
248     [ -n ${verbose} ] && echo "found ${devtreedir} and using it with grubby"
249     DEVTREEDIR="--devtreedir ${devtreedir}"
250   fi   fi
251    
252   # FIXME: is this a good heuristic to find out if we're on iSeries?   # FIXME: is this a good heuristic to find out if we're on iSeries?
# Line 132  install() Line 256  install()
256   if [[ -z ${initrdfile} ]]   if [[ -z ${initrdfile} ]]
257   then   then
258   [[ -n ${verbose} ]] && echo "No initrd, just adding system map"   [[ -n ${verbose} ]] && echo "No initrd, just adding system map"
259   /sbin/addSystemMap ${bootPrefix}/System.map-${version} ${bootPrefix}/${kernelName}-${version} ${bootPrefix}/vmlinitrd-${version}   /sbin/addSystemMap ${bootPrefix}/System.map-${version} ${kernelImage} ${bootPrefix}/vmlinitrd-${version}
260   else   else
261   /sbin/addSystemMap ${bootPrefix}/System.map-${version} ${bootPrefix}/${kernelName}-${version} ${bootPrefix}/vmlinux.sm-${version}   /sbin/addSystemMap ${bootPrefix}/System.map-${version} ${kernelImage} ${bootPrefix}/vmlinux.sm-${version}
262   /sbin/addRamDisk ${initrdfile} ${bootPrefix}/System.map-${version} ${bootPrefix}/vmlinux.sm-${version} ${bootPrefix}/vmlinitrd-${version} 2>/dev/null   /sbin/addRamDisk ${initrdfile} ${bootPrefix}/System.map-${version} ${bootPrefix}/vmlinux.sm-${version} ${bootPrefix}/vmlinitrd-${version} 2>/dev/null
263   rm ${bootPrefix}/vmlinux.sm-${version}   rm ${bootPrefix}/vmlinux.sm-${version}
264   fi   fi
# Line 142  install() Line 266  install()
266   fi   fi
267    
268   # get the root filesystem to use   # get the root filesystem to use
269   rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab)   rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab  2>/dev/null)
270     if [[ -z $rootdevice ]]
271     then
272     rootdevice=$(grep -o -P "(?<=root=)\S+" /proc/cmdline)
273     fi
274    
275   if [[ -n ${mbkernel} ]] && [[ -n ${cfgLilo} ]] && [[ ${liloFlag} != elilo ]]   if [[ -n ${mbkernel} ]] && [[ -n ${cfgLilo} ]] && [[ ${liloFlag} != elilo ]]
276   then   then
# Line 150  install() Line 278  install()
278   cfgLilo=""   cfgLilo=""
279   fi   fi
280    
281     set_title
282    
283   if [[ -n ${cfgGrub} ]]   if [[ -n ${cfgGrub} ]]
284   then   then
285   [[ -n ${verbose} ]] && echo "adding ${version} to ${grubConfig}"   [[ -n ${verbose} ]] && echo "adding ${version} to ${grubConfig}"
286    
287   if [[ -n ${banner} ]]   ARGS="--grub -c ${grubConfig} --add-kernel=${kernelImage} ${INITRD} \
288   then   ${mbkernel:+--add-multiboot=\"${mbkernel}\"} \
289   title="${banner} (${version})"   ${mbargs:+--mbargs=\"${mbargs}\"} \
290   elif [ -f /etc/mageversion ]   --title=\"${title}\${debugtitle}\" --copy-default \
291   then   --args=\"root=${rootdevice} ${kernargs} \${debugargs}\" \
292   title="Magellan Linux $(< /etc/mageversion) (${version})"   --remove-kernel=\"TITLE=${title}\${debugtitle}\""
293   else   rungrubby --debug ${ARGS}
294   title="Magellan Linux (${version})"   rungrubby ${ARGS} ${makedefault}
  fi  
  ${grubby} --add-kernel=${bootPrefix}/${kernelName}-${version} \  
  ${INITRD} --copy-default ${makedefault} --title "${title}" \  
  ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \  
  --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"  
295   else   else
296   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97"
297     fi
298     if [[ -n ${cfgGrub2} ]]
299     then
300     [[ -n ${verbose} ]] && echo "adding ${version} to ${grub2Config}"
301    
302     ARGS="--grub2 -c ${grub2Config} --add-kernel=${kernelImage} ${INITRD} \
303     --copy-default --title \"${title}\${debugtitle}\" \
304     ${mbkernel:+--add-multiboot=\"${mbkernel}\"} \
305     ${mbargs:+--mbargs=\"${mbargs}\"} \
306     --args=\"root=${rootdevice} ${kernargs} \${debugargs}\" \
307     --remove-kernel=\"TITLE=${title}\${debugtitle}\""
308     rungrubby --debug ${ARGS}
309     rungrubby ${ARGS} ${makedefault}
310     else
311     [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby for grub 2"
312     fi
313     if [[ -n ${cfgGrub2Efi} ]]
314     then
315     [[ -n ${verbose} ]] && echo "adding ${version} to ${grub2EfiConfig}"
316    
317     ARGS="--grub2 -c ${grub2EfiConfig} --efi \
318     --add-kernel=${kernelImage} ${DEVTREE} ${INITRD} \
319     --copy-default --title \"${title}\${debugtitle}\" \
320     ${mbkernel:+--add-multiboot=\"${mbkernel}\"} \
321     ${mbargs:+--mbargs=\"${mbargs}\"} \
322     --args=\"root=${rootdevice} ${kernargs} \${debugargs}\" \
323     --remove-kernel=\"TITLE=${title}\${debugtitle}\""
324     rungrubby --debug ${ARGS}
325     rungrubby ${ARGS} ${makedefault}
326     else
327     [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby for grub 2 with UEFI"
328   fi   fi
329    
330   if [[ -n ${cfgLilo} ]]   if [[ -n ${cfgLilo} ]]
331   then   then
332   [[ -n ${verbose} ]] && echo "adding ${version} to ${liloConfig}"   [[ -n ${verbose} ]] && echo "adding ${version} to ${liloConfig}"
333    
334   ${grubby} --add-kernel=${bootPrefix}/${kernelName}-${version} ${INITRD} \   ARGS="--${liloFlag} --add-kernel=${kernelImage} ${INITRD} \
335   --copy-default ${makedefault} --title ${version} \   --copy-default --title \"${title}\${debugtitle}\" \
336   ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \   ${mbkernel:+--add-multiboot=\"${mbkernel}\"} \
337   --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${version}" \   ${mbargs:+--mbargs=\"${mbargs}\"} \
338   --${liloFlag}   --args=\"root=${rootdevice} ${kernargs} \${debugargs}\" \
339     --remove-kernel=\"TITLE=${version}\""
340     rungrubby --debug ${ARGS}
341     rungrubby ${ARGS} ${makedefault}
342    
343   if [[ -n ${runLilo} ]]   if [[ -n ${runLilo} ]]
344   then   then
345   [[ -n ${verbose} ]] && echo "running ${lilo}"   [[ -n ${verbose} ]] && echo "running ${lilo}"
346   if [ ! -x $lilo ]   if [ ! -x ${lilo} ]
347   then   then
348   [[ -n ${verbose} ]] && echo "${lilo} does not exist"   [[ -n ${verbose} ]] && echo "${lilo} does not exist"
349   else   else
# Line 194  install() Line 353  install()
353   else   else
354   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
355   fi   fi
356    
357     if [[ -n ${cfgExtlinux} ]]
358     then
359     [[ -n ${verbose} ]] && echo "adding ${version} to ${extlinuxConfig}"
360    
361     ARGS="--extlinux -c ${extlinuxConfig} --add-kernel=${kernelImage} \
362     ${DEVTREEDIR} ${DEVTREE} \
363     ${INITRD} --copy-default --title \"${title}\${debugtitle}\" \
364     ${mbkernel:+--add-multiboot=\"${mbkernel}\"} \
365     ${mbargs:+--mbargs=\"${mbargs}\"} \
366     --args=\"root=${rootdevice} ${kernargs} \${debugargs}\" \
367     --remove-kernel=\"TITLE=${title}\${debugtitle}\""
368     rungrubby --debug ${ARGS}
369     rungrubby ${ARGS} ${makedefault}
370     else
371     [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux"
372     fi
373  }  }
374    
375  remove()  remove()
# Line 202  remove() Line 378  remove()
378   if [ -d /proc/iSeries ]   if [ -d /proc/iSeries ]
379   then   then
380   [[ -n ${verbose} ]] && echo "On an iSeries, remove img file"   [[ -n ${verbose} ]] && echo "On an iSeries, remove img file"
381   rm -f ${bootPrefix}/${kernelName}-${version}.img 2>/dev/null   rm -f ${kernelImage}.img 2>/dev/null
382   return   return
383   fi   fi
384    
385   if [[ -n ${cfgGrub} ]]   if [[ -n ${cfgGrub} ]]
386   then   then
387   [[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}"   [[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}"
388   ${grubby} --remove-kernel=${bootPrefix}/${kernelName}-${version}   ${grubby} --grub -c ${grubConfig} \
389     --remove-kernel=${kernelImage}
390   else   else
391   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97"
392     fi
393     if [[ -n ${cfgGrub2} ]]
394     then
395     [[ -n ${verbose} ]] && echo "removing ${version} from ${grub2Config}"
396     ${grubby} --grub2 -c ${grub2Config} \
397     --remove-kernel=${kernelImage}
398     else
399     [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby for grub 2"
400     fi
401     if [[ -n ${cfgGrub2Efi} ]]
402     then
403     [[ -n ${verbose} ]] && echo "removing ${version} from ${grub2EfiConfig}"
404     ${grubby} --grub2 -c ${grub2EfiConfig} --efi \
405     --remove-kernel=${kernelImage}
406     else
407     [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby grub 2 with UEFI"
408   fi   fi
409    
410   if [[ -n ${cfgLilo} ]]   if [[ -n ${cfgLilo} ]]
411   then   then
412   [[ -n ${verbose} ]] && echo "removing ${version} from ${liloConfig}"   [[ -n ${verbose} ]] && echo "removing ${version} from ${liloConfig}"
413   ${grubby} --remove-kernel=${bootPrefix}/${kernelName}-${version}    \   ${grubby} --remove-kernel=${kernelImage} --${liloFlag}
  --${liloFlag}  
414    
415   if [[ -n ${runLilo} ]]   if [[ -n ${runLilo} ]]
416   then   then
# Line 233  remove() Line 425  remove()
425   else   else
426   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
427   fi   fi
428    
429     if [[ -n ${cfguBoot} ]]
430     then
431     [[ -n ${verbose} ]] && echo "removing ${version} from ${ubootDir}..."
432    
433     if [ -f ${ubootDir}/${ubootKList} ]
434     then
435     tmpKList=$(mktemp ${ubootDir}/${ubootKList}.XXXX)
436     curversion=$(tail -n1 ${ubootDir}/${ubootKList})
437     sed "/$version$/d" ${ubootDir}/${ubootKList} > ${tmpKList}
438     newversion=$(tail -n1 ${tmpKList})
439     if [ -f ${ubootDir}/uImage-${newversion} ] && [ -f ${ubootDir}/uInitrd-${newversion} ]
440     then
441     if [[ ${curversion} != ${newversion} ]]
442     then
443     cp -fp ${ubootDir}/uImage-${newversion} ${ubootDir}/${ubootDefaultImage}
444     if [ $? -ne 0 ]
445     then
446     [[ -n ${verbose} ]] && echo "copy uImage-${newversion} error, default kernel not replaced!" && exit
447     fi
448     cp -fp ${ubootDir}/uInitrd-${newversion} ${ubootDir}/${ubootDefaultInitrd}
449     if [ $? -ne 0 ]
450     then
451     [[ -n ${verbose} ]] && echo "copy uInitrd-${newversion} error, default Initrd not replaced!" && exit
452     fi
453     fi
454    
455     [[ -n ${verbose} ]] && echo "removing uImage-${version}"
456     if [ -f ${ubootDir}/uImage-${version} ]
457     then
458     rm -f ${ubootDir}/uImage-${version}
459     else
460     [[ -n ${verbose} ]] && echo "uImage-${version} did not exist!"
461     fi
462    
463     [[ -n ${verbose} ]] && echo "removing uInitrd-${version}"
464     if [ -f ${ubootDir}/uInitrd-${version} ]
465     then
466     rm -f ${ubootDir}/uInitrd-${version}
467     else
468     [[ -n ${verbose} ]] && echo "uInitrd-${version} did not exist!"
469     fi
470    
471     mv ${tmpKList} ${ubootDir}/${ubootKList}
472     [ -x /sbin/a-b-c ] && /sbin/a-b-c
473     else
474     [[ -n ${verbose} ]] && echo "uImage ${newversion} does not exist!"
475     [ -f ${tmpKList} ] && rm -f ${tmpKList}
476     fi
477     else
478     [[ -n ${verbose} ]] && echo "No previous kernel version.  U-Boot images not removed!"
479     fi
480     else
481     [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}"
482     fi
483    
484     if [[ -n ${cfgExtlinux} ]]
485     then
486     [[ -n ${verbose} ]] && echo "removing ${version} from ${extlinuxConfig}"
487     ${grubby} --extlinux -c ${extlinuxConfig} \
488     --remove-kernel=${kernelImage}
489     else
490     [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux"
491     fi
492  }  }
493    
494  update()  update()
495  {  {
496     if [ ! -f ${kernelImage} ]
497     then
498     [[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby"
499     return
500     fi
501    
502     set_title
503    
504     INITRD=""
505     if [ -f ${initrdfile} ]
506     then
507     [[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby"
508     INITRD="--initrd ${initrdfile}"
509    
510     if [[ -n ${addplymouthinitrd} ]]
511     then
512     INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img"
513     fi
514     fi
515    
516     DEVTREE=""
517     if [[ -n ${devtreefile} ]] && [ -f ${devtreefile} ]
518     then
519     [[ -n ${verbose} ]] && echo "found ${devtreefile} and using it with grubby"
520     DEVTREE="--devtree ${devtreefile}"
521     fi
522    
523     DEVTREEDIR=""
524     if [[ -n ${devtreedir} ]] && [ -d ${devtreedir} ]
525     then
526     [[ -n ${verbose} ]] && echo "found ${devtreedir} and using it with grubby"
527     DEVTREEDIR="--devtreedir ${devtreedir}"
528     fi
529    
530   if [[ -n ${cfgGrub} ]]   if [[ -n ${cfgGrub} ]]
531   then   then
532   [[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}"   [[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}"
533   ${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \   ARGS="--grub -c ${grubConfig} --update-kernel=${kernelImage} ${INITRD} \
534   ${kernargs:+--args="${kernargs}"} \   ${kernargs:+--args=\"${kernargs}\"} \
535   ${removeargs:+--remove-args="${removeargs}"}   ${removeargs:+--remove-args=\"${removeargs}\"} \
536     ${mbkernel:+--add-multiboot=\"${mbkernel}\"} \
537     --title=\"${title}\${debugtitle}\""
538     rungrubby --debug ${ARGS}
539     rungrubby ${ARGS}
540   else   else
541   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"
542   fi   fi
543    
544     if [[ -n ${cfgGrub2} ]]
545     then
546     [[ -n ${verbose} ]] && echo "updating ${version} from ${grub2Config}"
547     ARGS="--grub2 -c ${grub2Config} --update-kernel=${kernelImage} ${INITRD} \
548     ${kernargs:+--args=\"${kernargs}\"} \
549     ${removeargs:+--remove-args=\"${removeargs}\"} \
550     --title=\"${title}\${debugtitle}\""
551     rungrubby --debug ${ARGS}
552     rungrubby ${ARGS}
553     else
554     [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby"
555     fi
556    
557     if [[ -n ${cfgGrub2Efi} ]]
558     then
559     [[ -n ${verbose} ]] && echo "updating ${version} from ${grub2EfiConfig}"
560     ARGS="--grub2 -c ${grub2EfiConfig} --efi --update-kernel=${kernelImage} \
561     ${INITRD} ${kernargs:+--args=\"${kernargs}\"} \
562     ${removeargs:+--remove-args=\"${removeargs}\"} \
563     --title=\"${title}\${debugtitle}\""
564     rungrubby --debug ${ARGS}
565     rungrubby ${ARGS}
566     else
567     [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby"
568     fi
569    
570   if [[ -n ${cfgLilo} ]]   if [[ -n ${cfgLilo} ]]
571   then   then
572   [[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}"   [[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}"
573   ${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \   ARGS="--${liloFlag} --update-kernel=${kernelImage} ${INITRD} \
574   ${kernargs:+--args="${kernargs}"} \   ${kernargs:+--args=\"${kernargs}\"} \
575   ${removeargs:+--remove-args="${removeargs}"} \   ${removeargs:+--remove-args=\"${removeargs}\"} \
576   --${liloFlag}   --title=\"${title}\${debugtitle}\""
577     rungrubby --debug ${ARGS}
578     rungrubby ${ARGS}
579    
580   if [[ -n ${runLilo} ]]   if [[ -n ${runLilo} ]]
581   then   then
# Line 268  update() Line 590  update()
590   else   else
591   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
592   fi   fi
593    
594     if [[ -n ${cfguBoot} ]]
595     then
596     [[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..."
597    
598     [[ -n ${verbose} ]] && echo "creating uImage-${version}"
599     mkimage -A arm -O linux -T kernel -C none -a ${ubootAddress} \
600     -e ${ubootAddress} -n ${version} \
601     -d ${kernelImage} ${ubootDir}/uImage-${version}
602    
603     [[ -n ${verbose} ]] && echo "creating uInitrd-${version}"
604     mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 \
605     -n initramfs -d ${initrdfile} ${ubootDir}/uInitrd-${version}
606    
607     if [ -f ${ubootDir}/uImage-${version} ] && [ -f ${ubootDir}/uInitrd-${version} ]
608     then
609     cp -fp ${ubootDir}/uImage-${version} ${ubootDir}/${ubootDefaultImage}
610     if [ $? -ne 0 ]
611     then
612     [[ -n ${verbose} ]] && echo "copy uImage-${version} error, kernel not installed!" && exit
613     fi
614     cp -fp ${ubootDir}/uInitrd-${version} ${ubootDir}/${ubootDefaultInitrd}
615     if [ $? -ne 0 ]
616     then
617     [[ -n ${verbose} ]] && echo "copy uInitrd-${version} error, kernel not installed!" && exit
618     fi
619     echo ${version} >> ${ubootDir}/${ubootKList}
620     [ -x /sbin/a-b-c ] && /sbin/a-b-c
621     else
622     [[ -n ${verbose} ]] && echo "cannot make ${version} the default"
623     fi
624     else
625     [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not setting up ${ubootDir}"
626     fi
627    
628     if [[ -n ${cfgExtlinux} ]]
629     then
630     [[ -n ${verbose} ]] && echo "updating ${version} from ${extlinuxConfig}"
631     ARGS="--extlinux -c ${extlinuxConfig} --update-kernel=${kernelImage} \
632     ${DEVTREE} ${DEVTREEDIR} ${INITRD} ${kernargs:+--args=\"${kernargs}\"} \
633     ${removeargs:+--remove-args=\"${removeargs}\"} \
634     --title=\"${title}\${debugtitle}\""
635     rungrubby --debug ${ARGS}
636     rungrubby ${ARGS}
637     else
638     [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby"
639     fi
640  }  }
641    
642  mkinitrd()  makeinitrd()
643  {  {
644     if [[ -n ${dracut} ]]
645     then
646     tool="dracut ${dracuthostonly} -f ${initrdfile} ${version}"
647     else
648     tool="mkinitrd --allow-missing -f ${initrdfile} ${version}"
649     fi
650   [[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}"   [[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}"
651   /sbin/mkinitrd --allow-missing -f ${initrdfile} ${version}   ${tool}
652   rc=$?   rc=$?
653   if [ ${rc} != 0 ]   if [ ${rc} != 0 ]
654   then   then
# Line 297  doDepmod() Line 672  doDepmod()
672  doRmmoddep()  doRmmoddep()
673  {  {
674   [[ -n ${verbose} ]] && echo "removing modules.dep info for ${version}"   [[ -n ${verbose} ]] && echo "removing modules.dep info for ${version}"
675   [ -d /lib/modules/${version} ] && rm -f /lib/modules/${version}/modules.*   if [ -d /lib/modules/${version} ]
676     then
677     rm -f /lib/modules/${version}/modules.*.bin \
678     /lib/modules/${version}/modules.{alias,dep,devname,symbols,softdep}
679     fi
680  }  }
681    
682    # kernel image for 2.4 is kernel
683    if [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]]
684    then
685     if [[ ${kernelmajor} = 2.4 ]]
686     then
687     kernelName=kernel
688     fi
689    fi
690    
691  while [ $# -gt 0 ]  while [ $# -gt 0 ]
692  do  do
# Line 312  do Line 699  do
699   initrd="remove"   initrd="remove"
700   ;;   ;;
701    
702     --devtree*)
703     if [[ $1 == --devtree\=* ]]
704     then
705     devtreefile="${1#--devtreefile=}"
706     else
707     devtreefile="$2"
708     shift
709     fi
710     ;;
711    
712     --devtreedir*)
713     if [[ $1 == --devtreedir\=* ]]
714     then
715     devtreedir=${1#--devtreedir=}
716     else
717     devtreedir=$2
718     shift
719     fi
720     ;;
721    
722     --dracut)
723     dracut=--dracut
724     ;;
725    
726     --host-only)
727     dracuthostonly=-H
728     ;;
729    
730   --initrdfile*)   --initrdfile*)
731   if echo $1 | grep '=' >/dev/null   if [[ $1 == --initrdfile\=* ]]
732   then   then
733   initrdfile=$(echo $1 | sed 's/^--initrdfile=//')   initrdfile=${1#--initrdfile=}
734   else   else
735   initrdfile=$2   initrdfile=$2
736   shift   shift
# Line 323  do Line 738  do
738   ;;   ;;
739    
740   --kernel-args*)   --kernel-args*)
741   if echo $1 | grep '=' >/dev/null   if [[ $1 == --kernel-args\=* ]]
742   then   then
743   kernargs=$(echo $1 | sed 's/^--kernel-args=//')   kernargs=${1#--kernel-args=}
744   else   else
745   kernargs=$2   kernargs=$2
746   shift   shift
# Line 333  do Line 748  do
748   ;;   ;;
749    
750   --remove-args*)   --remove-args*)
751   if echo $1 | grep '=' >/dev/null   if [[ $1 == --remove-args\=* ]]
752   then   then
753   removeargs=$(echo $1 | sed 's/^--remove-args=//')   removeargs=${1#--remove-args=}
754   else   else
755   removeargs=$2   removeargs=$2
756   shift   shift
# Line 343  do Line 758  do
758   ;;   ;;
759    
760   --banner*)   --banner*)
761   if echo $1 | grep '=' >/dev/null   if [[ $1 == --banner\=* ]]
762   then   then
763   banner=$(echo $1 | sed 's/^--banner=//')   banner=${1#--banner=}
764   else   else
765   banner=$2   banner=$2
766   shift   shift
# Line 353  do Line 768  do
768   ;;   ;;
769    
770   --multiboot*)   --multiboot*)
771   if echo $1 |grep '=' >/dev/null   if [[ $1 == --multiboot\=* ]]
772   then   then
773   mbkernel=$(echo $1 | sed 's/^--multiboot=//')   mbkernel=${1#--multiboot=}
774   else   else
775   # can't really support having an optional second arg here   # can't really support having an optional second arg here
776   # sorry!   # sorry!
# Line 364  do Line 779  do
779   ;;   ;;
780    
781   --mbargs*)   --mbargs*)
782   if echo $1 |grep '=' >/dev/null   if [[ $1 == --mbargs\=* ]]
783   then   then
784   mbargs=$(echo $1 | sed 's/^--mbargs=//')   mbargs=${1#--mbargs=}
785   else   else
786   mbargs="$2"   mbargs="$2"
787   shift   shift
# Line 385  do Line 800  do
800   makedefault="--make-default"   makedefault="--make-default"
801   ;;   ;;
802    
803   --package)   --package*)
804   if echo $1 | grep '=' >/dev/null   if [[ $1 == --package\=* ]]
805   then   then
806   package=$(echo $1 | sed 's/^--package=//')   package=${1#--package=}
807   else   else
808   package=$2   package=$2
809   shift   shift
810   fi   fi
811   ;;   ;;
812    
813     --add-dracut-args)
814     adddracutargs=--add-dracut-args
815     ;;
816    
817     --add-plymouth-initrd)
818     addplymouthinitrd=--add-plymouth-initrd
819     ;;
820    
821     --kernel-image*)
822     if [[ $1 == --kernel-image\=* ]]
823     then
824     kernelImage=${1#--kernel-image=}
825     else
826     kernelImage="$2"
827     shift
828     fi
829     if ! [[ -f ${kernelImage} ]]
830     then
831     echo "Can't find kernel image '${kernelImage}'" >&2
832     usage
833     exit 1
834     fi
835     ;;
836    
837     --kernel-name*)
838     if [[ $1 == --kernel-name\=* ]]
839     then
840     kernelName=${1#--kernel-name=}
841     else
842     kernelName="$2"
843     shift
844     fi
845     ;;
846    
847   -v)   -v)
848   verbose=-v   verbose=-v
849   ;;   ;;
# Line 433  fi Line 882  fi
882    
883  kernelmajor=$(echo ${kernel} | cut -d . -f 1,2)  kernelmajor=$(echo ${kernel} | cut -d . -f 1,2)
884    
885  # kernel image for 2.4 is vmlinux  [[ ${kernelImage} ]] || kernelImage="${bootPrefix}/${kernelName}-${version}"
 if [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]]  
 then  
  if [[ ${kernelmajor} = 2.4 ]]  
  then  
  kernelName=kernel  
  fi  
 fi  
886    
887  # 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
888  if [[ -z ${initrdfile} ]]  if [[ -z ${initrdfile} ]]
889  then  then
890   INITRD_NAME_PREFIX="initrd"   INITRD_NAME_PREFIX="initrd"
891     if [[ -n ${dracut} ]]
892     then
893     INITRD_NAME_PREFIX="initramfs"
894     fi
895    
896   if [[ $(uname -m) = ia64 ]]   if [[ $(uname -m) = ia64 ]]
897   then   then
# Line 456  then Line 902  then
902  fi  fi
903  [[ -n ${verbose} ]] && echo "initrdfile is ${initrdfile}"  [[ -n ${verbose} ]] && echo "initrdfile is ${initrdfile}"
904    
905    if [[ ${ARCH} =~ armv[5|7].*l ]]
906    then
907     if [ -d ${bootPrefix}/dtb-${version}/ ]
908     then
909     devtreedir="${bootPrefix}/dtb-${version}/"
910     if [[ -n ${dtbfile} ]] && [ -f ${devtreedir}/${dtbfile} ]
911     then
912     devtreefile="${devtreedir}/${dtbfile}"
913     fi
914     fi
915    fi
916    [[ -n ${verbose} ]] && echo "devtreedir is ${devtreedir}"
917    
918    # add dracut i18n, keyboard and plymouth kernel args if requested
919    if [[ -n ${dracut} ]] || [[ -n ${adddracutargs} ]]
920    then
921     if [ -r /etc/vconsole.conf ]
922     then
923     . /etc/vconsole.conf
924    
925     for i in SYSFONT SYSFONTACM UNIMAP KEYTABLE
926     do
927     val=$(eval echo \$$i)
928     [[ -n ${val} ]] && kernargs="${kernargs} ${i}=${val}"
929     done
930     else
931     if [ -r /etc/conf.d/consolefont ]
932     then
933     . /etc/conf.d/consolefont
934    
935     if [[ -n ${CONSOLEFONT} ]]
936     then
937     kernargs="${kernargs} SYSFONT=${CONSOLEFONT}"
938     fi
939     fi
940    
941     if  [ -r /etc/conf.d/keymap ]
942     then
943     . /etc/conf.d/keymap
944    
945     if [[ -n ${KEYMAP} ]]
946     then
947     kernargs="${kernargs} KEYTABLE=${KEYMAP}"
948     fi
949     fi
950     fi
951    
952     if [ -r /etc/locale.conf ]
953     then
954     . /etc/locale.conf
955    
956     if [[ -n ${LANG} ]]
957     then
958     kernargs="${kernargs} LANG=${LANG}"
959     fi
960     fi
961    fi
962    
963  # set this as the default if we have the package and it matches  # set this as the default if we have the package and it matches
964  if [[ ${mode} = --install ]] && [[ ${UPDATEDEFAULT} = yes ]] && [[ -n ${package} ]] &&  if [[ ${mode} = --install ]] && [[ ${UPDATEDEFAULT} = yes ]] && [[ -n ${package} ]] && [[ -n ${DEFAULTKERNEL} ]]
  [[ -n ${DEFAULTKERNEL} ]] && [[ ${package} = ${DEFAULTKERNEL} ]]  
965  then  then
966   makedefault="--make-default"   if [[ ${package} = ${DEFAULTKERNEL} ]] || [[ ${package}-core = ${DEFAULTKERNEL} ]]
967   [[ -n ${verbose} ]] && echo "making it the default based on config"   then
968     makedefault="--make-default"
969     [[ -n ${verbose} ]] && echo "making it the default based on config"
970     fi
971  fi  fi
972    
973  if [[ ${moddep} = make ]]  if [[ ${moddep} = make ]]
# Line 474  fi Line 980  fi
980    
981  if [[ ${initrd} = make ]]  if [[ ${initrd} = make ]]
982  then  then
983   mkinitrd   makeinitrd
984  elif [[ ${initrd} = remove ]]  elif [[ ${initrd} = remove ]]
985  then  then
986   rminitrd   rminitrd
# Line 487  then Line 993  then
993  fi  fi
994    
995  [[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1  [[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1
996    [[ -n ${grub2Config} ]] && [ -f ${grub2Config} ] && cfgGrub2=1
997    [[ -n ${grub2EfiConfig} ]] && [ -f ${grub2EfiConfig} ] && cfgGrub2Efi=1
998  [[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1  [[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1
999    [[ -n ${extlinuxConfig} ]] && [ -f ${extlinuxConfig} ] && cfgExtlinux=1
1000    
1001    # if we have a U-Boot directory, but no boot script, check if the directory
1002    # is mounted.  If not, mount it, and then check if a boot script exists.
1003    if [[ -n ${ubootDir} ]]
1004    then
1005     if [ -f ${ubootScript} ]
1006     then
1007     cfguBoot=1
1008     else
1009     mountEntry=$(mount | grep ${ubootDir})
1010     if [[ -z ${mountEntry} ]]
1011     then
1012     mount ${ubootDevice} ${ubootDir}
1013     mounted=1
1014     fi
1015     [ -f ${ubootScript} ] && cfguBoot=1
1016     fi
1017    fi
1018    
1019    # if we're using U-Boot, check if the default load address should change
1020    if [[ -n ${cfguBoot} ]] && [[ -z ${UBOOT_IMGADDR} ]]
1021    then
1022     [[ ${version}  =~ .([^.]*)$ ]]
1023     platform=${BASH_REMATCH[1]}
1024     # A few platforms use an alternate kernel load address
1025     if [[ ${platform} = omap ]]
1026     then
1027     ubootAddress=0x80008000
1028     elif [[ ${platform} = imx ]]
1029     then
1030     ubootAddress=0x90008000
1031     fi
1032    fi
1033    
1034  # 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
1035  # is lilo to determine if it should be run  # is lilo to determine if it should be run
# Line 507  then Line 1049  then
1049   update   update
1050  fi  fi
1051    
1052    # if we mounted the U-Boot directory, unmount it.
1053    [[ -n ${mounted} ]] && umount ${ubootDir}
1054    
1055  exit 0  exit 0

Legend:
Removed from v.924  
changed lines
  Added in v.2972