30_os-prober.in 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. #! /bin/sh
  2. set -e
  3. # grub-mkconfig helper script.
  4. # Copyright (C) 2006,2007,2008,2009 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. export TEXTDOMAIN=@PACKAGE@
  22. export TEXTDOMAINDIR="@localedir@"
  23. . "$pkgdatadir/grub-mkconfig_lib"
  24. if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then
  25. exit 0
  26. fi
  27. if [ -z "`which os-prober 2> /dev/null`" ] || [ -z "`which linux-boot-prober 2> /dev/null`" ] ; then
  28. # missing os-prober and/or linux-boot-prober
  29. exit 0
  30. fi
  31. OSPROBED="`os-prober | tr ' ' '^' | paste -s -d ' '`"
  32. if [ -z "${OSPROBED}" ] ; then
  33. # empty os-prober output, nothing doing
  34. exit 0
  35. fi
  36. osx_entry() {
  37. if [ x$2 = x32 ]; then
  38. # TRANSLATORS: it refers to kernel architecture (32-bit)
  39. bitstr="$(gettext "(32-bit)")"
  40. else
  41. # TRANSLATORS: it refers to kernel architecture (64-bit)
  42. bitstr="$(gettext "(64-bit)")"
  43. fi
  44. # TRANSLATORS: it refers on the OS residing on device %s
  45. onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
  46. cat << EOF
  47. menuentry '$(echo "${LONGNAME} $bitstr $onstr" | grub_quote)' --class osx --class darwin --class os \$menuentry_id_option 'osprober-xnu-$2-$(grub_get_device_id "${DEVICE}")' {
  48. EOF
  49. save_default_entry | grub_add_tab
  50. prepare_grub_to_access_device ${DEVICE} | grub_add_tab
  51. cat << EOF
  52. load_video
  53. set do_resume=0
  54. if [ /var/vm/sleepimage -nt10 / ]; then
  55. if xnu_resume /var/vm/sleepimage; then
  56. set do_resume=1
  57. fi
  58. fi
  59. if [ \$do_resume = 0 ]; then
  60. xnu_uuid ${OSXUUID} uuid
  61. if [ -f /Extra/DSDT.aml ]; then
  62. acpi -e /Extra/DSDT.aml
  63. fi
  64. if [ /kernelcache -nt /System/Library/Extensions ]; then
  65. $1 /kernelcache boot-uuid=\${uuid} rd=*uuid
  66. elif [ -f /System/Library/Kernels/kernel ]; then
  67. $1 /System/Library/Kernels/kernel boot-uuid=\${uuid} rd=*uuid
  68. xnu_kextdir /System/Library/Extensions
  69. else
  70. $1 /mach_kernel boot-uuid=\${uuid} rd=*uuid
  71. if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then
  72. xnu_mkext /System/Library/Extensions.mkext
  73. else
  74. xnu_kextdir /System/Library/Extensions
  75. fi
  76. fi
  77. if [ -f /Extra/Extensions.mkext ]; then
  78. xnu_mkext /Extra/Extensions.mkext
  79. fi
  80. if [ -d /Extra/Extensions ]; then
  81. xnu_kextdir /Extra/Extensions
  82. fi
  83. if [ -f /Extra/devprop.bin ]; then
  84. xnu_devprop_load /Extra/devprop.bin
  85. fi
  86. if [ -f /Extra/splash.jpg ]; then
  87. insmod jpeg
  88. xnu_splash /Extra/splash.jpg
  89. fi
  90. if [ -f /Extra/splash.png ]; then
  91. insmod png
  92. xnu_splash /Extra/splash.png
  93. fi
  94. if [ -f /Extra/splash.tga ]; then
  95. insmod tga
  96. xnu_splash /Extra/splash.tga
  97. fi
  98. fi
  99. }
  100. EOF
  101. }
  102. used_osprober_linux_ids=
  103. for OS in ${OSPROBED} ; do
  104. DEVICE="`echo ${OS} | cut -d ':' -f 1`"
  105. LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
  106. LABEL="`echo ${OS} | cut -d ':' -f 3 | tr '^' ' '`"
  107. BOOT="`echo ${OS} | cut -d ':' -f 4`"
  108. if UUID="`${grub_probe} --target=fs_uuid --device ${DEVICE%@*}`"; then
  109. EXPUUID="$UUID"
  110. if [ x"${DEVICE#*@}" != x ] ; then
  111. EXPUUID="${EXPUUID}@${DEVICE#*@}"
  112. fi
  113. if [ "x${GRUB_OS_PROBER_SKIP_LIST}" != "x" ] && [ "x`echo ${GRUB_OS_PROBER_SKIP_LIST} | grep -i -e '\b'${EXPUUID}'\b'`" != "x" ] ; then
  114. echo "Skipped ${LONGNAME} on ${DEVICE} by user request." >&2
  115. continue
  116. fi
  117. fi
  118. BTRFS="`echo ${OS} | cut -d ':' -f 5`"
  119. if [ "x$BTRFS" = "xbtrfs" ]; then
  120. BTRFSuuid="`echo ${OS} | cut -d ':' -f 6`"
  121. BTRFSsubvol="`echo ${OS} | cut -d ':' -f 7`"
  122. fi
  123. if [ -z "${LONGNAME}" ] ; then
  124. LONGNAME="${LABEL}"
  125. fi
  126. # os-prober returns text string followed by optional counter
  127. CLASS="--class $(echo "${LABEL}" | LC_ALL=C sed 's,[[:digit:]]*$,,' | cut -d' ' -f1 | tr 'A-Z' 'a-z' | LC_ALL=C sed 's,[^[:alnum:]_],_,g')"
  128. gettext_printf "Found %s on %s\n" "${LONGNAME}" "${DEVICE}" >&2
  129. case ${BOOT} in
  130. chain)
  131. onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
  132. cat << EOF
  133. menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' $CLASS --class os \$menuentry_id_option 'osprober-chain-$(grub_get_device_id "${DEVICE}")' {
  134. EOF
  135. save_default_entry | grub_add_tab
  136. prepare_grub_to_access_device ${DEVICE} | grub_add_tab
  137. if [ x"`${grub_probe} --device ${DEVICE} --target=partmap`" = xmsdos ]; then
  138. cat << EOF
  139. parttool \${root} hidden-
  140. EOF
  141. fi
  142. case ${LONGNAME} in
  143. Windows\ Vista*|Windows\ 7*|Windows\ Server\ 2008*)
  144. ;;
  145. *)
  146. cat << EOF
  147. drivemap -s (hd0) \${root}
  148. EOF
  149. ;;
  150. esac
  151. cat <<EOF
  152. chainloader +1
  153. }
  154. EOF
  155. ;;
  156. efi)
  157. EFIPATH=${DEVICE#*@}
  158. DEVICE=${DEVICE%@*}
  159. onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
  160. cat << EOF
  161. menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' $CLASS --class os \$menuentry_id_option 'osprober-efi-$(grub_get_device_id "${DEVICE}")' {
  162. EOF
  163. save_default_entry | sed -e "s/^/\t/"
  164. prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
  165. cat <<EOF
  166. chainloader ${EFIPATH}
  167. }
  168. EOF
  169. ;;
  170. linux)
  171. if [ "x$BTRFS" = "xbtrfs" ]; then
  172. LINUXPROBED="`linux-boot-prober btrfs ${BTRFSuuid} ${BTRFSsubvol} 2> /dev/null | tr ' ' '^' | paste -s -d ' '`"
  173. else
  174. LINUXPROBED="`linux-boot-prober ${DEVICE} 2> /dev/null | tr ' ' '^' | paste -s -d ' '`"
  175. fi
  176. prepare_boot_cache=
  177. boot_device_id=
  178. is_top_level=true
  179. title_correction_code=
  180. OS="${LONGNAME}"
  181. for LINUX in ${LINUXPROBED} ; do
  182. LROOT="`echo ${LINUX} | cut -d ':' -f 1`"
  183. LBOOT="`echo ${LINUX} | cut -d ':' -f 2`"
  184. LLABEL="`echo ${LINUX} | cut -d ':' -f 3 | tr '^' ' '`"
  185. LKERNEL="`echo ${LINUX} | cut -d ':' -f 4`"
  186. LINITRD="`echo ${LINUX} | cut -d ':' -f 5`"
  187. LPARAMS="`echo ${LINUX} | cut -d ':' -f 6- | tr '^' ' '`"
  188. if [ -z "${LLABEL}" ] ; then
  189. LLABEL="${LONGNAME}"
  190. fi
  191. if [ "${LROOT}" != "${LBOOT}" ]; then
  192. LKERNEL="${LKERNEL#/boot}"
  193. LINITRD="${LINITRD#/boot}"
  194. fi
  195. onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
  196. recovery_params="$(echo "${LPARAMS}" | grep single)" || true
  197. counter=1
  198. while echo "$used_osprober_linux_ids" | grep 'osprober-gnulinux-$LKERNEL-${recovery_params}-$counter-$boot_device_id' > /dev/null; do
  199. counter=$((counter+1));
  200. done
  201. if [ -z "$boot_device_id" ]; then
  202. boot_device_id="$(grub_get_device_id "${DEVICE}")"
  203. fi
  204. used_osprober_linux_ids="$used_osprober_linux_ids 'osprober-gnulinux-$LKERNEL-${recovery_params}-$counter-$boot_device_id'"
  205. if [ -z "${prepare_boot_cache}" ]; then
  206. prepare_boot_cache="$(prepare_grub_to_access_device ${LBOOT} | grub_add_tab)"
  207. fi
  208. if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then
  209. cat << EOF
  210. menuentry '$(echo "$OS $onstr" | grub_quote)' $CLASS --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-simple-$boot_device_id' {
  211. EOF
  212. save_default_entry | grub_add_tab
  213. printf '%s\n' "${prepare_boot_cache}"
  214. cat << EOF
  215. linux ${LKERNEL} ${LPARAMS}
  216. EOF
  217. if [ -n "${LINITRD}" ] ; then
  218. cat << EOF
  219. initrd ${LINITRD}
  220. EOF
  221. fi
  222. cat << EOF
  223. }
  224. EOF
  225. echo "submenu '$(gettext_printf "Advanced options for %s" "${OS} $onstr" | grub_quote)' \$menuentry_id_option 'osprober-gnulinux-advanced-$boot_device_id' {"
  226. is_top_level=false
  227. fi
  228. title="${LLABEL} $onstr"
  229. cat << EOF
  230. menuentry '$(echo "$title" | grub_quote)' --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-$LKERNEL-${recovery_params}-$boot_device_id' {
  231. EOF
  232. save_default_entry | sed -e "s/^/$grub_tab$grub_tab/"
  233. printf '%s\n' "${prepare_boot_cache}" | grub_add_tab
  234. cat << EOF
  235. linux ${LKERNEL} ${LPARAMS}
  236. EOF
  237. if [ -n "${LINITRD}" ] ; then
  238. cat << EOF
  239. initrd ${LINITRD}
  240. EOF
  241. fi
  242. cat << EOF
  243. }
  244. EOF
  245. if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
  246. replacement_title="$(echo "Advanced options for ${OS} $onstr" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
  247. quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
  248. title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
  249. 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")"
  250. fi
  251. done
  252. if [ x"$is_top_level" != xtrue ]; then
  253. echo '}'
  254. fi
  255. echo "$title_correction_code"
  256. ;;
  257. macosx)
  258. if [ "${UUID}" ]; then
  259. OSXUUID="${UUID}"
  260. osx_entry xnu_kernel 32
  261. osx_entry xnu_kernel64 64
  262. fi
  263. ;;
  264. hurd)
  265. onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
  266. cat << EOF
  267. menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class hurd --class gnu --class os \$menuentry_id_option 'osprober-gnuhurd-/boot/gnumach.gz-false-$(grub_get_device_id "${DEVICE}")' {
  268. EOF
  269. save_default_entry | grub_add_tab
  270. prepare_grub_to_access_device ${DEVICE} | grub_add_tab
  271. grub_device="`${grub_probe} --device ${DEVICE} --target=drive`"
  272. mach_device="`echo "${grub_device}" | sed -e 's/(\(hd.*\),msdos\(.*\))/\1s\2/'`"
  273. grub_fs="`${grub_probe} --device ${DEVICE} --target=fs`"
  274. case "${grub_fs}" in
  275. *fs) hurd_fs="${grub_fs}" ;;
  276. *) hurd_fs="${grub_fs}fs" ;;
  277. esac
  278. cat << EOF
  279. multiboot /boot/gnumach.gz root=device:${mach_device}
  280. module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\
  281. --multiboot-command-line='\${kernel-command-line}' \\
  282. --host-priv-port='\${host-port}' \\
  283. --device-master-port='\${device-port}' \\
  284. --exec-server-task='\${exec-task}' -T typed '\${root}' \\
  285. '\$(task-create)' '\$(task-resume)'
  286. module /lib/ld.so.1 exec /hurd/exec '\$(exec-task=task-create)'
  287. }
  288. EOF
  289. ;;
  290. minix)
  291. cat << EOF
  292. menuentry "${LONGNAME} (on ${DEVICE}, Multiboot)" {
  293. EOF
  294. save_default_entry | sed -e "s/^/\t/"
  295. prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
  296. cat << EOF
  297. multiboot /boot/image_latest
  298. }
  299. EOF
  300. ;;
  301. *)
  302. # TRANSLATORS: %s is replaced by OS name.
  303. gettext_printf "%s is not yet supported by grub-mkconfig.\n" " ${LONGNAME}" >&2
  304. ;;
  305. esac
  306. done