Magellan Linux

Diff of /tags/grubby-8_15/new-kernel-pkg

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/mkinitrd-magellan/grubby/new-kernel-pkg revision 1305 by niro, Fri May 27 17:31:15 2011 UTC trunk/grubby/new-kernel-pkg revision 1697 by niro, Sat Feb 18 00:15:09 2012 UTC
# Line 40  else Line 40  else
40  fi  fi
41    
42  [ -f /etc/conf.d/grubby ] && . /etc/conf.d/grubby  [ -f /etc/conf.d/grubby ] && . /etc/conf.d/grubby
43    [ -f /etc/conf.d/grubby-uboot ] && . /etc/conf.d/grubby-uboot
44    
45    cfgGrub2=""
46    cfgGrub2Efi=""
47  cfgGrub=""  cfgGrub=""
48  cfgLilo=""  cfgLilo=""
49    cfguBoot=""
50  runLilo=""  runLilo=""
51  grubConfig=""  grubConfig=""
52    
# Line 77  then Line 81  then
81   lilo=/sbin/zipl   lilo=/sbin/zipl
82   runLilo="yes"   runLilo="yes"
83   isx86=""   isx86=""
84    elif [[ ${ARCH} = armv7l ]]
85    then
86     liloConfig=""
87     bootPrefix=/boot
88     ubootDir=${UBOOT_DIR:-"/boot/uboot"}
89     ubootScript=$ubootDir/${UBOOT_SCR:-"boot.scr"}
90     ubootKList=${UBOOT_KLIST:-"klist.txt"}
91     ubootDevice=/dev/${UBOOT_DEVICE:-"mmcblk0p1"}
92     ubootDefaultImage=${UBOOT_UIMAGE:-"uImage"}
93     ubootDefaultInitrd=${UBOOT_UINITRD:-"uInitrd"}
94     mounted=""
95     liloFlag=""
96     isx86=""
97  else  else
98   # this leaves i?86 and x86_64   # this leaves i?86 and x86_64
99   liloConfig=/etc/lilo.conf   liloConfig=/etc/lilo.conf
100   grubConfig=/boot/grub/grub.conf   grubConfig=/boot/grub/grub.conf
101     grub2Config=/boot/grub/grub.cfg
102     grub2EfiConfig=/boot/grub/grub-efi.cfg
103   bootPrefix=/boot   bootPrefix=/boot
104   liloFlag=lilo   liloFlag=lilo
105   isx86="yes"   isx86="yes"
# Line 89  fi Line 108  fi
108  mode=""  mode=""
109  version=""  version=""
110  initrd=""  initrd=""
111    dracut=""
112    dracuthostonly=""
113  initrdfile=""  initrdfile=""
114  moddep=""  moddep=""
115  verbose=""  verbose=""
# Line 96  makedefault="" Line 117  makedefault=""
117  package=""  package=""
118  mbkernel=""  mbkernel=""
119  mbargs=""  mbargs=""
120    adddracutargs=""
121    addplymouthinitrd=""
122    
123  usage()  usage()
124  {  {
125   echo "Usage: $(basename $0) [-v] [--mkinitrd] [--rminitrd]" >&2   echo "Usage: $(basename $0) [-v] [--mkinitrd] [--rminitrd] [--dracut]" >&2
126   echo "       [--initrdfile=<initrd-image>] [--depmod] [--rmmoddep]" >&2   echo "       [--initrdfile=<initrd-image>] [--depmod] [--rmmoddep]" >&2
127   echo "       [--kernel-args=<args>] [--remove-args=<args>]" >&2   echo "       [--kernel-args=<args>] [--remove-args=<args>]" >&2
128   echo "       [--banner=<banner>] [--multiboot=multiboot]" >&2   echo "       [--banner=<banner>] [--multiboot=multiboot]" >&2
129   echo "       [--mbargs=mbargs] [--make-default]" >&2   echo "       [--mbargs=mbargs] [--make-default] [--add-dracut-args]" >&2
130     echo "       [--add-plymouth-initrd]" >&2
131     echo "       [--host-only]" >&2
132   echo "       <--install | --remove | --update> <kernel-version>" >&2   echo "       <--install | --remove | --update> <kernel-version>" >&2
133   echo "       (ex: $(basename $0) --mkinitrd --depmod --install 2.4.7-2)" >&2   echo "       (ex: $(basename $0) --mkinitrd --depmod --install 2.4.7-2)" >&2
134   exit 1   exit 1
135  }  }
136    
 run_grub2()  
 {  
  if [ -d /boot/grub2 -a -x /sbin/grub2-mkconfig ]  
  then  
  cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.old  
  /sbin/grub2-mkconfig -o /boot/grub2/grub.cfg  
  fi  
 }  
   
137  install()  install()
138  {  {
139   # 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)
# Line 132  install() Line 148  install()
148   then   then
149   [[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby"   [[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby"
150   INITRD="--initrd ${initrdfile}"   INITRD="--initrd ${initrdfile}"
151    
152     if [[ -n ${addplymouthinitrd} ]]
153     then
154     INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img"
155     fi
156   fi   fi
157    
158   # 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 150  install() Line 171  install()
171   return   return
172   fi   fi
173    
  # Run grub2's configuration update in parallel, if it is installed  
  run_grub2  
   
174   # get the root filesystem to use   # get the root filesystem to use
175   rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab)   rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab)
176    
# Line 175  install() Line 193  install()
193   else   else
194   title="Magellan Linux (${version})"   title="Magellan Linux (${version})"
195   fi   fi
196   ${grubby} --add-kernel=${bootPrefix}/${kernelName}-${version} \   ${grubby} --grub --add-kernel=${bootPrefix}/${kernelName}-${version} \
197   ${INITRD} --copy-default ${makedefault} --title "${title}" \   ${INITRD} --copy-default ${makedefault} --title "${title}" \
198   ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \   ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \
199   --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"   --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
200   else   else
201   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97"
202     fi
203     if [[ -n ${cfgGrub2} ]]
204     then
205     [[ -n ${verbose} ]] && echo "adding ${version} to ${grub2Config}"
206    
207     if [[ -n ${banner} ]]
208     then
209     title="${banner} (${version})"
210     elif [ -f /etc/mageversion ]
211     then
212     title="Magellan Linux $(< /etc/mageversion) (${version})"
213     else
214     title="Magellan Linux (${version})"
215     fi
216     ${grubby} --grub2 -c ${grub2Cfg} \
217     --add-kernel=${bootPrefix}/${kernelName}-${version} \
218     ${INITRD} --copy-default ${makedefault} --title "${title}" \
219     ${mbkernel:+--add-multiboot="${mbkernel}"} \
220     ${mbargs:+--mbargs="${mbargs}"} \
221     --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
222     else
223     [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby for grub 2"
224     fi
225     if [[ -n ${cfgGrub2Efi} ]]
226     then
227     [[ -n ${verbose} ]] && echo "adding ${version} to ${grub2EfiConfig}"
228    
229     if [[ -n ${banner} ]]
230     then
231     title="${banner} (${version})"
232     elif [ -f /etc/mageversion ]
233     then
234     title="Magellan Linux $(< /etc/mageversion) (${version})"
235     else
236     title="Magellan Linux (${version})"
237     fi
238     ${grubby} --grub2 -c ${grub2EfiCfg} \
239     --add-kernel=${bootPrefix}/${kernelName}-${version} \
240     ${INITRD} --copy-default ${makedefault} --title "${title}" \
241     ${mbkernel:+--add-multiboot="${mbkernel}"} \
242     ${mbargs:+--mbargs="${mbargs}"} \
243     --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
244     else
245     [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby for grub 2 with UEFI"
246   fi   fi
247    
248   if [[ -n ${cfgLilo} ]]   if [[ -n ${cfgLilo} ]]
# Line 218  remove() Line 280  remove()
280   return   return
281   fi   fi
282    
  # Run grub2's configuration update in parallel, if it is installed  
  run_grub2  
   
283   if [[ -n ${cfgGrub} ]]   if [[ -n ${cfgGrub} ]]
284   then   then
285   [[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}"   [[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}"
286   ${grubby} --remove-kernel=${bootPrefix}/${kernelName}-${version}   ${grubby} --grub --remove-kernel=${bootPrefix}/${kernelName}-${version}
287   else   else
288   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97"
289     fi
290     if [[ -n ${cfgGrub2} ]]
291     then
292     [[ -n ${verbose} ]] && echo "removing ${version} from ${grub2Config}"
293     ${grubby} --grub2 -c ${grub2Config} \
294     --remove-kernel=${bootPrefix}/${kernelName}-${version}
295     else
296     [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby for grub 2"
297     fi
298     if [[ -n ${cfgGrub2Efi} ]]
299     then
300     [[ -n ${verbose} ]] && echo "removing ${version} from ${grub2EfiConfig}"
301     ${grubby} --grub2 -c ${grub2EfiConfig} \
302     --remove-kernel=${bootPrefix}/${kernelName}-${version}
303     else
304     [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby grub 2 with UEFI"
305   fi   fi
306    
307   if [[ -n ${cfgLilo} ]]   if [[ -n ${cfgLilo} ]]
# Line 247  remove() Line 322  remove()
322   else   else
323   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
324   fi   fi
325    
326     if [[ -n ${cfguBoot} ]]
327     then
328     [[ -n ${verbose} ]] && echo "removing ${version} from ${ubootDir}..."
329    
330     if [ -f ${ubootDir}/${ubootKList} ]
331     then
332     tmpKList=$(mktemp ${ubootDir}/${ubootKList}.XXXX)
333     curversion=$(tail -n1 ${ubootDir}/${ubootKList})
334     sed "/${version}/d" ${ubootDir}/${ubootKList} > ${tmpKList}
335     newversion=$(tail -n1 ${tmpKList})
336     if [ -f ${ubootDir}/uImage-${newversion} ] && [ -f ${ubootDir}/uInitrd-${newversion} ]
337     then
338     if [[ ${curversion} != ${newversion} ]]
339     then
340     cp -fp ${ubootDir}/uImage-${newversion} ${ubootDir}/${ubootDefaultImage}
341     if [ $? -ne 0 ]
342     then
343     [[ -n ${verbose} ]] && echo "copy uImage-${newversion} error, default kernel not replaced!" && exit
344     fi
345     cp -fp ${ubootDir}/uInitrd-${newversion} ${ubootDir}/${ubootDefaultInitrd}
346     if [ $? -ne 0 ]
347     then
348     [[ -n ${verbose} ]] && echo "copy uInitrd-${newversion} error, default Initrd not replaced!" && exit
349     fi
350     fi
351    
352     [[ -n ${verbose} ]] && echo "removing uImage-${version}"
353     if [ -f ${ubootDir}/uImage-${version} ]
354     then
355     rm -f ${ubootDir}/uImage-${version}
356     else
357     [[ -n ${verbose} ]] && echo "uImage-${version} did not exist!"
358     fi
359    
360     [[ -n ${verbose} ]] && echo "removing uInitrd-${version}"
361     if [ -f ${ubootDir}/uInitrd-${version} ]
362     then
363     rm -f ${ubootDir}/uInitrd-${version}
364     else
365     [[ -n ${verbose} ]] && echo "uInitrd-${version} did not exist!"
366     fi
367    
368     mv ${tmpKList} ${ubootDir}/${ubootKList}
369     else
370     [[ -n ${verbose} ]] && echo "uImage ${newversion} does not exist!"
371     [ -f ${tmpKList} ] && rm -f ${tmpKList}
372     fi
373     else
374     [[ -n ${verbose} ]] && echo "No previous kernel version. uBoot images not removed!"
375     fi
376     else
377     [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}"
378     fi
379  }  }
380    
381  update()  update()
# Line 262  update() Line 391  update()
391   then   then
392   [[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby"   [[ -n ${verbose} ]] && echo "found ${initrdfile} and using it with grubby"
393   INITRD="--initrd ${initrdfile}"   INITRD="--initrd ${initrdfile}"
  fi  
394    
395   # Run grub2's configuration update in parallel, if it is installed   if [[ -n ${addplymouthinitrd} ]]
396   run_grub2   then
397     INITRD="${INITRD} --extra-initrd ${bootPrefix}/initrd-plymouth.img"
398     fi
399     fi
400    
401   if [[ -n ${cfgGrub} ]]   if [[ -n ${cfgGrub} ]]
402   then   then
# Line 278  update() Line 409  update()
409   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"
410   fi   fi
411    
412     if [[ -n ${cfgGrub2} ]]
413     then
414     [[ -n ${verbose} ]] && echo "updating ${version} from ${grub2Config}"
415     ${grubby} --grub2 -c ${grub2Config} \
416     --update-kernel=${bootPrefix}/${kernelName}-${version} \
417     ${INITRD} \
418     ${kernargs:+--args="${kernargs}"} \
419     ${removeargs:+--remove-args="${removeargs}"}
420     else
421     [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby"
422     fi
423    
424     if [[ -n ${cfgGrub2Efi} ]]
425     then
426     [[ -n ${verbose} ]] && echo "updating ${version} from ${grub2EfiConfig}"
427     ${grubby} --grub2 -c ${grub2EfiConfig} \
428     --update-kernel=${bootPrefix}/${kernelName}-${version} \
429     ${INITRD} \
430     ${kernargs:+--args="${kernargs}"} \
431     ${removeargs:+--remove-args="${removeargs}"}
432     else
433     [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby"
434     fi
435    
436   if [[ -n ${cfgLilo} ]]   if [[ -n ${cfgLilo} ]]
437   then   then
438   [[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}"   [[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}"
# Line 300  update() Line 455  update()
455   else   else
456   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
457   fi   fi
458    
459     if [[ -n ${cfguBoot} ]]
460     then
461     [[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..."
462    
463     [[ -n ${verbose} ]] && echo "creating uImage-${version}"
464     mkimage -A arm -O linux -T kernel -C none -a 0x80008000 -e 0x80008000 \
465     -n ${version} -d ${bootPrefix}/${kernelName}-${version} ${ubootDir}/uImage-${version}
466    
467     [[ -n ${verbose} ]] && echo "creating uInitrd-${version}"
468     mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 \
469     -n initramfs -d ${initrdfile} ${ubootDir}/uInitrd-${version}
470    
471     if [ -f ${ubootDir}/uImage-${version} ] && [ -f ${ubootDir}/uInitrd-${version} ]
472     then
473     cp -fp ${ubootDir}/uImage-${version} ${ubootDir}/${ubootDefaultImage}
474     if [ $? -ne 0 ]
475     then
476     [[ -n ${verbose} ]] && echo "copy uImage-${version} error, kernel not installed!" && exit
477     fi
478     cp -fp ${ubootDir}/uInitrd-${version} ${ubootDir}/${ubootDefaultInitrd}
479     if [ $? -ne 0 ]
480     then
481     [[ -n ${verbose} ]] && echo "copy uInitrd-${version} error, kernel not installed!" && exit
482     fi
483     echo ${version} >> ${ubootDir}/${ubootKList}
484     else
485     [[ -n ${verbose} ]] && echo "cannot make ${version} the default"
486     fi
487     else
488     [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not setting up ${ubootDir}"
489     fi
490  }  }
491    
492  mkinitrd()  mkinitrd()
493  {  {
494     if [[ -n ${dracut} ]]
495     then
496     tool="/sbin/dracut ${dracuthostonly} -f ${initrdfile} ${version}"
497     else
498     tool="/sbin/mkinitrd --allow-missing -f ${initrdfile} ${version}"
499     fi
500   [[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}"   [[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}"
501   /sbin/mkinitrd --allow-missing -f ${initrdfile} ${version}   ${tool}
502   rc=$?   rc=$?
503   if [ ${rc} != 0 ]   if [ ${rc} != 0 ]
504   then   then
# Line 344  do Line 537  do
537   initrd="remove"   initrd="remove"
538   ;;   ;;
539    
540     --dracut)
541     dracut=--dracut
542     ;;
543    
544     --host-only)
545     dracuthostonly=-H
546     ;;
547    
548   --initrdfile*)   --initrdfile*)
549   if echo $1 | grep '=' >/dev/null   if echo $1 | grep '=' >/dev/null
550   then   then
# Line 427  do Line 628  do
628   fi   fi
629   ;;   ;;
630    
631     --add-dracut-args)
632     adddracutargs=--add-dracut-args
633     ;;
634    
635     --add-plymouth-initrd)
636     addplymouthinitrd=--add-plymouth-initrd
637     ;;
638    
639   -v)   -v)
640   verbose=-v   verbose=-v
641   ;;   ;;
# Line 478  fi Line 687  fi
687  if [[ -z ${initrdfile} ]]  if [[ -z ${initrdfile} ]]
688  then  then
689   INITRD_NAME_PREFIX="initrd"   INITRD_NAME_PREFIX="initrd"
690     if [[ -n ${dracut} ]]
691     then
692     INITRD_NAME_PREFIX="initramfs"
693     fi
694    
695   if [[ $(uname -m) = ia64 ]]   if [[ $(uname -m) = ia64 ]]
696   then   then
# Line 488  then Line 701  then
701  fi  fi
702  [[ -n ${verbose} ]] && echo "initrdfile is ${initrdfile}"  [[ -n ${verbose} ]] && echo "initrdfile is ${initrdfile}"
703    
704    # add dracut i18n, keyboard and plymouth kernel args if requested
705    if [[ -n ${dracut} ]] || [[ -n ${adddracutargs} ]]
706    then
707     [ -r /etc/conf.d/keymap ] && . /etc/conf.d/keymap
708     [ -r /etc/conf.d/consolefont ] && . /etc/conf.d/consolefont
709    
710     if [[ -n ${KEYMAP} ]]
711     then
712     kernargs="${kernargs} KEYTABLE=${KEYMAP}"
713     fi
714    
715     if [[ -n ${CONSOLEFONT} ]]
716     then
717     kernargs="${kernargs} SYSFONT=${CONSOLEFONT}"
718     fi
719    fi
720    
721  # 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
722  if [[ ${mode} = --install ]] && [[ ${UPDATEDEFAULT} = yes ]] && [[ -n ${package} ]] &&  if [[ ${mode} = --install ]] && [[ ${UPDATEDEFAULT} = yes ]] && [[ -n ${package} ]] &&
723   [[ -n ${DEFAULTKERNEL} ]] && [[ ${package} = ${DEFAULTKERNEL} ]]   [[ -n ${DEFAULTKERNEL} ]] && [[ ${package} = ${DEFAULTKERNEL} ]]
# Line 519  then Line 749  then
749  fi  fi
750    
751  [[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1  [[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1
752    [[ -n ${grub2Config} ]] && [ -f ${grub2Config} ] && cfgGrub2=1
753    [[ -n ${grub2EfiConfig} ]] && [ -f ${grub2EfiConfig} ] && cfgGrub2Efi=1
754  [[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1  [[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1
755    
756    # if we have a uBoot directory, check if it is mounted.
757    # if not, mount it. Then check if a boot script exists.
758    if [[ -n ${ubootDir} ]]
759    then
760     mountEntry=$(mount | grep ${ubootDir})
761     if [[ -z ${mountEntry} ]]
762     then
763     mount ${ubootDevice} ${ubootDir}
764     mounted=1
765     fi
766     [ -f ${ubootScript} ] && cfguBoot=1
767    fi
768    
769  # if we have a lilo config on an x86 box, see if the default boot loader  # if we have a lilo config on an x86 box, see if the default boot loader
770  # is lilo to determine if it should be run  # is lilo to determine if it should be run
771  if [[ -n ${cfgLilo} ]] && [[ -n ${isx86} ]]  if [[ -n ${cfgLilo} ]] && [[ -n ${isx86} ]]

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