Magellan Linux

Diff of /trunk/grubby/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 1710 by niro, Sat Feb 18 00:28:45 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    grub2Config=""
53    grub2EfiConfig=""
54    
55  ARCH=$(uname -m)  ARCH=$(uname -m)
56    
# Line 77  then Line 83  then
83   lilo=/sbin/zipl   lilo=/sbin/zipl
84   runLilo="yes"   runLilo="yes"
85   isx86=""   isx86=""
86    elif [[ ${ARCH} = armv7l ]]
87    then
88     liloConfig=""
89     bootPrefix=/boot
90     ubootDir=${UBOOT_DIR:-"/boot/uboot"}
91     ubootScript=$ubootDir/${UBOOT_SCR:-"boot.scr"}
92     ubootKList=${UBOOT_KLIST:-"klist.txt"}
93     ubootDevice=/dev/${UBOOT_DEVICE:-"mmcblk0p1"}
94     ubootDefaultImage=${UBOOT_UIMAGE:-"uImage"}
95     ubootDefaultInitrd=${UBOOT_UINITRD:-"uInitrd"}
96     mounted=""
97     liloFlag=""
98     isx86=""
99  else  else
100   # this leaves i?86 and x86_64   # this leaves i?86 and x86_64
101   liloConfig=/etc/lilo.conf   liloConfig=/etc/lilo.conf
102   grubConfig=/boot/grub/grub.conf   grubConfig=/boot/grub/grub.conf
103     grub2Config=/boot/grub/grub.cfg
104     grub2EfiConfig=/boot/grub/grub-efi.cfg
105   bootPrefix=/boot   bootPrefix=/boot
106   liloFlag=lilo   liloFlag=lilo
107   isx86="yes"   isx86="yes"
# Line 96  moddep="" Line 117  moddep=""
117  verbose=""  verbose=""
118  makedefault=""  makedefault=""
119  package=""  package=""
120  mbkernel=""  mbkernel="${HYPERVISOR}"
121  mbargs=""  mbargs="${HYPERVISOR_ARGS}"
122  adddracutargs=""  adddracutargs=""
123  addplymouthinitrd=""  addplymouthinitrd=""
124    
# Line 115  usage() Line 136  usage()
136   exit 1   exit 1
137  }  }
138    
 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  
 }  
   
139  install()  install()
140  {  {
141   # 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 173  install()
173   return   return
174   fi   fi
175    
  # Run grub2's configuration update in parallel, if it is installed  
  run_grub2  
   
176   # get the root filesystem to use   # get the root filesystem to use
177   rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab)   rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab)
178    
# Line 186  install() Line 195  install()
195   else   else
196   title="Magellan Linux (${version})"   title="Magellan Linux (${version})"
197   fi   fi
198   ${grubby} --add-kernel=${bootPrefix}/${kernelName}-${version} \   ${grubby} --grub -c ${grubConfig} \
199     --add-kernel=${bootPrefix}/${kernelName}-${version} \
200   ${INITRD} --copy-default ${makedefault} --title "${title}" \   ${INITRD} --copy-default ${makedefault} --title "${title}" \
201   ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \   ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \
202   --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"   --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
203   else   else
204   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97"
205     fi
206     if [[ -n ${cfgGrub2} ]]
207     then
208     [[ -n ${verbose} ]] && echo "adding ${version} to ${grub2Config}"
209    
210     if [[ -n ${banner} ]]
211     then
212     title="${banner} (${version})"
213     elif [ -f /etc/mageversion ]
214     then
215     title="Magellan Linux $(< /etc/mageversion) (${version})"
216     else
217     title="Magellan Linux (${version})"
218     fi
219     ${grubby} --grub2 -c ${grub2Config} \
220     --add-kernel=${bootPrefix}/${kernelName}-${version} \
221     ${INITRD} --copy-default ${makedefault} --title "${title}" \
222     ${mbkernel:+--add-multiboot="${mbkernel}"} \
223     ${mbargs:+--mbargs="${mbargs}"} \
224     --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
225     else
226     [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby for grub 2"
227     fi
228     if [[ -n ${cfgGrub2Efi} ]]
229     then
230     [[ -n ${verbose} ]] && echo "adding ${version} to ${grub2EfiConfig}"
231    
232     if [[ -n ${banner} ]]
233     then
234     title="${banner} (${version})"
235     elif [ -f /etc/mageversion ]
236     then
237     title="Magellan Linux $(< /etc/mageversion) (${version})"
238     else
239     title="Magellan Linux (${version})"
240     fi
241     ${grubby} --grub2 -c ${grub2EfiConfig} \
242     --add-kernel=${bootPrefix}/${kernelName}-${version} \
243     ${INITRD} --copy-default ${makedefault} --title "${title}" \
244     ${mbkernel:+--add-multiboot="${mbkernel}"} \
245     ${mbargs:+--mbargs="${mbargs}"} \
246     --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
247     else
248     [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby for grub 2 with UEFI"
249   fi   fi
250    
251   if [[ -n ${cfgLilo} ]]   if [[ -n ${cfgLilo} ]]
# Line 229  remove() Line 283  remove()
283   return   return
284   fi   fi
285    
  # Run grub2's configuration update in parallel, if it is installed  
  run_grub2  
   
286   if [[ -n ${cfgGrub} ]]   if [[ -n ${cfgGrub} ]]
287   then   then
288   [[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}"   [[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}"
289   ${grubby} --remove-kernel=${bootPrefix}/${kernelName}-${version}   ${grubby} --grub -c ${grubConfig} \
290     --remove-kernel=${bootPrefix}/${kernelName}-${version}
291   else   else
292   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97"
293     fi
294     if [[ -n ${cfgGrub2} ]]
295     then
296     [[ -n ${verbose} ]] && echo "removing ${version} from ${grub2Config}"
297     ${grubby} --grub2 -c ${grub2Config} \
298     --remove-kernel=${bootPrefix}/${kernelName}-${version}
299     else
300     [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby for grub 2"
301     fi
302     if [[ -n ${cfgGrub2Efi} ]]
303     then
304     [[ -n ${verbose} ]] && echo "removing ${version} from ${grub2EfiConfig}"
305     ${grubby} --grub2 -c ${grub2EfiConfig} \
306     --remove-kernel=${bootPrefix}/${kernelName}-${version}
307     else
308     [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby grub 2 with UEFI"
309   fi   fi
310    
311   if [[ -n ${cfgLilo} ]]   if [[ -n ${cfgLilo} ]]
# Line 258  remove() Line 326  remove()
326   else   else
327   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
328   fi   fi
329    
330     if [[ -n ${cfguBoot} ]]
331     then
332     [[ -n ${verbose} ]] && echo "removing ${version} from ${ubootDir}..."
333    
334     if [ -f ${ubootDir}/${ubootKList} ]
335     then
336     tmpKList=$(mktemp ${ubootDir}/${ubootKList}.XXXX)
337     curversion=$(tail -n1 ${ubootDir}/${ubootKList})
338     sed "/${version}/d" ${ubootDir}/${ubootKList} > ${tmpKList}
339     newversion=$(tail -n1 ${tmpKList})
340     if [ -f ${ubootDir}/uImage-${newversion} ] && [ -f ${ubootDir}/uInitrd-${newversion} ]
341     then
342     if [[ ${curversion} != ${newversion} ]]
343     then
344     cp -fp ${ubootDir}/uImage-${newversion} ${ubootDir}/${ubootDefaultImage}
345     if [ $? -ne 0 ]
346     then
347     [[ -n ${verbose} ]] && echo "copy uImage-${newversion} error, default kernel not replaced!" && exit
348     fi
349     cp -fp ${ubootDir}/uInitrd-${newversion} ${ubootDir}/${ubootDefaultInitrd}
350     if [ $? -ne 0 ]
351     then
352     [[ -n ${verbose} ]] && echo "copy uInitrd-${newversion} error, default Initrd not replaced!" && exit
353     fi
354     fi
355    
356     [[ -n ${verbose} ]] && echo "removing uImage-${version}"
357     if [ -f ${ubootDir}/uImage-${version} ]
358     then
359     rm -f ${ubootDir}/uImage-${version}
360     else
361     [[ -n ${verbose} ]] && echo "uImage-${version} did not exist!"
362     fi
363    
364     [[ -n ${verbose} ]] && echo "removing uInitrd-${version}"
365     if [ -f ${ubootDir}/uInitrd-${version} ]
366     then
367     rm -f ${ubootDir}/uInitrd-${version}
368     else
369     [[ -n ${verbose} ]] && echo "uInitrd-${version} did not exist!"
370     fi
371    
372     mv ${tmpKList} ${ubootDir}/${ubootKList}
373     else
374     [[ -n ${verbose} ]] && echo "uImage ${newversion} does not exist!"
375     [ -f ${tmpKList} ] && rm -f ${tmpKList}
376     fi
377     else
378     [[ -n ${verbose} ]] && echo "No previous kernel version. uBoot images not removed!"
379     fi
380     else
381     [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}"
382     fi
383  }  }
384    
385  update()  update()
# Line 280  update() Line 402  update()
402   fi   fi
403   fi   fi
404    
  # Run grub2's configuration update in parallel, if it is installed  
  run_grub2  
   
405   if [[ -n ${cfgGrub} ]]   if [[ -n ${cfgGrub} ]]
406   then   then
407   [[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}"   [[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}"
408   ${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \   ${grubby} --grub -c ${grubConfig} \
409     --update-kernel=${bootPrefix}/${kernelName}-${version} \
410   ${INITRD} \   ${INITRD} \
411   ${kernargs:+--args="${kernargs}"} \   ${kernargs:+--args="${kernargs}"} \
412   ${removeargs:+--remove-args="${removeargs}"}   ${removeargs:+--remove-args="${removeargs}"}
# Line 294  update() Line 414  update()
414   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby"
415   fi   fi
416    
417     if [[ -n ${cfgGrub2} ]]
418     then
419     [[ -n ${verbose} ]] && echo "updating ${version} from ${grub2Config}"
420     ${grubby} --grub2 -c ${grub2Config} \
421     --update-kernel=${bootPrefix}/${kernelName}-${version} \
422     ${INITRD} \
423     ${kernargs:+--args="${kernargs}"} \
424     ${removeargs:+--remove-args="${removeargs}"}
425     else
426     [[ -n ${verbose} ]] && echo "${grub2Config} does not exist, not running grubby"
427     fi
428    
429     if [[ -n ${cfgGrub2Efi} ]]
430     then
431     [[ -n ${verbose} ]] && echo "updating ${version} from ${grub2EfiConfig}"
432     ${grubby} --grub2 -c ${grub2EfiConfig} \
433     --update-kernel=${bootPrefix}/${kernelName}-${version} \
434     ${INITRD} \
435     ${kernargs:+--args="${kernargs}"} \
436     ${removeargs:+--remove-args="${removeargs}"}
437     else
438     [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby"
439     fi
440    
441   if [[ -n ${cfgLilo} ]]   if [[ -n ${cfgLilo} ]]
442   then   then
443   [[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}"   [[ -n ${verbose} ]] && echo "updating ${version} from ${liloConfig}"
# Line 316  update() Line 460  update()
460   else   else
461   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
462   fi   fi
463    
464     if [[ -n ${cfguBoot} ]]
465     then
466     [[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..."
467    
468     [[ -n ${verbose} ]] && echo "creating uImage-${version}"
469     mkimage -A arm -O linux -T kernel -C none -a 0x80008000 -e 0x80008000 \
470     -n ${version} -d ${bootPrefix}/${kernelName}-${version} ${ubootDir}/uImage-${version}
471    
472     [[ -n ${verbose} ]] && echo "creating uInitrd-${version}"
473     mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 \
474     -n initramfs -d ${initrdfile} ${ubootDir}/uInitrd-${version}
475    
476     if [ -f ${ubootDir}/uImage-${version} ] && [ -f ${ubootDir}/uInitrd-${version} ]
477     then
478     cp -fp ${ubootDir}/uImage-${version} ${ubootDir}/${ubootDefaultImage}
479     if [ $? -ne 0 ]
480     then
481     [[ -n ${verbose} ]] && echo "copy uImage-${version} error, kernel not installed!" && exit
482     fi
483     cp -fp ${ubootDir}/uInitrd-${version} ${ubootDir}/${ubootDefaultInitrd}
484     if [ $? -ne 0 ]
485     then
486     [[ -n ${verbose} ]] && echo "copy uInitrd-${version} error, kernel not installed!" && exit
487     fi
488     echo ${version} >> ${ubootDir}/${ubootKList}
489     else
490     [[ -n ${verbose} ]] && echo "cannot make ${version} the default"
491     fi
492     else
493     [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not setting up ${ubootDir}"
494     fi
495  }  }
496    
497  mkinitrd()  mkinitrd()
# Line 578  then Line 754  then
754  fi  fi
755    
756  [[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1  [[ -n ${grubConfig} ]] && [ -f ${grubConfig} ] && cfgGrub=1
757    [[ -n ${grub2Config} ]] && [ -f ${grub2Config} ] && cfgGrub2=1
758    [[ -n ${grub2EfiConfig} ]] && [ -f ${grub2EfiConfig} ] && cfgGrub2Efi=1
759  [[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1  [[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1
760    
761    # if we have a uBoot directory, check if it is mounted.
762    # if not, mount it. Then check if a boot script exists.
763    if [[ -n ${ubootDir} ]]
764    then
765     mountEntry=$(mount | grep ${ubootDir})
766     if [[ -z ${mountEntry} ]]
767     then
768     mount ${ubootDevice} ${ubootDir}
769     mounted=1
770     fi
771     [ -f ${ubootScript} ] && cfguBoot=1
772    fi
773    
774  # 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
775  # is lilo to determine if it should be run  # is lilo to determine if it should be run
776  if [[ -n ${cfgLilo} ]] && [[ -n ${isx86} ]]  if [[ -n ${cfgLilo} ]] && [[ -n ${isx86} ]]

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