Magellan Linux

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

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

revision 1334 by niro, Fri Jun 3 20:56:30 2011 UTC revision 1757 by niro, Sat Feb 18 11:57:40 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    cfgExtlinux=""
50    cfguBoot=""
51  runLilo=""  runLilo=""
52  grubConfig=""  grubConfig=""
53    grub2Config=""
54    grub2EfiConfig=""
55    extlinuxConfig=""
56    
57  ARCH=$(uname -m)  ARCH=$(uname -m)
58    
# Line 77  then Line 85  then
85   lilo=/sbin/zipl   lilo=/sbin/zipl
86   runLilo="yes"   runLilo="yes"
87   isx86=""   isx86=""
88    elif [[ ${ARCH} = armv7l ]] || [[ ${ARCH} = armv7hl ]]
89    then
90     machine=$(grep "^Hardware" /proc/cpuinfo | sed 's/Hardware\s*:\s*//')
91     liloConfig=""
92     bootPrefix=/boot
93     ubootDir=${UBOOT_DIR:-"/boot/uboot"}
94     ubootScript=$ubootDir/${UBOOT_SCR:-"boot.scr"}
95     ubootKList=${UBOOT_KLIST:-"klist.txt"}
96     ubootDevice=/dev/${UBOOT_DEVICE:-"mmcblk0p1"}
97     ubootDefaultImage=${UBOOT_UIMAGE:-"uImage"}
98     ubootDefaultInitrd=${UBOOT_UINITRD:-"uInitrd"}
99     mounted=""
100     liloFlag=""
101     isx86=""
102     if [[ ${machine} == "OMAP3 Beagle Board" ]] || [[ ${machine} == "OMAP4 Panda board" ]]
103     then
104     ubootAddress=0x80008000
105     else
106     ubootAddress=0x00008000
107     fi
108  else  else
109   # this leaves i?86 and x86_64   # this leaves i?86 and x86_64
110   liloConfig=/etc/lilo.conf   liloConfig=/etc/lilo.conf
111   grubConfig=/boot/grub/grub.conf   grubConfig=/boot/grub/grub.conf
112     grub2Config=/boot/grub/grub.cfg
113     grub2EfiConfig=/boot/grub/grub-efi.cfg
114     extlinuxConfig=/boot/extlinux/extlinux.conf
115   bootPrefix=/boot   bootPrefix=/boot
116   liloFlag=lilo   liloFlag=lilo
117   isx86="yes"   isx86="yes"
# Line 96  moddep="" Line 127  moddep=""
127  verbose=""  verbose=""
128  makedefault=""  makedefault=""
129  package=""  package=""
130  mbkernel=""  mbkernel="${HYPERVISOR}"
131  mbargs=""  mbargs="${HYPERVISOR_ARGS}"
132  adddracutargs=""  adddracutargs=""
133  addplymouthinitrd=""  addplymouthinitrd=""
134    
# Line 115  usage() Line 146  usage()
146   exit 1   exit 1
147  }  }
148    
 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  
 }  
   
149  install()  install()
150  {  {
151   # 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 161  install() Line 183  install()
183   return   return
184   fi   fi
185    
  # Run grub2's configuration update in parallel, if it is installed  
  run_grub2  
   
186   # get the root filesystem to use   # get the root filesystem to use
187   rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab)   rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab)
188    
# Line 179  install() Line 198  install()
198    
199   if [[ -n ${banner} ]]   if [[ -n ${banner} ]]
200   then   then
201   title="${banner} (${version})"   title="${banner} [ ${version} ]"
202   elif [ -f /etc/mageversion ]   elif [ -f /etc/mageversion ]
203   then   then
204   title="Magellan Linux $(< /etc/mageversion) (${version})"   title="Magellan Linux $(< /etc/mageversion) [ ${version} ]"
205   else   else
206   title="Magellan Linux (${version})"   title="Magellan Linux [ ${version} ]"
207   fi   fi
208   ${grubby} --add-kernel=${bootPrefix}/${kernelName}-${version} \   ${grubby} --grub -c ${grubConfig} \
209     --add-kernel=${bootPrefix}/${kernelName}-${version} \
210   ${INITRD} --copy-default ${makedefault} --title "${title}" \   ${INITRD} --copy-default ${makedefault} --title "${title}" \
211   ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \   ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \
212   --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"   --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
213   else   else
214   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97"
215     fi
216     if [[ -n ${cfgGrub2} ]]
217     then
218     [[ -n ${verbose} ]] && echo "adding ${version} to ${grub2Config}"
219    
220     if [[ -n ${banner} ]]
221     then
222     title="${banner} [ ${version} ]"
223     elif [ -f /etc/mageversion ]
224     then
225     title="Magellan Linux $(< /etc/mageversion) [ ${version} ]"
226     else
227     title="Magellan Linux [ ${version} ]"
228     fi
229     ${grubby} --grub2 -c ${grub2Config} \
230     --add-kernel=${bootPrefix}/${kernelName}-${version} \
231     ${INITRD} --copy-default ${makedefault} --title "${title}" \
232     ${mbkernel:+--add-multiboot="${mbkernel}"} \
233     ${mbargs:+--mbargs="${mbargs}"} \
234     --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
235     else
236     [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby for grub 2"
237     fi
238     if [[ -n ${cfgGrub2Efi} ]]
239     then
240     [[ -n ${verbose} ]] && echo "adding ${version} to ${grub2EfiConfig}"
241    
242     if [[ -n ${banner} ]]
243     then
244     title="${banner} [ ${version} ]"
245     elif [ -f /etc/mageversion ]
246     then
247     title="Magellan Linux $(< /etc/mageversion) [ ${version} ]"
248     else
249     title="Magellan Linux [ ${version} ]"
250     fi
251     ${grubby} --grub2 -c ${grub2EfiConfig} \
252     --add-kernel=${bootPrefix}/${kernelName}-${version} \
253     ${INITRD} --copy-default ${makedefault} --title "${title}" \
254     ${mbkernel:+--add-multiboot="${mbkernel}"} \
255     ${mbargs:+--mbargs="${mbargs}"} \
256     --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
257     else
258     [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby for grub 2 with UEFI"
259   fi   fi
260    
261   if [[ -n ${cfgLilo} ]]   if [[ -n ${cfgLilo} ]]
# Line 217  install() Line 281  install()
281   else   else
282   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
283   fi   fi
284    
285     if [[ -n ${cfgExtlinux} ]]
286     then
287     [[ -n ${verbose} ]] && echo "adding ${version} to ${extlinuxConfig}"
288    
289     if [[ -n ${banner} ]]
290     then
291     title="${banner} [ ${version} ]"
292     elif [ -f /etc/mageversion ]
293     then
294     title="Magellan Linux $(< /etc/mageversion) [ ${version} ]"
295     else
296     title="Magellan Linux [ ${version} ]"
297     fi
298     ${grubby} --extlinux -c ${extlinuxConfig} \
299     --add-kernel=${bootPrefix}/${kernelName}-${version} \
300     ${INITRD} --copy-default ${makedefault} --title "${title}" \
301     ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \
302     --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
303     else
304     [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux"
305     fi
306  }  }
307    
308  remove()  remove()
# Line 229  remove() Line 315  remove()
315   return   return
316   fi   fi
317    
  # Run grub2's configuration update in parallel, if it is installed  
  run_grub2  
   
318   if [[ -n ${cfgGrub} ]]   if [[ -n ${cfgGrub} ]]
319   then   then
320   [[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}"   [[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}"
321   ${grubby} --remove-kernel=${bootPrefix}/${kernelName}-${version}   ${grubby} --grub -c ${grubConfig} \
322     --remove-kernel=${bootPrefix}/${kernelName}-${version}
323   else   else
324   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97"
325     fi
326     if [[ -n ${cfgGrub2} ]]
327     then
328     [[ -n ${verbose} ]] && echo "removing ${version} from ${grub2Config}"
329     ${grubby} --grub2 -c ${grub2Config} \
330     --remove-kernel=${bootPrefix}/${kernelName}-${version}
331     else
332     [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby for grub 2"
333     fi
334     if [[ -n ${cfgGrub2Efi} ]]
335     then
336     [[ -n ${verbose} ]] && echo "removing ${version} from ${grub2EfiConfig}"
337     ${grubby} --grub2 -c ${grub2EfiConfig} \
338     --remove-kernel=${bootPrefix}/${kernelName}-${version}
339     else
340     [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby grub 2 with UEFI"
341   fi   fi
342    
343   if [[ -n ${cfgLilo} ]]   if [[ -n ${cfgLilo} ]]
# Line 258  remove() Line 358  remove()
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 ${cfguBoot} ]]
363     then
364     [[ -n ${verbose} ]] && echo "removing ${version} from ${ubootDir}..."
365    
366     if [ -f ${ubootDir}/${ubootKList} ]
367     then
368     tmpKList=$(mktemp ${ubootDir}/${ubootKList}.XXXX)
369     curversion=$(tail -n1 ${ubootDir}/${ubootKList})
370     sed "/${version}/d" ${ubootDir}/${ubootKList} > ${tmpKList}
371     newversion=$(tail -n1 ${tmpKList})
372     if [ -f ${ubootDir}/uImage-${newversion} ] && [ -f ${ubootDir}/uInitrd-${newversion} ]
373     then
374     if [[ ${curversion} != ${newversion} ]]
375     then
376     cp -fp ${ubootDir}/uImage-${newversion} ${ubootDir}/${ubootDefaultImage}
377     if [ $? -ne 0 ]
378     then
379     [[ -n ${verbose} ]] && echo "copy uImage-${newversion} error, default kernel not replaced!" && exit
380     fi
381     cp -fp ${ubootDir}/uInitrd-${newversion} ${ubootDir}/${ubootDefaultInitrd}
382     if [ $? -ne 0 ]
383     then
384     [[ -n ${verbose} ]] && echo "copy uInitrd-${newversion} error, default Initrd not replaced!" && exit
385     fi
386     fi
387    
388     [[ -n ${verbose} ]] && echo "removing uImage-${version}"
389     if [ -f ${ubootDir}/uImage-${version} ]
390     then
391     rm -f ${ubootDir}/uImage-${version}
392     else
393     [[ -n ${verbose} ]] && echo "uImage-${version} did not exist!"
394     fi
395    
396     [[ -n ${verbose} ]] && echo "removing uInitrd-${version}"
397     if [ -f ${ubootDir}/uInitrd-${version} ]
398     then
399     rm -f ${ubootDir}/uInitrd-${version}
400     else
401     [[ -n ${verbose} ]] && echo "uInitrd-${version} did not exist!"
402     fi
403    
404     mv ${tmpKList} ${ubootDir}/${ubootKList}
405     else
406     [[ -n ${verbose} ]] && echo "uImage ${newversion} does not exist!"
407     [ -f ${tmpKList} ] && rm -f ${tmpKList}
408     fi
409     else
410     [[ -n ${verbose} ]] && echo "No previous kernel version.  U-Boot images not removed!"
411     fi
412     else
413     [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}"
414     fi
415    
416     if [[ -n ${cfgExtlinux} ]]
417     then
418     [[ -n ${verbose} ]] && echo "removing ${version} from ${extlinuxConfig}"
419     ${grubby} --extlinux -c ${extlinuxConfig} \
420     --remove-kernel=${bootPrefix}/${kernelName}-${version}
421     else
422     [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux"
423     fi
424  }  }
425    
426  update()  update()
# Line 280  update() Line 443  update()
443   fi   fi
444   fi   fi
445    
  # Run grub2's configuration update in parallel, if it is installed  
  run_grub2  
   
446   if [[ -n ${cfgGrub} ]]   if [[ -n ${cfgGrub} ]]
447   then   then
448   [[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}"   [[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}"
449   ${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \   ${grubby} --grub -c ${grubConfig} \
450     --update-kernel=${bootPrefix}/${kernelName}-${version} \
451   ${INITRD} \   ${INITRD} \
452   ${kernargs:+--args="${kernargs}"} \   ${kernargs:+--args="${kernargs}"} \
453   ${removeargs:+--remove-args="${removeargs}"}   ${removeargs:+--remove-args="${removeargs}"}
# Line 294  update() Line 455  update()
455   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"
456   fi   fi
457    
458     if [[ -n ${cfgGrub2} ]]
459     then
460     [[ -n ${verbose} ]] && echo "updating ${version} from ${grub2Config}"
461     ${grubby} --grub2 -c ${grub2Config} \
462     --update-kernel=${bootPrefix}/${kernelName}-${version} \
463     ${INITRD} \
464     ${kernargs:+--args="${kernargs}"} \
465     ${removeargs:+--remove-args="${removeargs}"}
466     else
467     [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby"
468     fi
469    
470     if [[ -n ${cfgGrub2Efi} ]]
471     then
472     [[ -n ${verbose} ]] && echo "updating ${version} from ${grub2EfiConfig}"
473     ${grubby} --grub2 -c ${grub2EfiConfig} \
474     --update-kernel=${bootPrefix}/${kernelName}-${version} \
475     ${INITRD} \
476     ${kernargs:+--args="${kernargs}"} \
477     ${removeargs:+--remove-args="${removeargs}"}
478     else
479     [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby"
480     fi
481    
482   if [[ -n ${cfgLilo} ]]   if [[ -n ${cfgLilo} ]]
483   then   then
484   [[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}"   [[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}"
# Line 316  update() Line 501  update()
501   else   else
502   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
503   fi   fi
504    
505     if [[ -n ${cfguBoot} ]]
506     then
507     [[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..."
508    
509     [[ -n ${verbose} ]] && echo "creating uImage-${version}"
510     mkimage -A arm -O linux -T kernel -C none -a ${ubootAddress} \
511     -e ${ubootAddress} -n ${version} \
512     -d ${bootPrefix}/${kernelName}-${version} ${ubootDir}/uImage-${version}
513    
514     [[ -n ${verbose} ]] && echo "creating uInitrd-${version}"
515     mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 \
516     -n initramfs -d ${initrdfile} ${ubootDir}/uInitrd-${version}
517    
518     if [ -f ${ubootDir}/uImage-${version} ] && [ -f ${ubootDir}/uInitrd-${version} ]
519     then
520     cp -fp ${ubootDir}/uImage-${version} ${ubootDir}/${ubootDefaultImage}
521     if [ $? -ne 0 ]
522     then
523     [[ -n ${verbose} ]] && echo "copy uImage-${version} error, kernel not installed!" && exit
524     fi
525     cp -fp ${ubootDir}/uInitrd-${version} ${ubootDir}/${ubootDefaultInitrd}
526     if [ $? -ne 0 ]
527     then
528     [[ -n ${verbose} ]] && echo "copy uInitrd-${version} error, kernel not installed!" && exit
529     fi
530     echo ${version} >> ${ubootDir}/${ubootKList}
531     else
532     [[ -n ${verbose} ]] && echo "cannot make ${version} the default"
533     fi
534     else
535     [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not setting up ${ubootDir}"
536     fi
537    
538     if [[ -n ${cfgExtlinux} ]]
539     then
540     [[ -n ${verbose} ]] && echo "updating ${version} from ${extlinuxConfig}"
541     ${grubby} --extlinux -c ${extlinuxConfig} \
542     --update-kernel=${bootPrefix}/${kernelName}-${version} \
543     ${INITRD} \
544     ${kernargs:+--args="${kernargs}"} \
545     ${removeargs:+--remove-args="${removeargs}"}
546     else
547     [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby"
548     fi
549  }  }
550    
551  mkinitrd()  makeinitrd()
552  {  {
553   if [[ -n ${dracut} ]]   if [[ -n ${dracut} ]]
554   then   then
555   tool="/sbin/dracut ${dracuthostonly} -f ${initrdfile} ${version}"   tool="dracut ${dracuthostonly} -f ${initrdfile} ${version}"
556   else   else
557   tool="/sbin/mkinitrd --allow-missing -f ${initrdfile} ${version}"   tool="mkinitrd --allow-missing -f ${initrdfile} ${version}"
558   fi   fi
559   [[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}"   [[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}"
560   ${tool}   ${tool}
# Line 565  fi Line 795  fi
795    
796  if [[ ${initrd} = make ]]  if [[ ${initrd} = make ]]
797  then  then
798   mkinitrd   makeinitrd
799  elif [[ ${initrd} = remove ]]  elif [[ ${initrd} = remove ]]
800  then  then
801   rminitrd   rminitrd
# Line 578  then Line 808  then
808  fi  fi
809    
810  [[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1  [[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1
811    [[ -n ${grub2Config} ]] && [ -f ${grub2Config} ] && cfgGrub2=1
812    [[ -n ${grub2EfiConfig} ]] && [ -f ${grub2EfiConfig} ] && cfgGrub2Efi=1
813  [[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1  [[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1
814    [[ -n ${extlinuxConfig} ]] && [ -f ${extlinuxConfig} ] && cfgExtlinux=1
815    
816    # if we have a U-Boot directory, but no boot script, check if the directory
817    # is mounted.  If not, mount it, and then check if a boot script exists.
818    if [[ -n ${ubootDir} ]]
819    then
820     if [ -f ${ubootScript} ]
821     then
822     cfguBoot=1
823     else
824     mountEntry=$(mount | grep ${ubootDir})
825     if [[ -z ${mountEntry} ]]
826     then
827     mount ${ubootDevice} ${ubootDir}
828     mounted=1
829     fi
830     [ -f ${ubootScript} ] && cfguBoot=1
831     fi
832    fi
833    
834  # 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
835  # is lilo to determine if it should be run  # is lilo to determine if it should be run
# Line 598  then Line 849  then
849   update   update
850  fi  fi
851    
852    # if we mounted the U-Boot directory, unmount it.
853    [[ -n ${mounted} ]] && umount ${ubootDir}
854    
855  exit 0  exit 0

Legend:
Removed from v.1334  
changed lines
  Added in v.1757