10_linux.in 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. #! /bin/sh
  2. set -e
  3. # grub-mkconfig helper script.
  4. # Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
  5. #
  6. # GRUB is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # GRUB is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. prefix="@prefix@"
  19. exec_prefix="@exec_prefix@"
  20. datarootdir="@datarootdir@"
  21. . "$pkgdatadir/grub-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. else
  28. OS="${GRUB_DISTRIBUTOR} GNU/Linux"
  29. CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
  30. fi
  31. # loop-AES arranges things so that /dev/loop/X can be our root device, but
  32. # the initrds that Linux uses don't like that.
  33. case ${GRUB_DEVICE} in
  34. /dev/loop/*|/dev/loop[0-9])
  35. GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
  36. ;;
  37. esac
  38. # Default to disabling partition uuid support to maintian compatibility with
  39. # older kernels.
  40. GRUB_DISABLE_LINUX_PARTUUID=${GRUB_DISABLE_LINUX_PARTUUID-true}
  41. # btrfs may reside on multiple devices. We cannot pass them as value of root= parameter
  42. # and mounting btrfs requires user space scanning, so force UUID in this case.
  43. if ( [ "x${GRUB_DEVICE_UUID}" = "x" ] && [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] ) \
  44. || ( [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
  45. && [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ] ) \
  46. || ( ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
  47. && ! test -e "/dev/disk/by-partuuid/${GRUB_DEVICE_PARTUUID}" ) \
  48. || ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then
  49. LINUX_ROOT_DEVICE=${GRUB_DEVICE}
  50. elif [ "x${GRUB_DEVICE_UUID}" = "x" ] \
  51. || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ]; then
  52. LINUX_ROOT_DEVICE=PARTUUID=${GRUB_DEVICE_PARTUUID}
  53. else
  54. LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
  55. fi
  56. case x"$GRUB_FS" in
  57. xbtrfs)
  58. rootsubvol="`make_system_path_relative_to_its_root /`"
  59. rootsubvol="${rootsubvol#/}"
  60. if [ "x${rootsubvol}" != x ]; then
  61. GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
  62. fi;;
  63. xzfs)
  64. rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
  65. bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
  66. LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs%/}"
  67. ;;
  68. esac
  69. title_correction_code=
  70. linux_entry ()
  71. {
  72. os="$1"
  73. version="$2"
  74. type="$3"
  75. args="$4"
  76. if [ -z "$boot_device_id" ]; then
  77. boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  78. fi
  79. if [ x$type != xsimple ] ; then
  80. case $type in
  81. recovery)
  82. title="$(gettext_printf "%s, with Linux %s (recovery mode)" "${os}" "${version}")" ;;
  83. *)
  84. title="$(gettext_printf "%s, with Linux %s" "${os}" "${version}")" ;;
  85. esac
  86. if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
  87. replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
  88. quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
  89. title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
  90. grub_warn "$(gettext_printf "Please don't use old title \`%s' for GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" "gnulinux-advanced-$boot_device_id>gnulinux-$version-$type-$boot_device_id")"
  91. fi
  92. echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  93. else
  94. echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  95. fi
  96. if [ x$type != xrecovery ] ; then
  97. save_default_entry | grub_add_tab
  98. fi
  99. # Use ELILO's generic "efifb" when it's known to be available.
  100. # FIXME: We need an interface to select vesafb in case efifb can't be used.
  101. if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then
  102. echo " load_video" | sed "s/^/$submenu_indentation/"
  103. if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \
  104. && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then
  105. echo " set gfxpayload=keep" | sed "s/^/$submenu_indentation/"
  106. fi
  107. else
  108. if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
  109. echo " load_video" | sed "s/^/$submenu_indentation/"
  110. fi
  111. echo " set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/"
  112. fi
  113. echo " insmod gzio" | sed "s/^/$submenu_indentation/"
  114. if [ x$dirname = x/ ]; then
  115. if [ -z "${prepare_root_cache}" ]; then
  116. prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)"
  117. fi
  118. printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/"
  119. else
  120. if [ -z "${prepare_boot_cache}" ]; then
  121. prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
  122. fi
  123. printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
  124. fi
  125. message="$(gettext_printf "Loading Linux %s ..." ${version})"
  126. sed "s/^/$submenu_indentation/" << EOF
  127. echo '$(echo "$message" | grub_quote)'
  128. linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
  129. EOF
  130. if test -n "${initrd}" ; then
  131. # TRANSLATORS: ramdisk isn't identifier. Should be translated.
  132. message="$(gettext_printf "Loading initial ramdisk ...")"
  133. initrd_path=
  134. for i in ${initrd}; do
  135. initrd_path="${initrd_path} ${rel_dirname}/${i}"
  136. done
  137. sed "s/^/$submenu_indentation/" << EOF
  138. echo '$(echo "$message" | grub_quote)'
  139. initrd $(echo $initrd_path)
  140. EOF
  141. fi
  142. sed "s/^/$submenu_indentation/" << EOF
  143. }
  144. EOF
  145. }
  146. machine=`uname -m`
  147. case "x$machine" in
  148. xi?86 | xx86_64)
  149. list=
  150. for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
  151. if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
  152. done ;;
  153. *)
  154. list=
  155. for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
  156. if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
  157. done ;;
  158. esac
  159. case "$machine" in
  160. i?86) GENKERNEL_ARCH="x86" ;;
  161. mips|mips64) GENKERNEL_ARCH="mips" ;;
  162. mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
  163. arm*) GENKERNEL_ARCH="arm" ;;
  164. *) GENKERNEL_ARCH="$machine" ;;
  165. esac
  166. prepare_boot_cache=
  167. prepare_root_cache=
  168. boot_device_id=
  169. title_correction_code=
  170. # Extra indentation to add to menu entries in a submenu. We're not in a submenu
  171. # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
  172. submenu_indentation=""
  173. is_top_level=true
  174. while [ "x$list" != "x" ] ; do
  175. linux=`version_find_latest $list`
  176. gettext_printf "Found linux image: %s\n" "$linux" >&2
  177. basename=`basename $linux`
  178. dirname=`dirname $linux`
  179. rel_dirname=`make_system_path_relative_to_its_root $dirname`
  180. version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
  181. alt_version=`echo $version | sed -e "s,\.old$,,g"`
  182. linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
  183. initrd_early=
  184. for i in ${GRUB_EARLY_INITRD_LINUX_STOCK} \
  185. ${GRUB_EARLY_INITRD_LINUX_CUSTOM}; do
  186. if test -e "${dirname}/${i}" ; then
  187. initrd_early="${initrd_early} ${i}"
  188. fi
  189. done
  190. initrd_real=
  191. for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
  192. "initrd-${version}" "initramfs-${version}.img" \
  193. "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
  194. "initrd-${alt_version}" "initramfs-${alt_version}.img" \
  195. "initramfs-genkernel-${version}" \
  196. "initramfs-genkernel-${alt_version}" \
  197. "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
  198. "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do
  199. if test -e "${dirname}/${i}" ; then
  200. initrd_real="${i}"
  201. break
  202. fi
  203. done
  204. initrd=
  205. if test -n "${initrd_early}" || test -n "${initrd_real}"; then
  206. initrd="${initrd_early} ${initrd_real}"
  207. initrd_display=
  208. for i in ${initrd}; do
  209. initrd_display="${initrd_display} ${dirname}/${i}"
  210. done
  211. gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2
  212. fi
  213. config=
  214. for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
  215. if test -e "${i}" ; then
  216. config="${i}"
  217. break
  218. fi
  219. done
  220. initramfs=
  221. if test -n "${config}" ; then
  222. initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
  223. fi
  224. if test -z "${initramfs}" && test -z "${initrd_real}" ; then
  225. # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs. Since there's
  226. # no initrd or builtin initramfs, it can't work here.
  227. if [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] \
  228. || [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ]; then
  229. linux_root_device_thisversion=${GRUB_DEVICE}
  230. else
  231. linux_root_device_thisversion=PARTUUID=${GRUB_DEVICE_PARTUUID}
  232. fi
  233. fi
  234. # The GRUB_DISABLE_SUBMENU option used to be different than others since it was
  235. # mentioned in the documentation that has to be set to 'y' instead of 'true' to
  236. # enable it. This caused a lot of confusion to users that set the option to 'y',
  237. # 'yes' or 'true'. This was fixed but all of these values must be supported now.
  238. if [ "x${GRUB_DISABLE_SUBMENU}" = xyes ] || [ "x${GRUB_DISABLE_SUBMENU}" = xy ]; then
  239. GRUB_DISABLE_SUBMENU="true"
  240. fi
  241. if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then
  242. linux_entry "${OS}" "${version}" simple \
  243. "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  244. submenu_indentation="$grub_tab"
  245. if [ -z "$boot_device_id" ]; then
  246. boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  247. fi
  248. # TRANSLATORS: %s is replaced with an OS name
  249. echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
  250. is_top_level=false
  251. fi
  252. linux_entry "${OS}" "${version}" advanced \
  253. "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  254. if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
  255. linux_entry "${OS}" "${version}" recovery \
  256. "single ${GRUB_CMDLINE_LINUX}"
  257. fi
  258. list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
  259. done
  260. # If at least one kernel was found, then we need to
  261. # add a closing '}' for the submenu command.
  262. if [ x"$is_top_level" != xtrue ]; then
  263. echo '}'
  264. fi
  265. echo "$title_correction_code"