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 925 by niro, Wed Oct 28 13:29:18 2009 UTC trunk/grubby/new-kernel-pkg revision 3006 by niro, Tue Jun 27 14:26:38 2017 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 40  else Line 66  else
66  fi  fi
67    
68  [ -f /etc/conf.d/grubby ] && . /etc/conf.d/grubby  [ -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.log_level=debug systemd.log_target=kmsg"
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     if [[ ${ARCH} = s390 ]] || [[ ${ARCH} = s390x ]]
181     then
182     declare -x debugtitle="_with_debugging"
183     else
184     declare -x debugtitle=" with debugging"
185     fi
186     declare -x debugargs="${DEBUGARG}"
187     shift
188     else
189     [[ -n ${verbose} ] && echo "- Making a normal entry."
190     fi
191     $(eval $grubby $@)
192     export -n debugargs
193     export -n debugtitle
194     unset debugargs
195     unset debugtitle
196    }
197    
198    set_title()
199    {
200     if [[ -n ${banner} ]]
201     then
202     if [[ ${ARCH} = s390 ]] || [[ ${ARCH} = s390x ]]
203     then
204     title=$(echo ${banner} | sed 's/ /_/g')
205     else
206     title="${banner} [ ${version} ]"
207     fi
208     elif [[ ${ARCH} = s390 ]] || [[ ${ARCH} = s390x ]]
209     then
210     title=$(echo ${version} | sed 's/ /_/g')
211     elif [ -f /etc/os-release ]
212     then
213     title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]"
214     elif [ -f /etc/mageversion ]
215     then
216     title="Magellan Linux $(< /etc/mageversion) [ ${version} ]"
217     else
218     title="Magellan Linux [ ${version} ]"
219     fi
220    }
221    
222  install()  install()
223  {  {
224   # 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)
225   if [ ! -f ${bootPrefix}/${kernelName}-${version} ]   if [ ! -f ${kernelImage} ]
226   then   then
227   [[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby"
228   return   return
# Line 123  install() Line 233  install()
233   then   then
234   [[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby"   [[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby"
235   INITRD="--initrd ${initrdfile}"   INITRD="--initrd ${initrdfile}"
236    
237     if [[ -n ${addplymouthinitrd} ]]
238     then
239     INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img"
240     fi
241     fi
242    
243     DEVTREE=""
244     if [[ -n ${devtreefile} ]] && [ -f ${devtreefile} ]
245     then
246     [[ -n ${verbose} ]] && echo "found ${devtreefile} and using it with grubby"
247     DEVTREE="--devtree ${devtreefile}"
248     fi
249    
250     DEVTREEDIR=""
251     if [[ -n ${devtreedir} ]] && [ -d ${devtreedir} ]
252     then
253     [ -n ${verbose} ] && echo "found ${devtreedir} and using it with grubby"
254     DEVTREEDIR="--devtreedir ${devtreedir}"
255   fi   fi
256    
257   # 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 261  install()
261   if [[ -z ${initrdfile} ]]   if [[ -z ${initrdfile} ]]
262   then   then
263   [[ -n ${verbose} ]] && echo "No initrd, just adding system map"   [[ -n ${verbose} ]] && echo "No initrd, just adding system map"
264   /sbin/addSystemMap ${bootPrefix}/System.map-${version} ${bootPrefix}/${kernelName}-${version} ${bootPrefix}/vmlinitrd-${version}   /sbin/addSystemMap ${bootPrefix}/System.map-${version} ${kernelImage} ${bootPrefix}/vmlinitrd-${version}
265   else   else
266   /sbin/addSystemMap ${bootPrefix}/System.map-${version} ${bootPrefix}/${kernelName}-${version} ${bootPrefix}/vmlinux.sm-${version}   /sbin/addSystemMap ${bootPrefix}/System.map-${version} ${kernelImage} ${bootPrefix}/vmlinux.sm-${version}
267   /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
268   rm ${bootPrefix}/vmlinux.sm-${version}   rm ${bootPrefix}/vmlinux.sm-${version}
269   fi   fi
# Line 142  install() Line 271  install()
271   fi   fi
272    
273   # get the root filesystem to use   # get the root filesystem to use
274   rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab)   rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab  2>/dev/null)
275     if [[ -z $rootdevice ]]
276     then
277     rootdevice=$(grep -o -P "(?<=root=)\S+" /proc/cmdline)
278     fi
279    
280   if [[ -n ${mbkernel} ]] && [[ -n ${cfgLilo} ]] && [[ ${liloFlag} != elilo ]]   if [[ -n ${mbkernel} ]] && [[ -n ${cfgLilo} ]] && [[ ${liloFlag} != elilo ]]
281   then   then
# Line 150  install() Line 283  install()
283   cfgLilo=""   cfgLilo=""
284   fi   fi
285    
286     set_title
287    
288   if [[ -n ${cfgGrub} ]]   if [[ -n ${cfgGrub} ]]
289   then   then
290   [[ -n ${verbose} ]] && echo "adding ${version} to ${grubConfig}"   [[ -n ${verbose} ]] && echo "adding ${version} to ${grubConfig}"
291    
292   if [[ -n ${banner} ]]   ARGS="--grub -c ${grubConfig} --add-kernel=${kernelImage} ${INITRD} \
293   then   ${mbkernel:+--add-multiboot=\"${mbkernel}\"} \
294   title="${banner} (${version})"   ${mbargs:+--mbargs=\"${mbargs}\"} \
295   elif [ -f /etc/mageversion ]   --title=\"${title}\${debugtitle}\" --copy-default \
296   then   --args=\"root=${rootdevice} ${kernargs} \${debugargs}\" \
297   title="Magellan Linux $(< /etc/mageversion) (${version})"   --remove-kernel=\"TITLE=${title}\${debugtitle}\""
298   else   rungrubby ${ARGS} ${makedefault}
299   title="Magellan Linux (${version})"   rungrubby --debug ${ARGS}
  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}"  
300   else   else
301   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97"
302     fi
303     if [[ -n ${cfgGrub2} ]]
304     then
305     [[ -n ${verbose} ]] && echo "adding ${version} to ${grub2Config}"
306    
307     ARGS="--grub2 -c ${grub2Config} --add-kernel=${kernelImage} ${INITRD} \
308     --copy-default --title \"${title}\${debugtitle}\" \
309     ${mbkernel:+--add-multiboot=\"${mbkernel}\"} \
310     ${mbargs:+--mbargs=\"${mbargs}\"} \
311     --args=\"root=${rootdevice} ${kernargs} \${debugargs}\" \
312     --remove-kernel=\"TITLE=${title}\${debugtitle}\""
313     rungrubby ${ARGS} ${makedefault}
314     rungrubby --debug ${ARGS}
315     else
316     [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby for grub 2"
317     fi
318     if [[ -n ${cfgGrub2Efi} ]]
319     then
320     [[ -n ${verbose} ]] && echo "adding ${version} to ${grub2EfiConfig}"
321    
322     ARGS="--grub2 -c ${grub2EfiConfig} --efi \
323     --add-kernel=${kernelImage} ${DEVTREE} ${INITRD} \
324     --copy-default --title \"${title}\${debugtitle}\" \
325     ${mbkernel:+--add-multiboot=\"${mbkernel}\"} \
326     ${mbargs:+--mbargs=\"${mbargs}\"} \
327     --args=\"root=${rootdevice} ${kernargs} \${debugargs}\" \
328     --remove-kernel=\"TITLE=${title}\${debugtitle}\""
329     rungrubby ${ARGS} ${makedefault}
330     rungrubby --debug ${ARGS}
331     else
332     [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby for grub 2 with UEFI"
333   fi   fi
334    
335   if [[ -n ${cfgLilo} ]]   if [[ -n ${cfgLilo} ]]
336   then   then
337   [[ -n ${verbose} ]] && echo "adding ${version} to ${liloConfig}"   [[ -n ${verbose} ]] && echo "adding ${version} to ${liloConfig}"
338    
339   ${grubby} --add-kernel=${bootPrefix}/${kernelName}-${version} ${INITRD} \   ARGS="--${liloFlag} --add-kernel=${kernelImage} ${INITRD} \
340   --copy-default ${makedefault} --title ${version} \   --copy-default --title \"${title}\${debugtitle}\" \
341   ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \   ${mbkernel:+--add-multiboot=\"${mbkernel}\"} \
342   --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${version}" \   ${mbargs:+--mbargs=\"${mbargs}\"} \
343   --${liloFlag}   --args=\"root=${rootdevice} ${kernargs} \${debugargs}\" \
344     --remove-kernel=\"TITLE=${version}\""
345     rungrubby ${ARGS} ${makedefault}
346     rungrubby --debug ${ARGS}
347    
348   if [[ -n ${runLilo} ]]   if [[ -n ${runLilo} ]]
349   then   then
350   [[ -n ${verbose} ]] && echo "running ${lilo}"   [[ -n ${verbose} ]] && echo "running ${lilo}"
351   if [ ! -x $lilo ]   if [ ! -x ${lilo} ]
352   then   then
353   [[ -n ${verbose} ]] && echo "${lilo} does not exist"   [[ -n ${verbose} ]] && echo "${lilo} does not exist"
354   else   else
# Line 194  install() Line 358  install()
358   else   else
359   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
360   fi   fi
361    
362     if [[ -n ${cfgExtlinux} ]]
363     then
364     [[ -n ${verbose} ]] && echo "adding ${version} to ${extlinuxConfig}"
365    
366     ARGS="--extlinux -c ${extlinuxConfig} --add-kernel=${kernelImage} \
367     ${DEVTREEDIR} ${DEVTREE} \
368     ${INITRD} --copy-default --title \"${title}\${debugtitle}\" \
369     ${mbkernel:+--add-multiboot=\"${mbkernel}\"} \
370     ${mbargs:+--mbargs=\"${mbargs}\"} \
371     --args=\"root=${rootdevice} ${kernargs} \${debugargs}\" \
372     --remove-kernel=\"TITLE=${title}\${debugtitle}\""
373     rungrubby ${ARGS} ${makedefault}
374     rungrubby --debug ${ARGS}
375     else
376     [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux"
377     fi
378  }  }
379    
380  remove()  remove()
# Line 202  remove() Line 383  remove()
383   if [ -d /proc/iSeries ]   if [ -d /proc/iSeries ]
384   then   then
385   [[ -n ${verbose} ]] && echo "On an iSeries, remove img file"   [[ -n ${verbose} ]] && echo "On an iSeries, remove img file"
386   rm -f ${bootPrefix}/${kernelName}-${version}.img 2>/dev/null   rm -f ${kernelImage}.img 2>/dev/null
387   return   return
388   fi   fi
389    
390   if [[ -n ${cfgGrub} ]]   if [[ -n ${cfgGrub} ]]
391   then   then
392   [[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}"   [[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}"
393   ${grubby} --remove-kernel=${bootPrefix}/${kernelName}-${version}   ${grubby} --grub -c ${grubConfig} \
394     --remove-kernel=${kernelImage}
395   else   else
396   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97"
397     fi
398     if [[ -n ${cfgGrub2} ]]
399     then
400     [[ -n ${verbose} ]] && echo "removing ${version} from ${grub2Config}"
401     ${grubby} --grub2 -c ${grub2Config} \
402     --remove-kernel=${kernelImage}
403     else
404     [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby for grub 2"
405     fi
406     if [[ -n ${cfgGrub2Efi} ]]
407     then
408     [[ -n ${verbose} ]] && echo "removing ${version} from ${grub2EfiConfig}"
409     ${grubby} --grub2 -c ${grub2EfiConfig} --efi \
410     --remove-kernel=${kernelImage}
411     else
412     [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby grub 2 with UEFI"
413   fi   fi
414    
415   if [[ -n ${cfgLilo} ]]   if [[ -n ${cfgLilo} ]]
416   then   then
417   [[ -n ${verbose} ]] && echo "removing ${version} from ${liloConfig}"   [[ -n ${verbose} ]] && echo "removing ${version} from ${liloConfig}"
418   ${grubby} --remove-kernel=${bootPrefix}/${kernelName}-${version}    \   ${grubby} --remove-kernel=${kernelImage} --${liloFlag}
  --${liloFlag}  
419    
420   if [[ -n ${runLilo} ]]   if [[ -n ${runLilo} ]]
421   then   then
# Line 233  remove() Line 430  remove()
430   else   else
431   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
432   fi   fi
433    
434     if [[ -n ${cfguBoot} ]]
435     then
436     [[ -n ${verbose} ]] && echo "removing ${version} from ${ubootDir}..."
437    
438     if [ -f ${ubootDir}/${ubootKList} ]
439     then
440     tmpKList=$(mktemp ${ubootDir}/${ubootKList}.XXXX)
441     curversion=$(tail -n1 ${ubootDir}/${ubootKList})
442     sed "/$version$/d" ${ubootDir}/${ubootKList} > ${tmpKList}
443     newversion=$(tail -n1 ${tmpKList})
444     if [ -f ${ubootDir}/uImage-${newversion} ] && [ -f ${ubootDir}/uInitrd-${newversion} ]
445     then
446     if [[ ${curversion} != ${newversion} ]]
447     then
448     cp -fp ${ubootDir}/uImage-${newversion} ${ubootDir}/${ubootDefaultImage}
449     if [ $? -ne 0 ]
450     then
451     [[ -n ${verbose} ]] && echo "copy uImage-${newversion} error, default kernel not replaced!" && exit
452     fi
453     cp -fp ${ubootDir}/uInitrd-${newversion} ${ubootDir}/${ubootDefaultInitrd}
454     if [ $? -ne 0 ]
455     then
456     [[ -n ${verbose} ]] && echo "copy uInitrd-${newversion} error, default Initrd not replaced!" && exit
457     fi
458     fi
459    
460     [[ -n ${verbose} ]] && echo "removing uImage-${version}"
461     if [ -f ${ubootDir}/uImage-${version} ]
462     then
463     rm -f ${ubootDir}/uImage-${version}
464     else
465     [[ -n ${verbose} ]] && echo "uImage-${version} did not exist!"
466     fi
467    
468     [[ -n ${verbose} ]] && echo "removing uInitrd-${version}"
469     if [ -f ${ubootDir}/uInitrd-${version} ]
470     then
471     rm -f ${ubootDir}/uInitrd-${version}
472     else
473     [[ -n ${verbose} ]] && echo "uInitrd-${version} did not exist!"
474     fi
475    
476     mv ${tmpKList} ${ubootDir}/${ubootKList}
477     [ -x /sbin/a-b-c ] && /sbin/a-b-c
478     else
479     [[ -n ${verbose} ]] && echo "uImage ${newversion} does not exist!"
480     [ -f ${tmpKList} ] && rm -f ${tmpKList}
481     fi
482     else
483     [[ -n ${verbose} ]] && echo "No previous kernel version.  U-Boot images not removed!"
484     fi
485     else
486     [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}"
487     fi
488    
489     if [[ -n ${cfgExtlinux} ]]
490     then
491     [[ -n ${verbose} ]] && echo "removing ${version} from ${extlinuxConfig}"
492     ${grubby} --extlinux -c ${extlinuxConfig} \
493     --remove-kernel=${kernelImage}
494     else
495     [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux"
496     fi
497  }  }
498    
499  update()  update()
500  {  {
501     if [ ! -f ${kernelImage} ]
502     then
503     [[ -n ${verbose} ]] && echo "kernel for ${version} does not exist, not running grubby"
504     return
505     fi
506    
507     set_title
508    
509     INITRD=""
510     if [ -f ${initrdfile} ]
511     then
512     [[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby"
513     INITRD="--initrd ${initrdfile}"
514    
515     if [[ -n ${addplymouthinitrd} ]]
516     then
517     INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img"
518     fi
519     fi
520    
521     DEVTREE=""
522     if [[ -n ${devtreefile} ]] && [ -f ${devtreefile} ]
523     then
524     [[ -n ${verbose} ]] && echo "found ${devtreefile} and using it with grubby"
525     DEVTREE="--devtree ${devtreefile}"
526     fi
527    
528     DEVTREEDIR=""
529     if [[ -n ${devtreedir} ]] && [ -d ${devtreedir} ]
530     then
531     [[ -n ${verbose} ]] && echo "found ${devtreedir} and using it with grubby"
532     DEVTREEDIR="--devtreedir ${devtreedir}"
533     fi
534    
535   if [[ -n ${cfgGrub} ]]   if [[ -n ${cfgGrub} ]]
536   then   then
537   [[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}"   [[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}"
538   ${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \   ARGS="--grub -c ${grubConfig} --update-kernel=${kernelImage} ${INITRD} \
539   ${kernargs:+--args="${kernargs}"} \   ${kernargs:+--args=\"${kernargs}\"} \
540   ${removeargs:+--remove-args="${removeargs}"}   ${removeargs:+--remove-args=\"${removeargs}\"} \
541     ${mbkernel:+--add-multiboot=\"${mbkernel}\"} \
542     --title=\"${title}\${debugtitle}\""
543     rungrubby ${ARGS}
544     rungrubby --debug ${ARGS}
545   else   else
546   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"
547   fi   fi
548    
549     if [[ -n ${cfgGrub2} ]]
550     then
551     [[ -n ${verbose} ]] && echo "updating ${version} from ${grub2Config}"
552     ARGS="--grub2 -c ${grub2Config} --update-kernel=${kernelImage} ${INITRD} \
553     ${kernargs:+--args=\"${kernargs}\"} \
554     ${removeargs:+--remove-args=\"${removeargs}\"} \
555     --title=\"${title}\${debugtitle}\""
556     rungrubby ${ARGS}
557     rungrubby --debug ${ARGS}
558     else
559     [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby"
560     fi
561    
562     if [[ -n ${cfgGrub2Efi} ]]
563     then
564     [[ -n ${verbose} ]] && echo "updating ${version} from ${grub2EfiConfig}"
565     ARGS="--grub2 -c ${grub2EfiConfig} --efi --update-kernel=${kernelImage} \
566     ${INITRD} ${kernargs:+--args=\"${kernargs}\"} \
567     ${removeargs:+--remove-args=\"${removeargs}\"} \
568     --title=\"${title}\${debugtitle}\""
569     rungrubby ${ARGS}
570     rungrubby --debug ${ARGS}
571     else
572     [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby"
573     fi
574    
575   if [[ -n ${cfgLilo} ]]   if [[ -n ${cfgLilo} ]]
576   then   then
577   [[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}"   [[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}"
578   ${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \   ARGS="--${liloFlag} --update-kernel=${kernelImage} ${INITRD} \
579   ${kernargs:+--args="${kernargs}"} \   ${kernargs:+--args=\"${kernargs}\"} \
580   ${removeargs:+--remove-args="${removeargs}"} \   ${removeargs:+--remove-args=\"${removeargs}\"} \
581   --${liloFlag}   --title=\"${title}\${debugtitle}\""
582     rungrubby ${ARGS}
583     rungrubby --debug ${ARGS}
584    
585   if [[ -n ${runLilo} ]]   if [[ -n ${runLilo} ]]
586   then   then
# Line 268  update() Line 595  update()
595   else   else
596   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
597   fi   fi
598    
599     if [[ -n ${cfguBoot} ]]
600     then
601     [[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..."
602    
603     [[ -n ${verbose} ]] && echo "creating uImage-${version}"
604     mkimage -A arm -O linux -T kernel -C none -a ${ubootAddress} \
605     -e ${ubootAddress} -n ${version} \
606     -d ${kernelImage} ${ubootDir}/uImage-${version}
607    
608     [[ -n ${verbose} ]] && echo "creating uInitrd-${version}"
609     mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 \
610     -n initramfs -d ${initrdfile} ${ubootDir}/uInitrd-${version}
611    
612     if [ -f ${ubootDir}/uImage-${version} ] && [ -f ${ubootDir}/uInitrd-${version} ]
613     then
614     cp -fp ${ubootDir}/uImage-${version} ${ubootDir}/${ubootDefaultImage}
615     if [ $? -ne 0 ]
616     then
617     [[ -n ${verbose} ]] && echo "copy uImage-${version} error, kernel not installed!" && exit
618     fi
619     cp -fp ${ubootDir}/uInitrd-${version} ${ubootDir}/${ubootDefaultInitrd}
620     if [ $? -ne 0 ]
621     then
622     [[ -n ${verbose} ]] && echo "copy uInitrd-${version} error, kernel not installed!" && exit
623     fi
624     echo ${version} >> ${ubootDir}/${ubootKList}
625     [ -x /sbin/a-b-c ] && /sbin/a-b-c
626     else
627     [[ -n ${verbose} ]] && echo "cannot make ${version} the default"
628     fi
629     else
630     [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not setting up ${ubootDir}"
631     fi
632    
633     if [[ -n ${cfgExtlinux} ]]
634     then
635     [[ -n ${verbose} ]] && echo "updating ${version} from ${extlinuxConfig}"
636     ARGS="--extlinux -c ${extlinuxConfig} --update-kernel=${kernelImage} \
637     ${DEVTREE} ${DEVTREEDIR} ${INITRD} ${kernargs:+--args=\"${kernargs}\"} \
638     ${removeargs:+--remove-args=\"${removeargs}\"} \
639     --title=\"${title}\${debugtitle}\""
640     rungrubby ${ARGS}
641     rungrubby --debug ${ARGS}
642     else
643     [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby"
644     fi
645  }  }
646    
647  mkinitrd()  makeinitrd()
648  {  {
649     if [[ -n ${dracut} ]]
650     then
651     tool="dracut ${dracuthostonly} -f ${initrdfile} ${version}"
652     else
653     tool="mkinitrd --allow-missing -f ${initrdfile} ${version}"
654     fi
655   [[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}"   [[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}"
656   /sbin/mkinitrd --allow-missing -f ${initrdfile} ${version}   ${tool}
657   rc=$?   rc=$?
658   if [ ${rc} != 0 ]   if [ ${rc} != 0 ]
659   then   then
# Line 297  doDepmod() Line 677  doDepmod()
677  doRmmoddep()  doRmmoddep()
678  {  {
679   [[ -n ${verbose} ]] && echo "removing modules.dep info for ${version}"   [[ -n ${verbose} ]] && echo "removing modules.dep info for ${version}"
680   [ -d /lib/modules/${version} ] && rm -f /lib/modules/${version}/modules.*   if [ -d /lib/modules/${version} ]
681     then
682     rm -f /lib/modules/${version}/modules.*.bin \
683     /lib/modules/${version}/modules.{alias,dep,devname,symbols,softdep}
684     fi
685  }  }
686    
687    # kernel image for 2.4 is kernel
688    if [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]]
689    then
690     if [[ ${kernelmajor} = 2.4 ]]
691     then
692     kernelName=kernel
693     fi
694    fi
695    
696  while [ $# -gt 0 ]  while [ $# -gt 0 ]
697  do  do
# Line 312  do Line 704  do
704   initrd="remove"   initrd="remove"
705   ;;   ;;
706    
707     --devtree*)
708     if [[ $1 == --devtree\=* ]]
709     then
710     devtreefile="${1#--devtreefile=}"
711     else
712     devtreefile="$2"
713     shift
714     fi
715     ;;
716    
717     --devtreedir*)
718     if [[ $1 == --devtreedir\=* ]]
719     then
720     devtreedir=${1#--devtreedir=}
721     else
722     devtreedir=$2
723     shift
724     fi
725     ;;
726    
727     --dracut)
728     dracut=--dracut
729     ;;
730    
731     --host-only)
732     dracuthostonly=-H
733     ;;
734    
735   --initrdfile*)   --initrdfile*)
736   if echo $1 | grep '=' >/dev/null   if [[ $1 == --initrdfile\=* ]]
737   then   then
738   initrdfile=$(echo $1 | sed 's/^--initrdfile=//')   initrdfile=${1#--initrdfile=}
739   else   else
740   initrdfile=$2   initrdfile=$2
741   shift   shift
# Line 323  do Line 743  do
743   ;;   ;;
744    
745   --kernel-args*)   --kernel-args*)
746   if echo $1 | grep '=' >/dev/null   if [[ $1 == --kernel-args\=* ]]
747   then   then
748   kernargs=$(echo $1 | sed 's/^--kernel-args=//')   kernargs=${1#--kernel-args=}
749   else   else
750   kernargs=$2   kernargs=$2
751   shift   shift
# Line 333  do Line 753  do
753   ;;   ;;
754    
755   --remove-args*)   --remove-args*)
756   if echo $1 | grep '=' >/dev/null   if [[ $1 == --remove-args\=* ]]
757   then   then
758   removeargs=$(echo $1 | sed 's/^--remove-args=//')   removeargs=${1#--remove-args=}
759   else   else
760   removeargs=$2   removeargs=$2
761   shift   shift
# Line 343  do Line 763  do
763   ;;   ;;
764    
765   --banner*)   --banner*)
766   if echo $1 | grep '=' >/dev/null   if [[ $1 == --banner\=* ]]
767   then   then
768   banner=$(echo $1 | sed 's/^--banner=//')   banner=${1#--banner=}
769   else   else
770   banner=$2   banner=$2
771   shift   shift
# Line 353  do Line 773  do
773   ;;   ;;
774    
775   --multiboot*)   --multiboot*)
776   if echo $1 |grep '=' >/dev/null   if [[ $1 == --multiboot\=* ]]
777   then   then
778   mbkernel=$(echo $1 | sed 's/^--multiboot=//')   mbkernel=${1#--multiboot=}
779   else   else
780   # can't really support having an optional second arg here   # can't really support having an optional second arg here
781   # sorry!   # sorry!
# Line 364  do Line 784  do
784   ;;   ;;
785    
786   --mbargs*)   --mbargs*)
787   if echo $1 |grep '=' >/dev/null   if [[ $1 == --mbargs\=* ]]
788   then   then
789   mbargs=$(echo $1 | sed 's/^--mbargs=//')   mbargs=${1#--mbargs=}
790   else   else
791   mbargs="$2"   mbargs="$2"
792   shift   shift
# Line 385  do Line 805  do
805   makedefault="--make-default"   makedefault="--make-default"
806   ;;   ;;
807    
808   --package)   --package*)
809   if echo $1 | grep '=' >/dev/null   if [[ $1 == --package\=* ]]
810   then   then
811   package=$(echo $1 | sed 's/^--package=//')   package=${1#--package=}
812   else   else
813   package=$2   package=$2
814   shift   shift
815   fi   fi
816   ;;   ;;
817    
818     --add-dracut-args)
819     adddracutargs=--add-dracut-args
820     ;;
821    
822     --add-plymouth-initrd)
823     addplymouthinitrd=--add-plymouth-initrd
824     ;;
825    
826     --kernel-image*)
827     if [[ $1 == --kernel-image\=* ]]
828     then
829     kernelImage=${1#--kernel-image=}
830     else
831     kernelImage="$2"
832     shift
833     fi
834     if ! [[ -f ${kernelImage} ]]
835     then
836     echo "Can't find kernel image '${kernelImage}'" >&2
837     usage
838     exit 1
839     fi
840     ;;
841    
842     --kernel-name*)
843     if [[ $1 == --kernel-name\=* ]]
844     then
845     kernelName=${1#--kernel-name=}
846     else
847     kernelName="$2"
848     shift
849     fi
850     ;;
851    
852   -v)   -v)
853   verbose=-v   verbose=-v
854   ;;   ;;
# Line 433  fi Line 887  fi
887    
888  kernelmajor=$(echo ${kernel} | cut -d . -f 1,2)  kernelmajor=$(echo ${kernel} | cut -d . -f 1,2)
889    
890  # 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  
891    
892  # 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
893  if [[ -z ${initrdfile} ]]  if [[ -z ${initrdfile} ]]
894  then  then
895   INITRD_NAME_PREFIX="initrd"   INITRD_NAME_PREFIX="initrd"
896     if [[ -n ${dracut} ]]
897     then
898     INITRD_NAME_PREFIX="initramfs"
899     fi
900    
901   if [[ $(uname -m) = ia64 ]]   if [[ $(uname -m) = ia64 ]]
902   then   then
# Line 456  then Line 907  then
907  fi  fi
908  [[ -n ${verbose} ]] && echo "initrdfile is ${initrdfile}"  [[ -n ${verbose} ]] && echo "initrdfile is ${initrdfile}"
909    
910    if [[ ${ARCH} =~ armv[5|7].*l ]]
911    then
912     if [[ -z ${SHIPSDTB} ]] || [[ ${SHIPSDTB} != yes ]]
913     then
914     if [[ -n ${dtbfile} ]] && [ -f ${bootPrefix}/dtb-${version}/${dtbfile} ]
915     then
916     devtreefile="${bootPrefix}/dtb-${version}/${dtbfile}"
917     [[ -n ${verbose} ]] && echo "devtreefile is ${devtreefile}"
918     elif [ -d ${bootPrefix}/dtb-${version}/ ]
919     then
920     devtreedir="${bootPrefix}/dtb-${version}/"
921     [[ -n ${verbose} ]] && echo "devtreedir is ${devtreedir}"
922     fi
923     fi
924    fi
925    [[ -n ${verbose} ]] && echo "devtreedir is ${devtreedir}"
926    
927    # add dracut kernel args if requested
928    if [[ -n ${dracut} ]] && [[ -n ${adddracutargs} ]]
929     [ -r /etc/vconsole.conf ] && . /etc/vconsole.conf
930     [ -r /etc/locale.conf ] && . /etc/locale.conf
931    
932     while read opt rd_opt
933     do
934     [ -n "${!opt}" ] && kernargs="$kernargs $rd_opt=\"${!opt}\""
935     done <<< 'KEYMAP rd.vconsole.keymap
936     FONT rd.vconsole.font
937     FONT_MAP rd.vconsole.font.map
938     FONT_UNIMAP rd.vconsole.font.unimap
939     UNICODE rd.vconsole.font.unicode
940     EXT_KEYMAP rd.vconsole.keymap.ext
941     LANG rd.locale.LANG
942     LC_ALL rd.locale.LC_ALL'
943    fi
944    
945  # 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
946  if [[ ${mode} = --install ]] && [[ ${UPDATEDEFAULT} = yes ]] && [[ -n ${package} ]] &&  if [[ ${mode} = --install ]] && [[ ${UPDATEDEFAULT} = yes ]] && [[ -n ${package} ]] && [[ -n ${DEFAULTKERNEL} ]]
  [[ -n ${DEFAULTKERNEL} ]] && [[ ${package} = ${DEFAULTKERNEL} ]]  
947  then  then
948   makedefault="--make-default"   if [[ ${package} = ${DEFAULTKERNEL} ]] || [[ ${package}-core = ${DEFAULTKERNEL} ]]
949   [[ -n ${verbose} ]] && echo "making it the default based on config"   then
950     makedefault="--make-default"
951     [[ -n ${verbose} ]] && echo "making it the default based on config"
952     fi
953  fi  fi
954    
955  if [[ ${moddep} = make ]]  if [[ ${moddep} = make ]]
# Line 474  fi Line 962  fi
962    
963  if [[ ${initrd} = make ]]  if [[ ${initrd} = make ]]
964  then  then
965   mkinitrd   makeinitrd
966  elif [[ ${initrd} = remove ]]  elif [[ ${initrd} = remove ]]
967  then  then
968   rminitrd   rminitrd
# Line 487  then Line 975  then
975  fi  fi
976    
977  [[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1  [[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1
978    [[ -n ${grub2Config} ]] && [ -f ${grub2Config} ] && cfgGrub2=1
979    [[ -n ${grub2EfiConfig} ]] && [ -f ${grub2EfiConfig} ] && cfgGrub2Efi=1
980  [[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1  [[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1
981    [[ -n ${extlinuxConfig} ]] && [ -f ${extlinuxConfig} ] && cfgExtlinux=1
982    
983    # if we have a U-Boot directory, but no boot script, check if the directory
984    # is mounted.  If not, mount it, and then check if a boot script exists.
985    if [[ -n ${ubootDir} ]]
986    then
987     if [ -f ${ubootScript} ]
988     then
989     cfguBoot=1
990     else
991     mountEntry=$(mount | grep ${ubootDir})
992     if [[ -z ${mountEntry} ]]
993     then
994     mount ${ubootDevice} ${ubootDir}
995     mounted=1
996     fi
997     [ -f ${ubootScript} ] && cfguBoot=1
998     fi
999    fi
1000    
1001    # if we're using U-Boot, check if the default load address should change
1002    if [[ -n ${cfguBoot} ]] && [[ -z ${UBOOT_IMGADDR} ]]
1003    then
1004     [[ ${version}  =~ .([^.]*)$ ]]
1005     platform=${BASH_REMATCH[1]}
1006     # A few platforms use an alternate kernel load address
1007     if [[ ${platform} = omap ]]
1008     then
1009     ubootAddress=0x80008000
1010     elif [[ ${platform} = imx ]]
1011     then
1012     ubootAddress=0x90008000
1013     fi
1014    fi
1015    
1016  # 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
1017  # is lilo to determine if it should be run  # is lilo to determine if it should be run
# Line 507  then Line 1031  then
1031   update   update
1032  fi  fi
1033    
1034    # if we mounted the U-Boot directory, unmount it.
1035    [[ -n ${mounted} ]] && umount ${ubootDir}
1036    
1037    # make sure changes make it to the disk.
1038    # if /boot is a mountpoint, force the meta data on disk
1039    # to by-pass writeback delay.
1040    # PPC64LE-only to deal with Petitboot issues
1041    if [[ ${ARCH} = ppc64le ]]
1042    then
1043     sync && mountpoint -q /boot && fsfreeze -f /boot && fsfreeze -u /boot
1044    fi
1045    
1046  exit 0  exit 0

Legend:
Removed from v.925  
changed lines
  Added in v.3006