]> git.proxmox.com Git - grub2.git/blob - util/grub.d/30_os-prober.in
Tolerate devices with no filesystem UUID returned by os-prober
[grub2.git] / util / grub.d / 30_os-prober.in
1 #! /bin/sh
2 set -e
3
4 # grub-mkconfig helper script.
5 # Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
6 #
7 # GRUB is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # GRUB is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19
20 prefix="@prefix@"
21 exec_prefix="@exec_prefix@"
22 datarootdir="@datarootdir@"
23 quick_boot="@QUICK_BOOT@"
24
25 export TEXTDOMAIN=@PACKAGE@
26 export TEXTDOMAINDIR="@localedir@"
27
28 . "@datadir@/@PACKAGE@/grub-mkconfig_lib"
29
30 found_other_os=
31
32 adjust_timeout () {
33 if [ "$quick_boot" = 1 ] && [ "x${found_other_os}" != "x" ]; then
34 cat << EOF
35 set timeout_style=menu
36 if [ "\${timeout}" = 0 ]; then
37 set timeout=10
38 fi
39 EOF
40 fi
41 }
42
43 if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then
44 exit 0
45 fi
46
47 if [ -z "`which os-prober 2> /dev/null`" -o -z "`which linux-boot-prober 2> /dev/null`" ] ; then
48 # missing os-prober and/or linux-boot-prober
49 exit 0
50 fi
51
52 OSPROBED="`os-prober | tr ' ' '^' | paste -s -d ' '`"
53 if [ -z "${OSPROBED}" ] ; then
54 # empty os-prober output, nothing doing
55 exit 0
56 fi
57
58 osx_entry() {
59 found_other_os=1
60 if [ x$2 = x32 ]; then
61 # TRANSLATORS: it refers to kernel architecture (32-bit)
62 bitstr="$(gettext "(32-bit)")"
63 else
64 # TRANSLATORS: it refers to kernel architecture (64-bit)
65 bitstr="$(gettext "(64-bit)")"
66 fi
67 # TRANSLATORS: it refers on the OS residing on device %s
68 onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
69 cat << EOF
70 menuentry '$(echo "${LONGNAME} $bitstr $onstr" | grub_quote)' --class osx --class darwin --class os \$menuentry_id_option 'osprober-xnu-$2-$(grub_get_device_id "${DEVICE}")' {
71 EOF
72 save_default_entry | grub_add_tab
73 prepare_grub_to_access_device ${DEVICE} | grub_add_tab
74 cat << EOF
75 load_video
76 set do_resume=0
77 if [ /var/vm/sleepimage -nt10 / ]; then
78 if xnu_resume /var/vm/sleepimage; then
79 set do_resume=1
80 fi
81 fi
82 if [ \$do_resume = 0 ]; then
83 xnu_uuid ${OSXUUID} uuid
84 if [ -f /Extra/DSDT.aml ]; then
85 acpi -e /Extra/DSDT.aml
86 fi
87 if [ /kernelcache -nt /System/Library/Extensions ]; then
88 $1 /kernelcache boot-uuid=\${uuid} rd=*uuid
89 else
90 $1 /mach_kernel boot-uuid=\${uuid} rd=*uuid
91 if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then
92 xnu_mkext /System/Library/Extensions.mkext
93 else
94 xnu_kextdir /System/Library/Extensions
95 fi
96 fi
97 if [ -f /Extra/Extensions.mkext ]; then
98 xnu_mkext /Extra/Extensions.mkext
99 fi
100 if [ -d /Extra/Extensions ]; then
101 xnu_kextdir /Extra/Extensions
102 fi
103 if [ -f /Extra/devprop.bin ]; then
104 xnu_devprop_load /Extra/devprop.bin
105 fi
106 if [ -f /Extra/splash.jpg ]; then
107 insmod jpeg
108 xnu_splash /Extra/splash.jpg
109 fi
110 if [ -f /Extra/splash.png ]; then
111 insmod png
112 xnu_splash /Extra/splash.png
113 fi
114 if [ -f /Extra/splash.tga ]; then
115 insmod tga
116 xnu_splash /Extra/splash.tga
117 fi
118 fi
119 }
120 EOF
121 }
122
123 used_osprober_linux_ids=
124
125 wubi=
126
127 for OS in ${OSPROBED} ; do
128 DEVICE="`echo ${OS} | cut -d ':' -f 1`"
129 LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
130 LABEL="`echo ${OS} | cut -d ':' -f 3 | tr '^' ' '`"
131 BOOT="`echo ${OS} | cut -d ':' -f 4`"
132 if UUID="`${grub_probe} --target=fs_uuid --device ${DEVICE%@*}`"; then
133 EXPUUID="$UUID"
134
135 if [ x"${DEVICE#*@}" != x ] ; then
136 EXPUUID="${EXPUUID}@${DEVICE#*@}"
137 fi
138
139 if [ "x${GRUB_OS_PROBER_SKIP_LIST}" != "x" -a "x`echo ${GRUB_OS_PROBER_SKIP_LIST} | grep -i -e '\b'${EXPUUID}'\b'`" != "x" ] ; then
140 echo "Skipped ${LONGNAME} on ${DEVICE} by user request." >&2
141 continue
142 fi
143 fi
144
145 BTRFS="`echo ${OS} | cut -d ':' -f 5`"
146 if [ "x$BTRFS" = "xbtrfs" ]; then
147 BTRFSuuid="`echo ${OS} | cut -d ':' -f 6`"
148 BTRFSsubvol="`echo ${OS} | cut -d ':' -f 7`"
149 fi
150
151 if [ -z "${LONGNAME}" ] ; then
152 LONGNAME="${LABEL}"
153 fi
154
155 gettext_printf "Found %s on %s\n" "${LONGNAME}" "${DEVICE}" >&2
156
157 case ${BOOT} in
158 chain)
159
160 case ${LONGNAME} in
161 Windows*)
162 if [ -z "$wubi" ]; then
163 if [ -x /usr/share/lupin-support/grub-mkimage ] && \
164 /usr/share/lupin-support/grub-mkimage --test; then
165 wubi=yes
166 else
167 wubi=no
168 fi
169 fi
170 if [ "$wubi" = yes ]; then
171 echo "Skipping ${LONGNAME} on Wubi system" >&2
172 continue
173 fi
174 ;;
175 esac
176
177 found_other_os=1
178 onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
179 cat << EOF
180 menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class windows --class os \$menuentry_id_option 'osprober-chain-$(grub_get_device_id "${DEVICE}")' {
181 EOF
182 save_default_entry | grub_add_tab
183 prepare_grub_to_access_device ${DEVICE} | grub_add_tab
184
185 if [ x"`${grub_probe} --device ${DEVICE} --target=partmap`" = xmsdos ]; then
186 cat << EOF
187 parttool \${root} hidden-
188 EOF
189 fi
190
191 case ${LONGNAME} in
192 Windows\ Vista*|Windows\ 7*|Windows\ Server\ 2008*)
193 ;;
194 *)
195 cat << EOF
196 drivemap -s (hd0) \${root}
197 EOF
198 ;;
199 esac
200
201 cat <<EOF
202 chainloader +1
203 }
204 EOF
205 ;;
206 efi)
207
208 found_other_os=1
209 EFIPATH=${DEVICE#*@}
210 DEVICE=${DEVICE%@*}
211 onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
212 cat << EOF
213 menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class windows --class os \$menuentry_id_option 'osprober-efi-$(grub_get_device_id "${DEVICE}")' {
214 EOF
215 save_default_entry | sed -e "s/^/\t/"
216 prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
217
218 cat <<EOF
219 chainloader ${EFIPATH}
220 }
221 EOF
222 ;;
223 linux)
224 if [ "x$BTRFS" = "xbtrfs" ]; then
225 LINUXPROBED="`linux-boot-prober btrfs ${BTRFSuuid} ${BTRFSsubvol} 2> /dev/null | tr ' ' '^' | paste -s -d ' '`"
226 else
227 LINUXPROBED="`linux-boot-prober ${DEVICE} 2> /dev/null | tr ' ' '^' | paste -s -d ' '`"
228 fi
229 prepare_boot_cache=
230 boot_device_id=
231 is_top_level=true
232 title_correction_code=
233 OS="${LONGNAME}"
234
235 for LINUX in ${LINUXPROBED} ; do
236 LROOT="`echo ${LINUX} | cut -d ':' -f 1`"
237 LBOOT="`echo ${LINUX} | cut -d ':' -f 2`"
238 LLABEL="`echo ${LINUX} | cut -d ':' -f 3 | tr '^' ' '`"
239 LKERNEL="`echo ${LINUX} | cut -d ':' -f 4`"
240 LINITRD="`echo ${LINUX} | cut -d ':' -f 5`"
241 LPARAMS="`echo ${LINUX} | cut -d ':' -f 6- | tr '^' ' '`"
242
243 if [ -z "${LLABEL}" ] ; then
244 LLABEL="${LONGNAME}"
245 fi
246
247 if [ "${LROOT}" != "${LBOOT}" ]; then
248 LKERNEL="${LKERNEL#/boot}"
249 LINITRD="${LINITRD#/boot}"
250 fi
251
252 if [ -z "${prepare_boot_cache}" ]; then
253 prepare_boot_cache="$(prepare_grub_to_access_device ${LBOOT} | grub_add_tab)"
254 [ "${prepare_boot_cache}" ] || continue
255 fi
256
257 found_other_os=1
258 onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
259 recovery_params="$(echo "${LPARAMS}" | grep 'single\|recovery')" || true
260 counter=1
261 while echo "$used_osprober_linux_ids" | grep 'osprober-gnulinux-$LKERNEL-${recovery_params}-$counter-$boot_device_id' > /dev/null; do
262 counter=$((counter+1));
263 done
264 if [ -z "$boot_device_id" ]; then
265 boot_device_id="$(grub_get_device_id "${DEVICE}")"
266 fi
267 used_osprober_linux_ids="$used_osprober_linux_ids 'osprober-gnulinux-$LKERNEL-${recovery_params}-$counter-$boot_device_id'"
268
269 if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then
270 cat << EOF
271 menuentry '$(echo "$OS $onstr" | grub_quote)' --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-simple-$boot_device_id' {
272 EOF
273 save_default_entry | grub_add_tab
274 printf '%s\n' "${prepare_boot_cache}"
275 cat << EOF
276 linux ${LKERNEL} ${LPARAMS}
277 EOF
278 if [ -n "${LINITRD}" ] ; then
279 cat << EOF
280 initrd ${LINITRD}
281 EOF
282 fi
283 cat << EOF
284 }
285 EOF
286 echo "submenu '$(gettext_printf "Advanced options for %s" "${OS} $onstr" | grub_quote)' \$menuentry_id_option 'osprober-gnulinux-advanced-$boot_device_id' {"
287 is_top_level=false
288 fi
289 title="${LLABEL} $onstr"
290 cat << EOF
291 menuentry '$(echo "$title" | grub_quote)' --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-$LKERNEL-${recovery_params}-$boot_device_id' {
292 EOF
293 save_default_entry | sed -e "s/^/$grub_tab$grub_tab/"
294 printf '%s\n' "${prepare_boot_cache}" | grub_add_tab
295 cat << EOF
296 linux ${LKERNEL} ${LPARAMS}
297 EOF
298 if [ -n "${LINITRD}" ] ; then
299 cat << EOF
300 initrd ${LINITRD}
301 EOF
302 fi
303 cat << EOF
304 }
305 EOF
306 if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
307 replacement_title="$(echo "Advanced options for ${OS} $onstr" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
308 quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
309 title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
310 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")"
311 fi
312 done
313 if [ x"$is_top_level" != xtrue ]; then
314 echo '}'
315 fi
316 echo "$title_correction_code"
317 ;;
318 macosx)
319 if [ "${UUID}" ]; then
320 OSXUUID="${UUID}"
321 osx_entry xnu_kernel 32
322 osx_entry xnu_kernel64 64
323 fi
324 ;;
325 hurd)
326 found_other_os=1
327 onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
328 cat << EOF
329 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}")' {
330 EOF
331 save_default_entry | grub_add_tab
332 prepare_grub_to_access_device ${DEVICE} | grub_add_tab
333 grub_device="`${grub_probe} --device ${DEVICE} --target=drive`"
334 mach_device="`echo "${grub_device}" | sed -e 's/(\(hd.*\),msdos\(.*\))/\1s\2/'`"
335 grub_fs="`${grub_probe} --device ${DEVICE} --target=fs`"
336 case "${grub_fs}" in
337 *fs) hurd_fs="${grub_fs}" ;;
338 *) hurd_fs="${grub_fs}fs" ;;
339 esac
340 cat << EOF
341 multiboot /boot/gnumach.gz root=device:${mach_device}
342 module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\
343 --multiboot-command-line='\${kernel-command-line}' \\
344 --host-priv-port='\${host-port}' \\
345 --device-master-port='\${device-port}' \\
346 --exec-server-task='\${exec-task}' -T typed '\${root}' \\
347 '\$(task-create)' '\$(task-resume)'
348 module /lib/ld.so.1 exec /hurd/exec '\$(exec-task=task-create)'
349 }
350 EOF
351 ;;
352 minix)
353 cat << EOF
354 menuentry "${LONGNAME} (on ${DEVICE}, Multiboot)" {
355 EOF
356 save_default_entry | sed -e "s/^/\t/"
357 prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
358 cat << EOF
359 multiboot /boot/image_latest
360 }
361 EOF
362 ;;
363 *)
364 echo -n " "
365 # TRANSLATORS: %s is replaced by OS name.
366 gettext_printf "%s is not yet supported by grub-mkconfig.\n" "${LONGNAME}" >&2
367 ;;
368 esac
369 done
370
371 adjust_timeout