30_os-prober 12 KB

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