Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
192 - 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="/usr"
21
exec_prefix="/usr"
22
datarootdir="/usr/share"
23
 
24
export TEXTDOMAIN=grub
25
export TEXTDOMAINDIR="${datarootdir}/locale"
26
 
27
. "$pkgdatadir/grub-mkconfig_lib"
28
 
29
if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then
30
  exit 0
31
fi
32
 
33
if [ -z "`which os-prober 2> /dev/null`" ] || [ -z "`which linux-boot-prober 2> /dev/null`" ] ; then
34
  # missing os-prober and/or linux-boot-prober
35
  exit 0
36
fi
37
 
38
OSPROBED="`os-prober | tr ' ' '^' | paste -s -d ' '`"
39
if [ -z "${OSPROBED}" ] ; then
40
  # empty os-prober output, nothing doing
41
  exit 0
42
fi
43
 
44
osx_entry() {
45
    found_other_os=1
46
    # TRANSLATORS: it refers on the OS residing on device %s
47
    onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
48
    hints=""
49
    for hint in `"${grub_probe}" --device ${device} --target=efi_hints 2> /dev/null` ; do
50
      hints="${hints} --hint=${hint}"
51
    done
52
    cat << EOF
53
menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class osx --class darwin --class os \$menuentry_id_option 'osprober-xnu-$2-$(grub_get_device_id "${DEVICE}")'  {
54
EOF
55
	save_default_entry | grub_add_tab
56
	prepare_grub_to_access_device ${DEVICE} | grub_add_tab
57
	cat << EOF
58
	set gfxpayload=keep
59
        load_video
60
	insmod part_gpt
61
	insmod hfsplus
62
	search --no-floppy --fs-uuid --set=root ${hints} $(grub_get_device_id "${DEVICE}")
63
	chainloader (\$root)/System/Library/CoreServices/boot.efi
64
	boot
65
}
66
EOF
67
}
68
 
69
used_osprober_linux_ids=
70
 
71
for OS in ${OSPROBED} ; do
72
  DEVICE="`echo ${OS} | cut -d ':' -f 1`"
73
  LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
74
  LABEL="`echo ${OS} | cut -d ':' -f 3 | tr '^' ' '`"
75
  BOOT="`echo ${OS} | cut -d ':' -f 4`"
76
  if UUID="`${grub_probe} --target=fs_uuid --device ${DEVICE%@*}`"; then
77
    EXPUUID="$UUID"
78
 
79
    if [ x"${DEVICE#*@}" != x ] ; then
80
      EXPUUID="${EXPUUID}@${DEVICE#*@}"
81
    fi
82
 
83
    if [ "x${GRUB_OS_PROBER_SKIP_LIST}" != "x" ] && [ "x`echo ${GRUB_OS_PROBER_SKIP_LIST} | grep -i -e '\b'${EXPUUID}'\b'`" != "x" ] ; then
84
      echo "Skipped ${LONGNAME} on ${DEVICE} by user request." >&2
85
      continue
86
    fi
87
  fi
88
 
89
  BTRFS="`echo ${OS} | cut -d ':' -f 5`"
90
  if [ "x$BTRFS" = "xbtrfs" ]; then
91
	BTRFSuuid="`echo ${OS} | cut -d ':' -f 6`"
92
	BTRFSsubvol="`echo ${OS} | cut -d ':' -f 7`"
93
  fi
94
 
95
  if [ -z "${LONGNAME}" ] ; then
96
    LONGNAME="${LABEL}"
97
  fi
98
 
99
  # os-prober returns text string followed by optional counter
100
  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')"
101
 
102
  gettext_printf "Found %s on %s\n" "${LONGNAME}" "${DEVICE}" >&2
103
 
104
  case ${BOOT} in
105
    chain)
106
      found_other_os=1
107
 
108
	  onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
109
      cat << EOF
110
menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' $CLASS --class os \$menuentry_id_option 'osprober-chain-$(grub_get_device_id "${DEVICE}")' {
111
EOF
112
      save_default_entry | grub_add_tab
113
      prepare_grub_to_access_device ${DEVICE} | grub_add_tab
114
 
115
      if [ x"`${grub_probe} --device ${DEVICE} --target=partmap`" = xmsdos ]; then
116
	  cat << EOF
117
	parttool \${root} hidden-
118
EOF
119
      fi
120
 
121
      case ${LONGNAME} in
122
	Windows\ Vista*|Windows\ 7*|Windows\ Server\ 2008*)
123
	;;
124
	*)
125
	  cat << EOF
126
	drivemap -s (hd0) \${root}
127
EOF
128
	;;
129
      esac
130
 
131
      cat <<EOF
132
	chainloader +1
133
}
134
EOF
135
    ;;
136
    efi)
137
      found_other_os=1
138
 
139
	EFIPATH=${DEVICE#*@}
140
	DEVICE=${DEVICE%@*}
141
	onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
142
      cat << EOF
143
menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' $CLASS --class os \$menuentry_id_option 'osprober-efi-$(grub_get_device_id "${DEVICE}")' {
144
EOF
145
      save_default_entry | sed -e "s/^/\t/"
146
      prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
147
 
148
      cat <<EOF
149
	chainloader ${EFIPATH}
150
}
151
EOF
152
    ;;
153
    linux)
154
      if [ "x$BTRFS" = "xbtrfs" ]; then
155
         LINUXPROBED="`linux-boot-prober btrfs ${BTRFSuuid} ${BTRFSsubvol}  2> /dev/null | tr ' ' '^' | paste -s -d ' '`"
156
      else
157
         LINUXPROBED="`linux-boot-prober ${DEVICE} 2> /dev/null | tr ' ' '^' | paste -s -d ' '`"
158
      fi
159
      prepare_boot_cache=
160
      boot_device_id=
161
      is_top_level=true
162
      title_correction_code=
163
      OS="${LONGNAME}"
164
 
165
      for LINUX in ${LINUXPROBED} ; do
166
        LROOT="`echo ${LINUX} | cut -d ':' -f 1`"
167
        LBOOT="`echo ${LINUX} | cut -d ':' -f 2`"
168
        LLABEL="`echo ${LINUX} | cut -d ':' -f 3 | tr '^' ' '`"
169
        LKERNEL="`echo ${LINUX} | cut -d ':' -f 4`"
170
        LINITRD="`echo ${LINUX} | cut -d ':' -f 5`"
171
        LPARAMS="`echo ${LINUX} | cut -d ':' -f 6- | tr '^' ' '`"
172
 
173
        if [ -z "${LLABEL}" ] ; then
174
          LLABEL="${LONGNAME}"
175
        fi
176
 
177
	if [ "${LROOT}" != "${LBOOT}" ]; then
178
	  LKERNEL="${LKERNEL#/boot}"
179
	  LINITRD="${LINITRD#/boot}"
180
	fi
181
 
182
        found_other_os=1
183
	onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
184
	recovery_params="$(echo "${LPARAMS}" | grep single)" || true
185
	counter=1
186
	while echo "$used_osprober_linux_ids" | grep 'osprober-gnulinux-$LKERNEL-${recovery_params}-$counter-$boot_device_id' > /dev/null; do
187
	    counter=$((counter+1));
188
	done
189
	if [ -z "$boot_device_id" ]; then
190
	    boot_device_id="$(grub_get_device_id "${DEVICE}")"
191
	fi
192
	used_osprober_linux_ids="$used_osprober_linux_ids 'osprober-gnulinux-$LKERNEL-${recovery_params}-$counter-$boot_device_id'"
193
 
194
	if [ -z "${prepare_boot_cache}" ]; then
195
	  prepare_boot_cache="$(prepare_grub_to_access_device ${LBOOT} | grub_add_tab)"
196
	fi
197
 
198
	if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then
199
            cat << EOF
200
menuentry '$(echo "$OS $onstr" | grub_quote)' $CLASS --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-simple-$boot_device_id' {
201
EOF
202
	    save_default_entry | grub_add_tab
203
	    printf '%s\n' "${prepare_boot_cache}"
204
	    cat <<  EOF
205
	linux ${LKERNEL} ${LPARAMS}
206
EOF
207
            if [ -n "${LINITRD}" ] ; then
208
          cat << EOF
209
	initrd ${LINITRD}
210
EOF
211
            fi
212
        cat << EOF
213
}
214
EOF
215
	    echo "submenu '$(gettext_printf "Advanced options for %s" "${OS} $onstr" | grub_quote)' \$menuentry_id_option 'osprober-gnulinux-advanced-$boot_device_id' {"
216
	    is_top_level=false
217
	fi
218
	title="${LLABEL} $onstr"
219
        cat << EOF
220
	menuentry '$(echo "$title" | grub_quote)' --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-$LKERNEL-${recovery_params}-$boot_device_id' {
221
EOF
222
	save_default_entry | sed -e "s/^/$grub_tab$grub_tab/"
223
	printf '%s\n' "${prepare_boot_cache}" | grub_add_tab
224
	cat <<  EOF
225
		linux ${LKERNEL} ${LPARAMS}
226
EOF
227
        if [ -n "${LINITRD}" ] ; then
228
            cat << EOF
229
		initrd ${LINITRD}
230
EOF
231
        fi
232
        cat << EOF
233
	}
234
EOF
235
	if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
236
	    replacement_title="$(echo "Advanced options for ${OS} $onstr" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
237
	    quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
238
	    title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
239
	    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")"
240
	fi
241
      done
242
      if [ x"$is_top_level" != xtrue ]; then
243
	  echo '}'
244
      fi
245
      echo "$title_correction_code"
246
    ;;
247
    macosx)
248
      for subdevice in ${DEVICE%[[:digit:]]*}* ; do
249
	parttype="`"${grub_probe}" --device ${device} --target=gpt_parttype "${subdevice}" 2> /dev/null`"
250
	if [[ "$parttype" = "426f6f74-0000-11aa-aa11-00306543ecac" ]]; then
251
	  DEVICE="${subdevice}" osx_entry
252
	fi
253
      done
254
    ;;
255
    hurd)
256
      found_other_os=1
257
      onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
258
      cat << EOF
259
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}")' {
260
EOF
261
      save_default_entry | grub_add_tab
262
      prepare_grub_to_access_device ${DEVICE} | grub_add_tab
263
      grub_device="`${grub_probe} --device ${DEVICE} --target=drive`"
264
      mach_device="`echo "${grub_device}" | sed -e 's/(\(hd.*\),msdos\(.*\))/\1s\2/'`"
265
      grub_fs="`${grub_probe} --device ${DEVICE} --target=fs`"
266
      case "${grub_fs}" in
267
	*fs)	hurd_fs="${grub_fs}" ;;
268
	*)	hurd_fs="${grub_fs}fs" ;;
269
      esac
270
      cat << EOF
271
	multiboot /boot/gnumach.gz root=device:${mach_device}
272
	module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\
273
			--multiboot-command-line='\${kernel-command-line}' \\
274
			--host-priv-port='\${host-port}' \\
275
			--device-master-port='\${device-port}' \\
276
			--exec-server-task='\${exec-task}' -T typed '\${root}' \\
277
			'\$(task-create)' '\$(task-resume)'
278
	module /lib/ld.so.1 exec /hurd/exec '\$(exec-task=task-create)'
279
}
280
EOF
281
    ;;
282
    minix)
283
      found_other_os=1
284
	  cat << EOF
285
menuentry "${LONGNAME} (on ${DEVICE}, Multiboot)" {
286
EOF
287
         save_default_entry | sed -e "s/^/\t/"
288
         prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
289
	 cat << EOF
290
	multiboot /boot/image_latest
291
}
292
EOF
293
    ;;
294
    *)
295
      case ${DEVICE} in
296
	*.efi)
297
	  cat << EOF
298
menuentry '$(echo "${LONGNAME}" | grub_quote)' {
299
EOF
300
	  save_default_entry | grub_add_tab
301
	  cat << EOF
302
	  chainloader /EFI/${DEVICE}
303
	  boot
304
}
305
EOF
306
	  ;;
307
	*)
308
          echo -n "  "
309
          # TRANSLATORS: %s is replaced by OS name.
310
          gettext_printf "%s is not yet supported by grub-mkconfig.\n" "${LONGNAME}" >&2
311
        ;;
312
      esac
313
  esac
314
done
315
 
316
# We override the results of the menu_auto_hide code here, this is a bit ugly,
317
# but grub-mkconfig writes out the file linearly, so this is the only way
318
if [ "${found_other_os}" = "1" ]; then
319
  cat << EOF
320
# Other OS found, undo autohiding of menu unless menu_auto_hide=2
321
if [ "\${orig_timeout_style}" -a "\${menu_auto_hide}" != "2" ]; then
322
  set timeout_style=\${orig_timeout_style}
323
  set timeout=\${orig_timeout}
324
fi
325
EOF
326
fi