20_linux_xen.in 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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 --class xen"
  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. # 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. # Allow overriding GRUB_CMDLINE_LINUX and GRUB_CMDLINE_LINUX_DEFAULT.
  48. if [ "${GRUB_CMDLINE_LINUX_XEN_REPLACE}" ]; then
  49. GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX_XEN_REPLACE}"
  50. fi
  51. if [ "${GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT}" ]; then
  52. GRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT}"
  53. fi
  54. case x"$GRUB_FS" in
  55. xbtrfs)
  56. rootsubvol="`make_system_path_relative_to_its_root /`"
  57. rootsubvol="${rootsubvol#/}"
  58. if [ "x${rootsubvol}" != x ]; then
  59. GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
  60. fi;;
  61. xzfs)
  62. rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
  63. bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
  64. LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
  65. ;;
  66. esac
  67. title_correction_code=
  68. linux_entry ()
  69. {
  70. os="$1"
  71. version="$2"
  72. xen_version="$3"
  73. type="$4"
  74. args="$5"
  75. xen_args="$6"
  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. if [ x$type = xrecovery ] ; then
  81. title="$(gettext_printf "%s, with Xen %s and Linux %s (recovery mode)" "${os}" "${xen_version}" "${version}")"
  82. else
  83. title="$(gettext_printf "%s, with Xen %s and Linux %s" "${os}" "${xen_version}" "${version}")"
  84. fi
  85. replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
  86. if [ x"Xen ${xen_version}>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
  87. quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
  88. title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
  89. 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")"
  90. fi
  91. echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'xen-gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  92. else
  93. title="$(gettext_printf "%s, with Xen hypervisor" "${os}")"
  94. echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'xen-gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  95. fi
  96. if [ x$type != xrecovery ] ; then
  97. save_default_entry | grub_add_tab | sed "s/^/$submenu_indentation/"
  98. fi
  99. if [ -z "${prepare_boot_cache}" ]; then
  100. prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
  101. fi
  102. printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
  103. xmessage="$(gettext_printf "Loading Xen %s ..." ${xen_version})"
  104. lmessage="$(gettext_printf "Loading Linux %s ..." ${version})"
  105. sed "s/^/$submenu_indentation/" << EOF
  106. echo '$(echo "$xmessage" | grub_quote)'
  107. if [ "\$grub_platform" = "pc" -o "\$grub_platform" = "" ]; then
  108. xen_rm_opts=
  109. else
  110. xen_rm_opts="no-real-mode edd=off"
  111. fi
  112. multiboot ${rel_xen_dirname}/${xen_basename} placeholder ${xen_args} \${xen_rm_opts}
  113. echo '$(echo "$lmessage" | grub_quote)'
  114. module ${rel_dirname}/${basename} placeholder root=${linux_root_device_thisversion} ro ${args}
  115. EOF
  116. if test -n "${initrd}" ; then
  117. # TRANSLATORS: ramdisk isn't identifier. Should be translated.
  118. message="$(gettext_printf "Loading initial ramdisk ...")"
  119. sed "s/^/$submenu_indentation/" << EOF
  120. echo '$(echo "$message" | grub_quote)'
  121. module --nounzip ${rel_dirname}/${initrd}
  122. EOF
  123. fi
  124. sed "s/^/$submenu_indentation/" << EOF
  125. }
  126. EOF
  127. }
  128. linux_list=
  129. for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* /boot/kernel-*; do
  130. if grub_file_is_not_garbage "$i"; then
  131. basename=$(basename $i)
  132. version=$(echo $basename | sed -e "s,^[^0-9]*-,,g")
  133. dirname=$(dirname $i)
  134. config=
  135. for j in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
  136. if test -e "${j}" ; then
  137. config="${j}"
  138. break
  139. fi
  140. done
  141. if (grep -qx "CONFIG_XEN_DOM0=y" "${config}" 2> /dev/null || grep -qx "CONFIG_XEN_PRIVILEGED_GUEST=y" "${config}" 2> /dev/null); then linux_list="$linux_list $i" ; fi
  142. fi
  143. done
  144. if [ "x${linux_list}" = "x" ] ; then
  145. exit 0
  146. fi
  147. file_is_not_sym () {
  148. case "$1" in
  149. */xen-syms-*)
  150. return 1;;
  151. *)
  152. return 0;;
  153. esac
  154. }
  155. xen_list=
  156. for i in /boot/xen*; do
  157. if grub_file_is_not_garbage "$i" && file_is_not_sym "$i" ; then xen_list="$xen_list $i" ; fi
  158. done
  159. prepare_boot_cache=
  160. boot_device_id=
  161. title_correction_code=
  162. machine=`uname -m`
  163. case "$machine" in
  164. i?86) GENKERNEL_ARCH="x86" ;;
  165. mips|mips64) GENKERNEL_ARCH="mips" ;;
  166. mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
  167. arm*) GENKERNEL_ARCH="arm" ;;
  168. *) GENKERNEL_ARCH="$machine" ;;
  169. esac
  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${xen_list}" != "x" ] ; do
  175. list="${linux_list}"
  176. current_xen=`version_find_latest $xen_list`
  177. xen_basename=`basename ${current_xen}`
  178. xen_dirname=`dirname ${current_xen}`
  179. rel_xen_dirname=`make_system_path_relative_to_its_root $xen_dirname`
  180. xen_version=`echo $xen_basename | sed -e "s,.gz$,,g;s,^xen-,,g"`
  181. if [ -z "$boot_device_id" ]; then
  182. boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  183. fi
  184. if [ "x$is_top_level" != xtrue ]; then
  185. echo " submenu '$(gettext_printf "Xen hypervisor, version %s" "${xen_version}" | grub_quote)' \$menuentry_id_option 'xen-hypervisor-$xen_version-$boot_device_id' {"
  186. fi
  187. while [ "x$list" != "x" ] ; do
  188. linux=`version_find_latest $list`
  189. gettext_printf "Found linux image: %s\n" "$linux" >&2
  190. basename=`basename $linux`
  191. dirname=`dirname $linux`
  192. rel_dirname=`make_system_path_relative_to_its_root $dirname`
  193. version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
  194. alt_version=`echo $version | sed -e "s,\.old$,,g"`
  195. linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
  196. initrd=
  197. for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
  198. "initrd-${version}" "initramfs-${version}.img" \
  199. "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
  200. "initrd-${alt_version}" "initramfs-${alt_version}.img" \
  201. "initramfs-genkernel-${version}" \
  202. "initramfs-genkernel-${alt_version}" \
  203. "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
  204. "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}" ; do
  205. if test -e "${dirname}/${i}" ; then
  206. initrd="$i"
  207. break
  208. fi
  209. done
  210. if test -n "${initrd}" ; then
  211. gettext_printf "Found initrd image: %s\n" "${dirname}/${initrd}" >&2
  212. else
  213. # "UUID=" magic is parsed by initrds. Since there's no initrd, it can't work here.
  214. linux_root_device_thisversion=${GRUB_DEVICE}
  215. fi
  216. if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then
  217. linux_entry "${OS}" "${version}" "${xen_version}" simple \
  218. "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}"
  219. submenu_indentation="$grub_tab$grub_tab"
  220. if [ -z "$boot_device_id" ]; then
  221. boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  222. fi
  223. # TRANSLATORS: %s is replaced with an OS name
  224. echo "submenu '$(gettext_printf "Advanced options for %s (with Xen hypervisor)" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
  225. echo " submenu '$(gettext_printf "Xen hypervisor, version %s" "${xen_version}" | grub_quote)' \$menuentry_id_option 'xen-hypervisor-$xen_version-$boot_device_id' {"
  226. is_top_level=false
  227. fi
  228. linux_entry "${OS}" "${version}" "${xen_version}" advanced \
  229. "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}"
  230. if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
  231. linux_entry "${OS}" "${version}" "${xen_version}" recovery \
  232. "single ${GRUB_CMDLINE_LINUX}" "${GRUB_CMDLINE_XEN}"
  233. fi
  234. list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
  235. done
  236. if [ x"$is_top_level" != xtrue ]; then
  237. echo ' }'
  238. fi
  239. xen_list=`echo $xen_list | tr ' ' '\n' | fgrep -vx "$current_xen" | tr '\n' ' '`
  240. done
  241. # If at least one kernel was found, then we need to
  242. # add a closing '}' for the submenu command.
  243. if [ x"$is_top_level" != xtrue ]; then
  244. echo '}'
  245. fi
  246. echo "$title_correction_code"