Magellan Linux

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

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

revision 1702 by niro, Sat Feb 18 00:21:34 2012 UTC revision 2237 by niro, Mon Oct 21 13:22:08 2013 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 46  cfgGrub2="" Line 72  cfgGrub2=""
72  cfgGrub2Efi=""  cfgGrub2Efi=""
73  cfgGrub=""  cfgGrub=""
74  cfgLilo=""  cfgLilo=""
75    cfgExtlinux=""
76  cfguBoot=""  cfguBoot=""
77  runLilo=""  runLilo=""
78  grubConfig=""  grubConfig=""
79  grub2Config=""  grub2Config=""
80  grub2EfiConfig=""  grub2EfiConfig=""
81    extlinuxConfig=""
82    
83  ARCH=$(uname -m)  ARCH=$(uname -m)
84    
# Line 63  then Line 91  then
91  elif [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]]  elif [[ ${ARCH} = ppc64 ]] || [[ ${ARCH} = ppc ]]
92  then  then
93   liloConfig=/etc/yaboot.conf   liloConfig=/etc/yaboot.conf
94     grub2Config=/boot/grub/grub.cfg
95   bootPrefix=/boot   bootPrefix=/boot
96   lilo=/sbin/ybin   lilo=/sbin/ybin
97   liloFlag=yaboot   liloFlag=yaboot
# Line 83  then Line 112  then
112   lilo=/sbin/zipl   lilo=/sbin/zipl
113   runLilo="yes"   runLilo="yes"
114   isx86=""   isx86=""
115  elif [[ ${ARCH} = armv7l ]]  elif [[ ${ARCH} =~ armv[5|7].*l ]]
116  then  then
117   liloConfig=""   liloConfig=""
118   bootPrefix=/boot   bootPrefix=/boot
119   ubootDir=${UBOOT_DIR:-"/boot/uboot"}   ubootDir=${UBOOT_DIR:-"/boot"}
120   ubootScript=$ubootDir/${UBOOT_SCR:-"boot.scr"}   ubootScript=$ubootDir/${UBOOT_SCR:-"boot.scr"}
121   ubootKList=${UBOOT_KLIST:-"klist.txt"}   ubootKList=${UBOOT_KLIST:-"klist.txt"}
122   ubootDevice=/dev/${UBOOT_DEVICE:-"mmcblk0p1"}   ubootDevice=/dev/${UBOOT_DEVICE:-"mmcblk0p1"}
123   ubootDefaultImage=${UBOOT_UIMAGE:-"uImage"}   ubootDefaultImage=${UBOOT_UIMAGE:-"uImage"}
124   ubootDefaultInitrd=${UBOOT_UINITRD:-"uInitrd"}   ubootDefaultInitrd=${UBOOT_UINITRD:-"uInitrd"}
125     ubootAddress=${UBOOT_IMGADDR:-"0x00008000"}
126   mounted=""   mounted=""
127   liloFlag=""   liloFlag=""
128   isx86=""   isx86=""
# Line 102  else Line 132  else
132   grubConfig=/boot/grub/grub.conf   grubConfig=/boot/grub/grub.conf
133   grub2Config=/boot/grub/grub.cfg   grub2Config=/boot/grub/grub.cfg
134   grub2EfiConfig=/boot/grub/grub-efi.cfg   grub2EfiConfig=/boot/grub/grub-efi.cfg
135     extlinuxConfig=/boot/extlinux/extlinux.conf
136   bootPrefix=/boot   bootPrefix=/boot
137   liloFlag=lilo   liloFlag=lilo
138   isx86="yes"   isx86="yes"
# Line 117  moddep="" Line 148  moddep=""
148  verbose=""  verbose=""
149  makedefault=""  makedefault=""
150  package=""  package=""
151  mbkernel=""  mbkernel="${HYPERVISOR}"
152  mbargs=""  mbargs="${HYPERVISOR_ARGS}"
153  adddracutargs=""  adddracutargs=""
154  addplymouthinitrd=""  addplymouthinitrd=""
155    
# Line 175  install() Line 206  install()
206    
207   # get the root filesystem to use   # get the root filesystem to use
208   rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab)   rootdevice=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/fstab)
209     if [[ -z $rootdevice ]]
210     then
211     rootdevice=$(grep -o -P "(?<=root=)\S+" /proc/cmdline)
212     fi
213    
214   if [[ -n ${mbkernel} ]] && [[ -n ${cfgLilo} ]] && [[ ${liloFlag} != elilo ]]   if [[ -n ${mbkernel} ]] && [[ -n ${cfgLilo} ]] && [[ ${liloFlag} != elilo ]]
215   then   then
# Line 188  install() Line 223  install()
223    
224   if [[ -n ${banner} ]]   if [[ -n ${banner} ]]
225   then   then
226   title="${banner} (${version})"   title="${banner} [ ${version} ]"
227   elif [ -f /etc/mageversion ]   elif [ -f /etc/mageversion ]
228   then   then
229   title="Magellan Linux $(< /etc/mageversion) (${version})"   title="Magellan Linux $(< /etc/mageversion) [ ${version} ]"
230     elif [[ $(read_os_release id) = magellan ]]
231     then
232     title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]"
233   else   else
234   title="Magellan Linux (${version})"   title="Magellan Linux [ ${version} ]"
235   fi   fi
236   ${grubby} --grub --add-kernel=${bootPrefix}/${kernelName}-${version} \   ${grubby} --grub -c ${grubConfig} \
237     --add-kernel=${bootPrefix}/${kernelName}-${version} \
238   ${INITRD} --copy-default ${makedefault} --title "${title}" \   ${INITRD} --copy-default ${makedefault} --title "${title}" \
239   ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \   ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \
240   --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"   --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
# Line 208  install() Line 247  install()
247    
248   if [[ -n ${banner} ]]   if [[ -n ${banner} ]]
249   then   then
250   title="${banner} (${version})"   title="${banner} [ ${version} ]"
251   elif [ -f /etc/mageversion ]   elif [ -f /etc/mageversion ]
252   then   then
253   title="Magellan Linux $(< /etc/mageversion) (${version})"   title="Magellan Linux $(< /etc/mageversion) [ ${version} ]"
254     elif [[ $(read_os_release id) = magellan ]]
255     then
256     title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]"
257   else   else
258   title="Magellan Linux (${version})"   title="Magellan Linux [ ${version} ]"
259   fi   fi
260   ${grubby} --grub2 -c ${grub2Config} \   ${grubby} --grub2 -c ${grub2Config} \
261   --add-kernel=${bootPrefix}/${kernelName}-${version} \   --add-kernel=${bootPrefix}/${kernelName}-${version} \
# Line 230  install() Line 272  install()
272    
273   if [[ -n ${banner} ]]   if [[ -n ${banner} ]]
274   then   then
275   title="${banner} (${version})"   title="${banner} [ ${version} ]"
276   elif [ -f /etc/mageversion ]   elif [ -f /etc/mageversion ]
277   then   then
278   title="Magellan Linux $(< /etc/mageversion) (${version})"   title="Magellan Linux $(< /etc/mageversion) [ ${version} ]"
279     elif [[ $(read_os_release id) = magellan ]]
280     then
281     title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]"
282   else   else
283   title="Magellan Linux (${version})"   title="Magellan Linux [ ${version} ]"
284   fi   fi
285   ${grubby} --grub2 -c ${grub2EfiConfig} \   ${grubby} --grub2 -c ${grub2EfiConfig} --efi \
286   --add-kernel=${bootPrefix}/${kernelName}-${version} \   --add-kernel=${bootPrefix}/${kernelName}-${version} \
287   ${INITRD} --copy-default ${makedefault} --title "${title}" \   ${INITRD} --copy-default ${makedefault} --title "${title}" \
288   ${mbkernel:+--add-multiboot="${mbkernel}"} \   ${mbkernel:+--add-multiboot="${mbkernel}"} \
# Line 270  install() Line 315  install()
315   else   else
316   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"   [[ -n ${verbose} ]] && echo "${liloConfig} does not exist, not running grubby"
317   fi   fi
318    
319     if [[ -n ${cfgExtlinux} ]]
320     then
321     [[ -n ${verbose} ]] && echo "adding ${version} to ${extlinuxConfig}"
322    
323     if [[ -n ${banner} ]]
324     then
325     title="${banner} [ ${version} ]"
326     elif [ -f /etc/mageversion ]
327     then
328     title="Magellan Linux $(< /etc/mageversion) [ ${version} ]"
329     elif [[ $(read_os_release id) = magellan ]]
330     then
331     title="$(read_os_release name) $(read_os_release version_id) [ ${version} ]"
332     else
333     title="Magellan Linux [ ${version} ]"
334     fi
335     ${grubby} --extlinux -c ${extlinuxConfig} \
336     --add-kernel=${bootPrefix}/${kernelName}-${version} \
337     ${INITRD} --copy-default ${makedefault} --title "${title}" \
338     ${mbkernel:+--add-multiboot="${mbkernel}"} ${mbargs:+--mbargs="${mbargs}"} \
339     --args="root=${rootdevice} ${kernargs}" --remove-kernel="TITLE=${title}"
340     else
341     [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux"
342     fi
343  }  }
344    
345  remove()  remove()
# Line 285  remove() Line 355  remove()
355   if [[ -n ${cfgGrub} ]]   if [[ -n ${cfgGrub} ]]
356   then   then
357   [[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}"   [[ -n ${verbose} ]] && echo "removing ${version} from ${grubConfig}"
358   ${grubby} --grub --remove-kernel=${bootPrefix}/${kernelName}-${version}   ${grubby} --grub -c ${grubConfig} \
359     --remove-kernel=${bootPrefix}/${kernelName}-${version}
360   else   else
361   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97"   [[ -n ${verbose} ]] && echo "${grubConfig} does not exist, not running grubby for grub 0.97"
362   fi   fi
# Line 300  remove() Line 371  remove()
371   if [[ -n ${cfgGrub2Efi} ]]   if [[ -n ${cfgGrub2Efi} ]]
372   then   then
373   [[ -n ${verbose} ]] && echo "removing ${version} from ${grub2EfiConfig}"   [[ -n ${verbose} ]] && echo "removing ${version} from ${grub2EfiConfig}"
374   ${grubby} --grub2 -c ${grub2EfiConfig} \   ${grubby} --grub2 -c ${grub2EfiConfig} --efi \
375   --remove-kernel=${bootPrefix}/${kernelName}-${version}   --remove-kernel=${bootPrefix}/${kernelName}-${version}
376   else   else
377   [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby grub 2 with UEFI"   [[ -n ${verbose} ]] && echo "${grub2EfiConfig} does not exist, not running grubby grub 2 with UEFI"
# Line 333  remove() Line 404  remove()
404   then   then
405   tmpKList=$(mktemp ${ubootDir}/${ubootKList}.XXXX)   tmpKList=$(mktemp ${ubootDir}/${ubootKList}.XXXX)
406   curversion=$(tail -n1 ${ubootDir}/${ubootKList})   curversion=$(tail -n1 ${ubootDir}/${ubootKList})
407   sed "/${version}/d" ${ubootDir}/${ubootKList} > ${tmpKList}   sed "/$version$/d" ${ubootDir}/${ubootKList} > ${tmpKList}
408   newversion=$(tail -n1 ${tmpKList})   newversion=$(tail -n1 ${tmpKList})
409   if [ -f ${ubootDir}/uImage-${newversion} ] && [ -f ${ubootDir}/uInitrd-${newversion} ]   if [ -f ${ubootDir}/uImage-${newversion} ] && [ -f ${ubootDir}/uInitrd-${newversion} ]
410   then   then
# Line 373  remove() Line 444  remove()
444   [ -f ${tmpKList} ] && rm -f ${tmpKList}   [ -f ${tmpKList} ] && rm -f ${tmpKList}
445   fi   fi
446   else   else
447   [[ -n ${verbose} ]] && echo "No previous kernel version. uBoot images not removed!"   [[ -n ${verbose} ]] && echo "No previous kernel version.  U-Boot images not removed!"
448   fi   fi
449   else   else
450   [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}"   [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not modifying ${ubootDir}"
451   fi   fi
452    
453     if [[ -n ${cfgExtlinux} ]]
454     then
455     [[ -n ${verbose} ]] && echo "removing ${version} from ${extlinuxConfig}"
456     ${grubby} --extlinux -c ${extlinuxConfig} \
457     --remove-kernel=${bootPrefix}/${kernelName}-${version}
458     else
459     [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby for extlinux"
460     fi
461  }  }
462    
463  update()  update()
# Line 403  update() Line 483  update()
483   if [[ -n ${cfgGrub} ]]   if [[ -n ${cfgGrub} ]]
484   then   then
485   [[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}"   [[ -n ${verbose} ]] && echo "updating ${version} from ${grubConfig}"
486   ${grubby} --update-kernel=${bootPrefix}/${kernelName}-${version} \   ${grubby} --grub -c ${grubConfig} \
487     --update-kernel=${bootPrefix}/${kernelName}-${version} \
488   ${INITRD} \   ${INITRD} \
489   ${kernargs:+--args="${kernargs}"} \   ${kernargs:+--args="${kernargs}"} \
490   ${removeargs:+--remove-args="${removeargs}"}   ${removeargs:+--remove-args="${removeargs}"}
# Line 426  update() Line 507  update()
507   if [[ -n ${cfgGrub2Efi} ]]   if [[ -n ${cfgGrub2Efi} ]]
508   then   then
509   [[ -n ${verbose} ]] && echo "updating ${version} from ${grub2EfiConfig}"   [[ -n ${verbose} ]] && echo "updating ${version} from ${grub2EfiConfig}"
510   ${grubby} --grub2 -c ${grub2EfiConfig} \   ${grubby} --grub2 -c ${grub2EfiConfig} --efi \
511   --update-kernel=${bootPrefix}/${kernelName}-${version} \   --update-kernel=${bootPrefix}/${kernelName}-${version} \
512   ${INITRD} \   ${INITRD} \
513   ${kernargs:+--args="${kernargs}"} \   ${kernargs:+--args="${kernargs}"} \
# Line 463  update() Line 544  update()
544   [[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..."   [[ -n ${verbose} ]] && echo "adding $version to ${ubootDir}..."
545    
546   [[ -n ${verbose} ]] && echo "creating uImage-${version}"   [[ -n ${verbose} ]] && echo "creating uImage-${version}"
547   mkimage -A arm -O linux -T kernel -C none -a 0x80008000 -e 0x80008000 \   mkimage -A arm -O linux -T kernel -C none -a ${ubootAddress} \
548   -n ${version} -d ${bootPrefix}/${kernelName}-${version} ${ubootDir}/uImage-${version}   -e ${ubootAddress} -n ${version} \
549     -d ${bootPrefix}/${kernelName}-${version} ${ubootDir}/uImage-${version}
550    
551   [[ -n ${verbose} ]] && echo "creating uInitrd-${version}"   [[ -n ${verbose} ]] && echo "creating uInitrd-${version}"
552   mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 \   mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 \
# Line 489  update() Line 571  update()
571   else   else
572   [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not setting up ${ubootDir}"   [[ -n ${verbose} ]] && echo "${ubootScript} does not exist, not setting up ${ubootDir}"
573   fi   fi
574    
575     if [[ -n ${cfgExtlinux} ]]
576     then
577     [[ -n ${verbose} ]] && echo "updating ${version} from ${extlinuxConfig}"
578     ${grubby} --extlinux -c ${extlinuxConfig} \
579     --update-kernel=${bootPrefix}/${kernelName}-${version} \
580     ${INITRD} \
581     ${kernargs:+--args="${kernargs}"} \
582     ${removeargs:+--remove-args="${removeargs}"}
583     else
584     [[ -n ${verbose} ]] && echo "${extlinuxConfig} does not exist, not running grubby"
585     fi
586  }  }
587    
588  mkinitrd()  makeinitrd()
589  {  {
590   if [[ -n ${dracut} ]]   if [[ -n ${dracut} ]]
591   then   then
592   tool="/sbin/dracut ${dracuthostonly} -f ${initrdfile} ${version}"   tool="dracut ${dracuthostonly} -f ${initrdfile} ${version}"
593   else   else
594   tool="/sbin/mkinitrd --allow-missing -f ${initrdfile} ${version}"   tool="mkinitrd --allow-missing -f ${initrdfile} ${version}"
595   fi   fi
596   [[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}"   [[ -n ${verbose} ]] && echo "creating initrd ${initrdfile} using ${version}"
597   ${tool}   ${tool}
# Line 706  fi Line 800  fi
800  # add dracut i18n, keyboard and plymouth kernel args if requested  # add dracut i18n, keyboard and plymouth kernel args if requested
801  if [[ -n ${dracut} ]] || [[ -n ${adddracutargs} ]]  if [[ -n ${dracut} ]] || [[ -n ${adddracutargs} ]]
802  then  then
803   [ -r /etc/conf.d/keymap ] && . /etc/conf.d/keymap   if [ -r /etc/vconsole.conf ]
  [ -r /etc/conf.d/consolefont ] && . /etc/conf.d/consolefont  
   
  if [[ -n ${KEYMAP} ]]  
804   then   then
805   kernargs="${kernargs} KEYTABLE=${KEYMAP}"   . /etc/vconsole.conf
806    
807     for i in SYSFONT SYSFONTACM UNIMAP KEYTABLE
808     do
809     val=$(eval echo \$$i)
810     [[ -n ${val} ]] && kernargs="${kernargs} ${i}=${val}"
811     done
812     else
813     if [ -r /etc/conf.d/consolefont ]
814     then
815     . /etc/conf.d/consolefont
816    
817     if [[ -n ${CONSOLEFONT} ]]
818     then
819     kernargs="${kernargs} SYSFONT=${CONSOLEFONT}"
820     fi
821     fi
822    
823     if  [ -r /etc/conf.d/keymap ]
824     then
825     . /etc/conf.d/keymap
826    
827     if [[ -n ${KEYMAP} ]]
828     then
829     kernargs="${kernargs} KEYTABLE=${KEYMAP}"
830     fi
831     fi
832   fi   fi
833    
834   if [[ -n ${CONSOLEFONT} ]]   if [ -r /etc/locale.conf ]
835   then   then
836   kernargs="${kernargs} SYSFONT=${CONSOLEFONT}"   . /etc/locale.conf
837    
838     if [[ -n ${LANG} ]]
839     then
840     kernargs="${kernargs} LANG=${LANG}"
841     fi
842   fi   fi
843  fi  fi
844    
# Line 738  fi Line 860  fi
860    
861  if [[ ${initrd} = make ]]  if [[ ${initrd} = make ]]
862  then  then
863   mkinitrd   makeinitrd
864  elif [[ ${initrd} = remove ]]  elif [[ ${initrd} = remove ]]
865  then  then
866   rminitrd   rminitrd
# Line 754  fi Line 876  fi
876  [[ -n ${grub2Config} ]] && [ -f ${grub2Config} ] && cfgGrub2=1  [[ -n ${grub2Config} ]] && [ -f ${grub2Config} ] && cfgGrub2=1
877  [[ -n ${grub2EfiConfig} ]] && [ -f ${grub2EfiConfig} ] && cfgGrub2Efi=1  [[ -n ${grub2EfiConfig} ]] && [ -f ${grub2EfiConfig} ] && cfgGrub2Efi=1
878  [[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1  [[ -n ${liloConfig} ]] && [ -f ${liloConfig} ] && cfgLilo=1
879    [[ -n ${extlinuxConfig} ]] && [ -f ${extlinuxConfig} ] && cfgExtlinux=1
880    
881  # if we have a uBoot directory, check if it is mounted.  # if we have a U-Boot directory, but no boot script, check if the directory
882  # if not, mount it. Then check if a boot script exists.  # is mounted.  If not, mount it, and then check if a boot script exists.
883  if [[ -n ${ubootDir} ]]  if [[ -n ${ubootDir} ]]
884  then  then
885   mountEntry=$(mount | grep ${ubootDir})   if [ -f ${ubootScript} ]
  if [[ -z ${mountEntry} ]]  
886   then   then
887   mount ${ubootDevice} ${ubootDir}   cfguBoot=1
888   mounted=1   else
889     mountEntry=$(mount | grep ${ubootDir})
890     if [[ -z ${mountEntry} ]]
891     then
892     mount ${ubootDevice} ${ubootDir}
893     mounted=1
894     fi
895     [ -f ${ubootScript} ] && cfguBoot=1
896     fi
897    fi
898    
899    # if we're using U-Boot, check if the default load address should change
900    if [[ -n ${cfguBoot} ]] && [[ -z ${UBOOT_IMGADDR} ]]
901    then
902     [[ ${version}  =~ .([^.]*)$ ]]
903     platform=${BASH_REMATCH[1]}
904     # A few platforms use an alternate kernel load address
905     if [[ ${platform} = omap ]]
906     then
907     ubootAddress=0x80008000
908     elif [[ ${platform} = imx ]]
909     then
910     ubootAddress=0x90008000
911   fi   fi
  [ -f ${ubootScript} ] && cfguBoot=1  
912  fi  fi
913    
914  # 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
# Line 786  then Line 929  then
929   update   update
930  fi  fi
931    
932    # if we mounted the U-Boot directory, unmount it.
933    [[ -n ${mounted} ]] && umount ${ubootDir}
934    
935  exit 0  exit 0

Legend:
Removed from v.1702  
changed lines
  Added in v.2237