10_linux.in 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. : ${GRUB_CMDLINE_LINUX_RECOVERY:=single}
  39. # Default to disabling partition uuid support to maintian compatibility with
  40. # older kernels.
  41. : ${GRUB_DISABLE_LINUX_PARTUUID=true}
  42. # btrfs may reside on multiple devices. We cannot pass them as value of root= parameter
  43. # and mounting btrfs requires user space scanning, so force UUID in this case.
  44. if ( [ "x${GRUB_DEVICE_UUID}" = "x" ] && [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] ) \
  45. || ( [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
  46. && [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ] ) \
  47. || ( ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
  48. && ! test -e "/dev/disk/by-partuuid/${GRUB_DEVICE_PARTUUID}" ) \
  49. || ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then
  50. LINUX_ROOT_DEVICE=${GRUB_DEVICE}
  51. elif [ "x${GRUB_DEVICE_UUID}" = "x" ] \
  52. || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ]; then
  53. LINUX_ROOT_DEVICE=PARTUUID=${GRUB_DEVICE_PARTUUID}
  54. else
  55. LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
  56. fi
  57. case x"$GRUB_FS" in
  58. xbtrfs)
  59. rootsubvol="`make_system_path_relative_to_its_root /`"
  60. rootsubvol="${rootsubvol#/}"
  61. if [ "x${rootsubvol}" != x ]; then
  62. GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
  63. fi;;
  64. xzfs)
  65. rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
  66. bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
  67. LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs%/}"
  68. ;;
  69. esac
  70. title_correction_code=
  71. linux_entry ()
  72. {
  73. os="$1"
  74. version="$2"
  75. type="$3"
  76. args="$4"
  77. if [ -z "$boot_device_id" ]; then
  78. boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  79. fi
  80. if [ x$type != xsimple ] ; then
  81. case $type in
  82. recovery)
  83. title="$(gettext_printf "%s, with Linux %s (recovery mode)" "${os}" "${version}")" ;;
  84. *)
  85. title="$(gettext_printf "%s, with Linux %s" "${os}" "${version}")" ;;
  86. esac
  87. if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
  88. replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
  89. quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
  90. title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
  91. 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")"
  92. fi
  93. echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  94. else
  95. echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  96. fi
  97. if [ x$type != xrecovery ] ; then
  98. save_default_entry | grub_add_tab
  99. fi
  100. # Use ELILO's generic "efifb" when it's known to be available.
  101. # FIXME: We need an interface to select vesafb in case efifb can't be used.
  102. if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then
  103. echo " load_video" | sed "s/^/$submenu_indentation/"
  104. if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \
  105. && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then
  106. echo " set gfxpayload=keep" | sed "s/^/$submenu_indentation/"
  107. fi
  108. else
  109. if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
  110. echo " load_video" | sed "s/^/$submenu_indentation/"
  111. fi
  112. echo " set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/"
  113. fi
  114. echo " insmod gzio" | sed "s/^/$submenu_indentation/"
  115. if [ x$dirname = x/ ]; then
  116. if [ -z "${prepare_root_cache}" ]; then
  117. prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)"
  118. fi
  119. printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/"
  120. else
  121. if [ -z "${prepare_boot_cache}" ]; then
  122. prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
  123. fi
  124. printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
  125. fi
  126. message="$(gettext_printf "Loading Linux %s ..." ${version})"
  127. sed "s/^/$submenu_indentation/" << EOF
  128. echo '$(echo "$message" | grub_quote)'
  129. linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
  130. EOF
  131. if test -n "${initrd}" ; then
  132. # TRANSLATORS: ramdisk isn't identifier. Should be translated.
  133. message="$(gettext_printf "Loading initial ramdisk ...")"
  134. initrd_path=
  135. for i in ${initrd}; do
  136. initrd_path="${initrd_path} ${rel_dirname}/${i}"
  137. done
  138. sed "s/^/$submenu_indentation/" << EOF
  139. echo '$(echo "$message" | grub_quote)'
  140. initrd $(echo $initrd_path)
  141. EOF
  142. fi
  143. sed "s/^/$submenu_indentation/" << EOF
  144. }
  145. EOF
  146. }
  147. machine=`uname -m`
  148. case "x$machine" in
  149. xi?86 | xx86_64)
  150. list=
  151. for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
  152. if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
  153. done ;;
  154. *)
  155. list=
  156. for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
  157. if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
  158. done ;;
  159. esac
  160. case "$machine" in
  161. i?86) GENKERNEL_ARCH="x86" ;;
  162. mips|mips64) GENKERNEL_ARCH="mips" ;;
  163. mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
  164. arm*) GENKERNEL_ARCH="arm" ;;
  165. *) GENKERNEL_ARCH="$machine" ;;
  166. esac
  167. prepare_boot_cache=
  168. prepare_root_cache=
  169. boot_device_id=
  170. title_correction_code=
  171. # Extra indentation to add to menu entries in a submenu. We're not in a submenu
  172. # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
  173. submenu_indentation=""
  174. # Perform a reverse version sort on the entire list.
  175. # Temporarily replace the '.old' suffix by ' 1' and append ' 2' for all
  176. # other files to order the '.old' files after their non-old counterpart
  177. # in reverse-sorted order.
  178. reverse_sorted_list=$(echo $list | tr ' ' '\n' | sed -e 's/\.old$/ 1/; / 1$/! s/$/ 2/' | version_sort -r | sed -e 's/ 1$/.old/; s/ 2$//')
  179. if [ "x$GRUB_TOP_LEVEL" != x ]; then
  180. reverse_sorted_list=$(grub_move_to_front "$GRUB_TOP_LEVEL" ${reverse_sorted_list})
  181. fi
  182. is_top_level=true
  183. for linux in ${reverse_sorted_list}; do
  184. gettext_printf "Found linux image: %s\n" "$linux" >&2
  185. basename=`basename $linux`
  186. dirname=`dirname $linux`
  187. rel_dirname=`make_system_path_relative_to_its_root $dirname`
  188. version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
  189. alt_version=`echo $version | sed -e "s,\.old$,,g"`
  190. linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
  191. initrd_early=
  192. for i in ${GRUB_EARLY_INITRD_LINUX_STOCK} \
  193. ${GRUB_EARLY_INITRD_LINUX_CUSTOM}; do
  194. if test -e "${dirname}/${i}" ; then
  195. initrd_early="${initrd_early} ${i}"
  196. fi
  197. done
  198. initrd_real=
  199. for i in "initrd.img-${version}" "initrd-${version}.img" \
  200. "initrd-${alt_version}.img.old" "initrd-${version}.gz" \
  201. "initrd-${alt_version}.gz.old" "initrd-${version}" \
  202. "initramfs-${version}.img" "initramfs-${alt_version}.img.old" \
  203. "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
  204. "initrd-${alt_version}" "initramfs-${alt_version}.img" \
  205. "initramfs-genkernel-${version}" \
  206. "initramfs-genkernel-${alt_version}" \
  207. "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
  208. "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do
  209. if test -e "${dirname}/${i}" ; then
  210. initrd_real="${i}"
  211. break
  212. fi
  213. done
  214. initrd=
  215. if test -n "${initrd_early}" || test -n "${initrd_real}"; then
  216. initrd="${initrd_early} ${initrd_real}"
  217. initrd_display=
  218. for i in ${initrd}; do
  219. initrd_display="${initrd_display} ${dirname}/${i}"
  220. done
  221. gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2
  222. fi
  223. config=
  224. for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
  225. if test -e "${i}" ; then
  226. config="${i}"
  227. break
  228. fi
  229. done
  230. initramfs=
  231. if test -n "${config}" ; then
  232. initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
  233. fi
  234. if test -z "${initramfs}" && test -z "${initrd_real}" ; then
  235. # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs. Since there's
  236. # no initrd or builtin initramfs, it can't work here.
  237. if [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] \
  238. || [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ]; then
  239. linux_root_device_thisversion=${GRUB_DEVICE}
  240. else
  241. linux_root_device_thisversion=PARTUUID=${GRUB_DEVICE_PARTUUID}
  242. fi
  243. fi
  244. # The GRUB_DISABLE_SUBMENU option used to be different than others since it was
  245. # mentioned in the documentation that has to be set to 'y' instead of 'true' to
  246. # enable it. This caused a lot of confusion to users that set the option to 'y',
  247. # 'yes' or 'true'. This was fixed but all of these values must be supported now.
  248. if [ "x${GRUB_DISABLE_SUBMENU}" = xyes ] || [ "x${GRUB_DISABLE_SUBMENU}" = xy ]; then
  249. GRUB_DISABLE_SUBMENU="true"
  250. fi
  251. if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then
  252. linux_entry "${OS}" "${version}" simple \
  253. "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  254. submenu_indentation="$grub_tab"
  255. if [ -z "$boot_device_id" ]; then
  256. boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  257. fi
  258. # TRANSLATORS: %s is replaced with an OS name
  259. echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
  260. is_top_level=false
  261. fi
  262. linux_entry "${OS}" "${version}" advanced \
  263. "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  264. if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
  265. linux_entry "${OS}" "${version}" recovery \
  266. "${GRUB_CMDLINE_LINUX_RECOVERY} ${GRUB_CMDLINE_LINUX}"
  267. fi
  268. done
  269. # If at least one kernel was found, then we need to
  270. # add a closing '}' for the submenu command.
  271. if [ x"$is_top_level" != xtrue ]; then
  272. echo '}'
  273. fi
  274. echo "$title_correction_code"