10_linux.in 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #! /bin/sh -e
  2. # grub-mkconfig helper script.
  3. # Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
  4. #
  5. # GRUB is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # GRUB is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. prefix=@prefix@
  18. exec_prefix=@exec_prefix@
  19. bindir=@bindir@
  20. libdir=@libdir@
  21. . ${libdir}/burg/burg-mkconfig_lib
  22. export TEXTDOMAIN=@PACKAGE@
  23. export TEXTDOMAINDIR=@localedir@
  24. CLASS="--class gnu-linux --class gnu --class os"
  25. if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
  26. OS=GNU/Linux
  27. OSLABEL=linux
  28. else
  29. OS="${GRUB_DISTRIBUTOR} GNU/Linux"
  30. OSLABEL="$(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]' | cut -d' ' -f1)"
  31. fi
  32. CLASS="--class ${OSLABEL} ${CLASS}"
  33. export AUTH_NORMAL AUTH_RESCUE
  34. get_auth_option ${OSLABEL}
  35. # loop-AES arranges things so that /dev/loop/X can be our root device, but
  36. # the initrds that Linux uses don't like that.
  37. case ${GRUB_DEVICE} in
  38. /dev/loop/*|/dev/loop[0-9])
  39. GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
  40. ;;
  41. esac
  42. if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
  43. || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" ; then
  44. LINUX_ROOT_DEVICE=${GRUB_DEVICE}
  45. else
  46. LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
  47. fi
  48. linux_entry ()
  49. {
  50. os="$1"
  51. version="$2"
  52. recovery="$3"
  53. args="$4"
  54. if ${recovery} ; then
  55. title="$(gettext_quoted "%s, with Linux %s (recovery mode)")"
  56. auth_option=${AUTH_RESCUE}
  57. else
  58. title="$(gettext_quoted "%s, with Linux %s")"
  59. auth_option=${AUTH_NORMAL}
  60. fi
  61. printf "menuentry '${title}' ${CLASS} --group group_main ${auth_option}{\n" "${os}" "${version}"
  62. save_default_entry | sed -e "s/^/\t/"
  63. # Use ELILO's generic "efifb" when it's known to be available.
  64. # FIXME: We need an interface to select vesafb in case efifb can't be used.
  65. if [ "x$GRUB_GFXPAYLOAD_LINUX" != x ]; then
  66. # if grep -qx "CONFIG_FB_EFI=y" /boot/config-${version} 2> /dev/null \
  67. # && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" /boot/config-${version} 2> /dev/null; then
  68. # cat << EOF
  69. # set gfxpayload=keep
  70. #EOF
  71. # fi
  72. # else
  73. cat << EOF
  74. set gfxpayload=$GRUB_GFXPAYLOAD_LINUX
  75. EOF
  76. fi
  77. if [ -z "${prepare_boot_cache}" ]; then
  78. prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
  79. fi
  80. printf '%s\n' "${prepare_boot_cache}"
  81. cat << EOF
  82. echo '$(printf "$(gettext_quoted "Loading Linux %s ...")" ${version})'
  83. linux${GRUB_LINUX16} ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
  84. EOF
  85. if test -n "${initrd}" ; then
  86. cat << EOF
  87. echo '$(gettext_quoted "Loading initial ramdisk ...")'
  88. initrd${GRUB_LINUX16} ${rel_dirname}/${initrd}
  89. EOF
  90. fi
  91. cat << EOF
  92. }
  93. EOF
  94. }
  95. list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* ; do
  96. if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
  97. done`
  98. prepare_boot_cache=
  99. while [ "x$list" != "x" ] ; do
  100. linux=`version_find_latest $list`
  101. echo "Found linux image: $linux" >&2
  102. basename=`basename $linux`
  103. dirname=`dirname $linux`
  104. rel_dirname=`make_system_path_relative_to_its_root $dirname`
  105. version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
  106. alt_version=`echo $version | sed -e "s,\.old$,,g"`
  107. linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
  108. initrd=
  109. for i in "initrd.img-${version}" "initrd-${version}.img" \
  110. "initrd-${version}" "initramfs-${version}.img" \
  111. "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
  112. "initrd-${alt_version}" "initramfs-${alt_version}.img"; do
  113. if test -e "${dirname}/${i}" ; then
  114. initrd="$i"
  115. break
  116. fi
  117. done
  118. if test -n "${initrd}" ; then
  119. echo "Found initrd image: ${dirname}/${initrd}" >&2
  120. else
  121. # "UUID=" magic is parsed by initrds. Since there's no initrd, it can't work here.
  122. linux_root_device_thisversion=${GRUB_DEVICE}
  123. fi
  124. linux_entry "${OS}" "${version}" false \
  125. "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  126. if [ "x${GRUB_DISABLE_LINUX_RECOVERY}" != "xtrue" ]; then
  127. linux_entry "${OS}" "${version}" true \
  128. "single ${GRUB_CMDLINE_LINUX}"
  129. fi
  130. list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
  131. done