/grub.d/30_os-prober

http://github.com/brinkman83/bashrc · Shell · 249 lines · 209 code · 22 blank · 18 comment · 36 complexity · 235cb43f280c29557f0f24a1e8163457 MD5 · raw file

  1. #! /bin/sh -e
  2. # grub-mkconfig helper script.
  3. # Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
  4. #
  5. # GRUB is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # GRUB is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. prefix=/usr
  18. exec_prefix=${prefix}
  19. libdir=${exec_prefix}/lib
  20. . ${libdir}/grub/grub-mkconfig_lib
  21. found_other_os=
  22. adjust_timeout () {
  23. if [ "x${found_other_os}" = "x" ] ; then
  24. if [ "x${GRUB_HIDDEN_TIMEOUT}" != "x" ] ; then
  25. if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then
  26. verbose=
  27. else
  28. verbose=" --verbose"
  29. fi
  30. if [ "x${GRUB_HIDDEN_TIMEOUT}" = "x0" ] ; then
  31. cat <<EOF
  32. if [ \${timeout} != -1 ]; then
  33. if keystatus; then
  34. if keystatus --shift; then
  35. set timeout=-1
  36. else
  37. set timeout=0
  38. fi
  39. else
  40. if sleep$verbose --interruptible 3 ; then
  41. set timeout=0
  42. fi
  43. fi
  44. fi
  45. EOF
  46. else
  47. cat << EOF
  48. if [ \${timeout} != -1 ]; then
  49. if sleep$verbose --interruptible ${GRUB_HIDDEN_TIMEOUT} ; then
  50. set timeout=0
  51. fi
  52. fi
  53. EOF
  54. fi
  55. fi
  56. fi
  57. }
  58. if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then
  59. adjust_timeout
  60. exit 0
  61. fi
  62. if [ -z "`which os-prober 2> /dev/null`" -o -z "`which linux-boot-prober 2> /dev/null`" ] ; then
  63. # missing os-prober and/or linux-boot-prober
  64. adjust_timeout
  65. exit 0
  66. fi
  67. OSPROBED="`os-prober | tr ' ' '^' | paste -s -d ' '`"
  68. if [ -z "${OSPROBED}" ] ; then
  69. # empty os-prober output, nothing doing
  70. adjust_timeout
  71. exit 0
  72. fi
  73. osx_entry() {
  74. cat << EOF
  75. menuentry "${LONGNAME} (${2}-bit) (on ${DEVICE})" {
  76. EOF
  77. save_default_entry | sed -e "s/^/\t/"
  78. prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
  79. cat << EOF
  80. insmod ${GRUB_VIDEO_BACKEND}
  81. set do_resume=0
  82. if [ /var/vm/sleepimage -nt10 / ]; then
  83. if xnu_resume /var/vm/sleepimage; then
  84. set do_resume=1
  85. fi
  86. fi
  87. if [ \$do_resume == 0 ]; then
  88. xnu_uuid ${OSXUUID} uuid
  89. if [ -f /Extra/DSDT.aml ]; then
  90. acpi -e /Extra/DSDT.aml
  91. fi
  92. $1 /mach_kernel boot-uuid=\${uuid} rd=*uuid
  93. if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then
  94. xnu_mkext /System/Library/Extensions.mkext
  95. else
  96. xnu_kextdir /System/Library/Extensions
  97. fi
  98. if [ -f /Extra/Extensions.mkext ]; then
  99. xnu_mkext /Extra/Extensions.mkext
  100. fi
  101. if [ -d /Extra/Extensions ]; then
  102. xnu_kextdir /Extra/Extensions
  103. fi
  104. if [ -f /Extra/devprop.bin ]; then
  105. xnu_devprop_load /Extra/devprop.bin
  106. fi
  107. if [ -f /Extra/splash.jpg ]; then
  108. insmod jpeg
  109. xnu_splash /Extra/splash.jpg
  110. fi
  111. if [ -f /Extra/splash.png ]; then
  112. insmod png
  113. xnu_splash /Extra/splash.png
  114. fi
  115. if [ -f /Extra/splash.tga ]; then
  116. insmod tga
  117. xnu_splash /Extra/splash.tga
  118. fi
  119. fi
  120. }
  121. EOF
  122. }
  123. for OS in ${OSPROBED} ; do
  124. DEVICE="`echo ${OS} | cut -d ':' -f 1`"
  125. LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
  126. LABEL="`echo ${OS} | cut -d ':' -f 3 | tr '^' ' '`"
  127. BOOT="`echo ${OS} | cut -d ':' -f 4`"
  128. if [ -z "${LONGNAME}" ] ; then
  129. LONGNAME="${LABEL}"
  130. fi
  131. echo "Found ${LONGNAME} on ${DEVICE}" >&2
  132. found_other_os=1
  133. case ${BOOT} in
  134. chain)
  135. cat << EOF
  136. menuentry "${LONGNAME} (on ${DEVICE})" {
  137. EOF
  138. save_default_entry | sed -e "s/^/\t/"
  139. prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
  140. case ${LONGNAME} in
  141. Windows\ Vista*|Windows\ 7*)
  142. ;;
  143. *)
  144. cat << EOF
  145. drivemap -s (hd0) \${root}
  146. EOF
  147. ;;
  148. esac
  149. cat <<EOF
  150. chainloader +1
  151. }
  152. EOF
  153. ;;
  154. linux)
  155. LINUXPROBED="`linux-boot-prober ${DEVICE} 2> /dev/null | tr ' ' '^' | paste -s -d ' '`"
  156. prepare_boot_cache=
  157. for LINUX in ${LINUXPROBED} ; do
  158. LROOT="`echo ${LINUX} | cut -d ':' -f 1`"
  159. LBOOT="`echo ${LINUX} | cut -d ':' -f 2`"
  160. LLABEL="`echo ${LINUX} | cut -d ':' -f 3 | tr '^' ' '`"
  161. LKERNEL="`echo ${LINUX} | cut -d ':' -f 4`"
  162. LINITRD="`echo ${LINUX} | cut -d ':' -f 5`"
  163. LPARAMS="`echo ${LINUX} | cut -d ':' -f 6- | tr '^' ' '`"
  164. if [ -z "${LLABEL}" ] ; then
  165. LLABEL="${LONGNAME}"
  166. fi
  167. if [ "${LROOT}" != "${LBOOT}" ]; then
  168. LKERNEL="${LKERNEL#/boot}"
  169. LINITRD="${LINITRD#/boot}"
  170. fi
  171. cat << EOF
  172. menuentry "${LLABEL} (on ${DEVICE})" {
  173. EOF
  174. save_default_entry | sed -e "s/^/\t/"
  175. if [ -z "${prepare_boot_cache}" ]; then
  176. prepare_boot_cache="$(prepare_grub_to_access_device ${LBOOT} | sed -e "s/^/\t/")"
  177. fi
  178. printf '%s\n' "${prepare_boot_cache}"
  179. cat << EOF
  180. linux ${LKERNEL} ${LPARAMS}
  181. EOF
  182. if [ -n "${LINITRD}" ] ; then
  183. cat << EOF
  184. initrd ${LINITRD}
  185. EOF
  186. fi
  187. cat << EOF
  188. }
  189. EOF
  190. done
  191. ;;
  192. macosx)
  193. OSXUUID="`grub-probe --target=fs_uuid --device ${DEVICE} 2> /dev/null`"
  194. osx_entry xnu_kernel 32
  195. osx_entry xnu_kernel64 64
  196. ;;
  197. hurd)
  198. cat << EOF
  199. menuentry "${LONGNAME} (on ${DEVICE})" {
  200. EOF
  201. save_default_entry | sed -e "s/^/\t/"
  202. prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
  203. grub_device="`${grub_probe} --device ${DEVICE} --target=drive`"
  204. mach_device="`echo "${grub_device}" | tr -d '()' | tr , s`"
  205. grub_fs="`${grub_probe} --device ${DEVICE} --target=fs`"
  206. case "${grub_fs}" in
  207. *fs) hurd_fs="${grub_fs}" ;;
  208. *) hurd_fs="${grub_fs}fs" ;;
  209. esac
  210. cat << EOF
  211. multiboot /boot/gnumach.gz root=device:${mach_device}
  212. module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\
  213. --multiboot-command-line='\${kernel-command-line}' \\
  214. --host-priv-port='\${host-port}' \\
  215. --device-master-port='\${device-port}' \\
  216. --exec-server-task='\${exec-task}' -T typed '\${root}' \\
  217. '\$(task-create)' '\$(task-resume)'
  218. module /lib/ld.so.1 exec /hurd/exec '\$(exec-task=task-create)'
  219. }
  220. EOF
  221. ;;
  222. *)
  223. echo " ${LONGNAME} is not yet supported by grub-mkconfig." >&2
  224. ;;
  225. esac
  226. done
  227. adjust_timeout