10_linux 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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="/usr"
  19. exec_prefix="/usr"
  20. datarootdir="/usr/share"
  21. . "$pkgdatadir/grub-mkconfig_lib"
  22. . /etc/default/grub/grub.default
  23. export TEXTDOMAIN=grub
  24. export TEXTDOMAINDIR="${datarootdir}/locale"
  25. DAGITIM=`lsb_release -i -s`
  26. CODENAME=`lsb_release -c -s`
  27. VERSION=`lsb_release -r -s`
  28. GRUB_DISTRIBUTOR="$DAGITIM $VERSION $CODENAME"
  29. OS="${GRUB_DISTRIBUTOR} GNU/Linux"
  30. CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') --class gnu-linux --class gnu --class os"
  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. # btrfs may reside on multiple devices. We cannot pass them as value of root= parameter
  39. # and mounting btrfs requires user space scanning, so force UUID in this case.
  40. if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
  41. || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
  42. || test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm; then
  43. LINUX_ROOT_DEVICE=${GRUB_DEVICE}
  44. else
  45. LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
  46. fi
  47. case x"$GRUB_FS" in
  48. xbtrfs)
  49. rootsubvol="`make_system_path_relative_to_its_root /`"
  50. rootsubvol="${rootsubvol#/}"
  51. if [ "x${rootsubvol}" != x ]; then
  52. GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
  53. fi;;
  54. xzfs)
  55. rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
  56. bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
  57. LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
  58. ;;
  59. esac
  60. title_correction_code=
  61. linux_entry ()
  62. {
  63. os="$1"
  64. version="$2"
  65. type="$3"
  66. args="$4"
  67. if [ -z "$boot_device_id" ]; then
  68. boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  69. fi
  70. if [ x$type != xsimple ] ; then
  71. case $type in
  72. recovery)
  73. title="$(gettext_printf "%s, with Linux %s (recovery mode)" "${os}" "${version}")" ;;
  74. *)
  75. title="$(gettext_printf "%s, with Linux %s" "${os}" "${version}")" ;;
  76. esac
  77. if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
  78. replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
  79. quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
  80. title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
  81. 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")"
  82. fi
  83. echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  84. else
  85. echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  86. fi
  87. if [ x$type != xrecovery ] ; then
  88. save_default_entry | grub_add_tab
  89. fi
  90. # Use ELILO's generic "efifb" when it's known to be available.
  91. # FIXME: We need an interface to select vesafb in case efifb can't be used.
  92. if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then
  93. echo " load_video" | sed "s/^/$submenu_indentation/"
  94. if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \
  95. && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then
  96. echo " set gfxpayload=keep" | sed "s/^/$submenu_indentation/"
  97. fi
  98. else
  99. if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
  100. echo " load_video" | sed "s/^/$submenu_indentation/"
  101. fi
  102. echo " set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/"
  103. fi
  104. echo " insmod gzio" | sed "s/^/$submenu_indentation/"
  105. if [ x$dirname = x/ ]; then
  106. if [ -z "${prepare_root_cache}" ]; then
  107. prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)"
  108. fi
  109. printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/"
  110. else
  111. if [ -z "${prepare_boot_cache}" ]; then
  112. prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
  113. fi
  114. printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
  115. fi
  116. message="$(gettext_printf "Loading Linux %s ..." ${version})"
  117. sed "s/^/$submenu_indentation/" << EOF
  118. echo '$(echo "$message" | grub_quote)'
  119. linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
  120. EOF
  121. if test -n "${initrd}" ; then
  122. # TRANSLATORS: ramdisk isn't identifier. Should be translated.
  123. message="$(gettext_printf "Loading initial ramdisk ...")"
  124. sed "s/^/$submenu_indentation/" << EOF
  125. echo '$(echo "$message" | grub_quote)'
  126. initrd ${rel_dirname}/${initrd}
  127. EOF
  128. fi
  129. sed "s/^/$submenu_indentation/" << EOF
  130. }
  131. EOF
  132. }
  133. machine=`uname -m`
  134. case "x$machine" in
  135. xi?86 | xx86_64)
  136. list=
  137. for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
  138. if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
  139. done ;;
  140. *)
  141. list=
  142. for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
  143. if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
  144. done ;;
  145. esac
  146. case "$machine" in
  147. i?86) GENKERNEL_ARCH="x86" ;;
  148. mips|mips64) GENKERNEL_ARCH="mips" ;;
  149. mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
  150. arm*) GENKERNEL_ARCH="arm" ;;
  151. *) GENKERNEL_ARCH="$machine" ;;
  152. esac
  153. prepare_boot_cache=
  154. prepare_root_cache=
  155. boot_device_id=
  156. title_correction_code=
  157. # Extra indentation to add to menu entries in a submenu. We're not in a submenu
  158. # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
  159. submenu_indentation=""
  160. is_top_level=true
  161. while [ "x$list" != "x" ] ; do
  162. linux=`version_find_latest $list`
  163. gettext_printf "Found linux image: %s\n" "$linux" >&2
  164. basename=`basename $linux`
  165. dirname=`dirname $linux`
  166. rel_dirname=`make_system_path_relative_to_its_root $dirname`
  167. version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
  168. alt_version=`echo $version | sed -e "s,\.old$,,g"`
  169. linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
  170. initrd=
  171. for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
  172. "initrd-${version}" "initramfs-${version}.img" \
  173. "initramfs-${version}.gz" \
  174. "initramfs" \
  175. "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
  176. "initrd-${alt_version}" "initramfs-${alt_version}.img" \
  177. "initramfs-genkernel-${version}" \
  178. "initramfs-genkernel-${alt_version}" \
  179. "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
  180. "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do
  181. if test -e "${dirname}/${i}" ; then
  182. initrd="$i"
  183. break
  184. fi
  185. done
  186. config=
  187. for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
  188. if test -e "${i}" ; then
  189. config="${i}"
  190. break
  191. fi
  192. done
  193. initramfs=
  194. if test -n "${config}" ; then
  195. initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
  196. fi
  197. if test -n "${initrd}" ; then
  198. gettext_printf "Found initrd image: %s\n" "${dirname}/${initrd}" >&2
  199. elif test -z "${initramfs}" ; then
  200. # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs. Since there's
  201. # no initrd or builtin initramfs, it can't work here.
  202. linux_root_device_thisversion=${GRUB_DEVICE}
  203. fi
  204. if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then
  205. linux_entry "${OS}" "${version}" simple \
  206. "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  207. submenu_indentation="$grub_tab"
  208. if [ -z "$boot_device_id" ]; then
  209. boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  210. fi
  211. # TRANSLATORS: %s is replaced with an OS name
  212. echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
  213. is_top_level=false
  214. fi
  215. linux_entry "${OS}" "${version}" advanced \
  216. "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  217. if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
  218. linux_entry "${OS}" "${version}" recovery \
  219. "single ${GRUB_CMDLINE_LINUX}"
  220. fi
  221. list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
  222. done
  223. # If at least one kernel was found, then we need to
  224. # add a closing '}' for the submenu command.
  225. if [ x"$is_top_level" != xtrue ]; then
  226. echo '}'
  227. fi
  228. echo "$title_correction_code"