Upgraded GRUB2 to 2.00 release.
[AROS.git] / arch / all-pc / boot / grub2-aros / util / grub-install.in
blobe19f1cd943be0613077581842a5c0209c42417ab
1 #! /bin/sh
3 # Install GRUB on your drive.
4 # Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
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.
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.
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/>.
19 # Initialize some variables.
20 transform="@program_transform_name@"
22 prefix="@prefix@"
23 exec_prefix="@exec_prefix@"
24 datarootdir="@datarootdir@"
25 sbindir="@sbindir@"
26 bindir="@bindir@"
27 libdir="@libdir@"
28 sysconfdir="@sysconfdir@"
29 PACKAGE_NAME=@PACKAGE_NAME@
30 PACKAGE_TARNAME=@PACKAGE_TARNAME@
31 PACKAGE_VERSION=@PACKAGE_VERSION@
33 export TEXTDOMAIN=@PACKAGE@
34 export TEXTDOMAINDIR="@localedir@"
36 host_os=@host_os@
37 source_dir=
38 target=
39 datadir="@datadir@"
40 if [ "x$pkgdatadir" = x ]; then
41 pkgdatadir="${datadir}/@PACKAGE@"
43 localedir="@datadir@/locale"
45 self="`basename $0`"
47 grub_mkimage="${bindir}/`echo grub-mkimage | sed ${transform}`"
48 grub_probe="${sbindir}/`echo grub-probe | sed ${transform}`"
49 grub_editenv="${bindir}/`echo grub-editenv | sed ${transform}`"
50 grub_mkrelpath="${bindir}/`echo grub-mkrelpath | sed ${transform}`"
51 rootdir=
52 bootdir=
53 grubdir="`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'`"
54 modules=
56 install_device=
57 force_lba=
58 recheck=no
59 debug=no
60 debug_image=
62 update_nvram=yes
64 removable=no
65 efi_quiet=
67 # Get GRUB_DISTRIBUTOR.
68 if test -f "${sysconfdir}/default/grub" ; then
69 . "${sysconfdir}/default/grub"
72 bootloader_id="$(echo "$GRUB_DISTRIBUTOR" | tr 'A-Z' 'a-z' | cut -d' ' -f1)"
73 if test -z "$bootloader_id"; then
74 bootloader_id=grub
77 disk_module=unspecified
79 . "${pkgdatadir}/grub-mkconfig_lib"
81 # Usage: usage
82 # Print the usage.
83 usage () {
84 # TRANSLATORS: INSTALL_DEVICE isn't an identifier and is the DEVICE you
85 # install to.
86 gettext_printf "Usage: %s [OPTION] [INSTALL_DEVICE]" "$self"
87 echo
88 gettext "Install GRUB on your drive." ; echo
89 echo
90 print_option_help "-h, --help" "$(gettext "print this message and exit")"
91 print_option_help "-v, --version" "$(gettext "print the version information and exit")"
92 print_option_help "--modules=$(gettext "MODULES")" "$(gettext "pre-load specified modules MODULES")"
93 dirmsg="$(gettext_printf "install GRUB images under the directory DIR/%s instead of the %s directory" "@grubdirname@" "$grubdir")"
94 print_option_help "--boot-directory=$(gettext "DIR")" "$dirmsg"
95 # TRANSLATORS: "TARGET" as in "target platform".
96 target_trans="$(gettext "TARGET")"
97 # TRANSLATORS: "current" refers to the platform user's currently running on
98 print_option_help "--target=$target_trans" "$(gettext "install GRUB for TARGET platform [default=current]")"
99 print_option_help "--directory=$(gettext "DIR")" "$(gettext "use GRUB images from DIR. Takes precedence over target")"
100 print_option_help "--grub-setup=$(gettext "FILE")" "$(gettext "use FILE as grub-setup")"
101 print_option_help "--grub-mkimage=$(gettext "FILE")" "$(gettext "use FILE as grub-mkimage")"
102 print_option_help "--grub-mkrelpath=$(gettext "FILE")" "$(gettext "use FILE as grub-mkrelpath")"
103 print_option_help "--grub-probe=$(gettext "FILE")" "$(gettext "use FILE as grub-probe")"
104 # TRANSLATORS: "may break" doesn't just mean that option wouldn't have any
105 # effect but that it will make the resulting install unbootable from HDD.
106 print_option_help "--allow-floppy" "$(gettext "make the drive also bootable as floppy (default for fdX devices). May break on some BIOSes.")"
107 print_option_help "--recheck" "$(gettext "delete device map if it already exists")"
108 print_option_help "--force" "$(gettext "install even if problems are detected")"
109 print_option_help "--force-file-id" "$(gettext "use identifier file even if UUID is available")"
110 print_option_help "--disk-module=$(gettext "MODULE")" "$(gettext "disk module to use (biosdisk or native). This option is only available on BIOS target.")"
111 print_option_help "--no-nvram" "$(gettext "don't update the \`boot-device' NVRAM variable. This option is only available on IEEE1275 targets.")"
112 print_option_help "--removable" "$(gettext "the installation device is removable. This option is only available on EFI.")"
113 print_option_help "--bootloader-id=$(gettext "ID")" "$(gettext "the ID of bootloader. This option is only available on EFI.")"
114 print_option_help "--efi-directory=$(gettext "DIR")" "$(gettext "use DIR as the EFI System Partition root.")"
115 echo
116 gettext "INSTALL_DEVICE must be system device filename.";echo
117 echo
119 gettext_printf "%s copies GRUB images into %s, and uses grub-setup
120 to install grub into the boot sector.\n" "$self" "$grubdir";echo
121 echo
122 gettext "Report bugs to <bug-grub@gnu.org>."; echo
125 argument () {
126 opt="$1"
127 shift
129 if test $# -eq 0; then
130 gettext_printf "%s: option requires an argument -- \`%s'\n" "$0" "$opt" 1>&2
131 exit 1
133 echo "$1"
136 allow_floppy=""
137 force_file_id=
138 efidir=
140 # Check the arguments.
141 while test $# -gt 0
143 option=$1
144 shift
146 case "$option" in
147 -h | --help)
148 usage
149 exit 0 ;;
150 -v | --version)
151 echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
152 exit 0 ;;
154 --modules)
155 modules=`argument $option "$@"`; shift;;
156 --modules=*)
157 modules=`echo "$option" | sed 's/--modules=//'` ;;
159 --force-file-id)
160 force_file_id=y ;;
162 # Accept and ignore for compatibility
163 --font)
164 shift;;
165 --font=*)
168 # Accept for compatibility
169 --root-directory)
170 rootdir="`argument $option "$@"`"; shift;;
171 --root-directory=*)
172 rootdir="`echo "$option" | sed 's/--root-directory=//'`" ;;
174 --boot-directory)
175 bootdir="`argument $option "$@"`"; shift;;
176 --boot-directory=*)
177 bootdir="`echo "$option" | sed 's/--boot-directory=//'`" ;;
179 --efi-directory)
180 efidir="`argument $option "$@"`"; shift;;
181 --efi-directory=*)
182 efidir="`echo "$option" | sed 's/--efi-directory=//'`" ;;
184 --directory | -d)
185 source_dir="`argument $option "$@"`"; shift;;
186 --directory=*)
187 source_dir="`echo "$option" | sed 's/--directory=//'`" ;;
189 --target)
190 target="`argument $option "$@"`"; shift;;
191 --target=*)
192 target="`echo "$option" | sed 's/--target=//'`" ;;
194 --grub-setup)
195 grub_setup="`argument "$option" "$@"`"; shift;;
196 --grub-setup=*)
197 grub_setup="`echo "$option" | sed 's/--grub-setup=//'`" ;;
199 --bootloader-id)
200 bootloader_id="`argument $option "$@"`"; shift;;
201 --bootloader-id=*)
202 bootloader_id="`echo "$option" | sed 's/--bootloader-id=//'`" ;;
204 --grub-mkimage)
205 grub_mkimage="`argument $option "$@"`"; shift;;
206 --grub-mkimage=*)
207 grub_mkimage="`echo "$option" | sed 's/--grub-mkimage=//'`" ;;
209 --grub-mkrelpath)
210 grub_mkrelpath="`argument "$option" "$@"`"; shift;;
211 --grub-mkrelpath=*)
212 grub_mkrelpath="`echo "$option" | sed 's/--grub-mkrelpath=//'`" ;;
214 # Ignore: for compatibility
215 --grub-mkdevicemap)
216 shift;;
217 --grub-mkdevicemap=*)
220 --grub-probe)
221 grub_probe="`argument "$option" "$@"`"; shift;;
222 --grub-probe=*)
223 grub_probe="`echo "$option" | sed 's/--grub-probe=//'`" ;;
225 --no-floppy)
227 --recheck)
228 recheck=yes ;;
229 --removable)
230 removable=yes ;;
232 --allow-floppy)
233 allow_floppy="--allow-floppy" ;;
235 --disk-module)
236 disk_module="`argument "$option" "$@"`"; shift;
238 --disk-module=*)
239 disk_module="`echo "$option" | sed 's/--disk-module=//'`"
242 --no-nvram)
243 update_nvram=no ;;
245 # This is an undocumented feature...
246 --debug)
247 debug=yes ;;
248 --debug-image)
249 debug_image="`argument "$option" "$@"`"; shift;;
250 --debug-image=*)
251 debug_image="`echo "$option" | sed 's/--debug-image=//'`" ;;
253 -f | --force)
254 setup_force="--force" ;;
257 gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2
258 usage
259 exit 1
262 if test "x$install_device" != x; then
263 gettext "More than one install device?" 1>&2
264 echo 1>&2
265 usage
266 exit 1
268 install_device="${option}" ;;
269 esac
270 done
272 if [ x$source_dir = x ]; then
273 if [ x$target = x ]; then
274 case x"`uname -m`" in
275 x"powerpc"* | x"ppc"*)
276 target="powerpc-ieee1275";;
277 x"sparc"*)
278 target="sparc64-ieee1275";;
279 x"mips"*"el")
280 target="mipsel-loongson";;
281 x"mips"*)
282 target="mips-arc";;
283 x"ia64"*)
284 target="ia64-efi";;
285 x"x86_64"* | x"amd64"*)
286 # On Linux, we need the efivars kernel modules.
287 # If no EFI is available this module just does nothing
288 # besides a small hello and if we detect efi we'll load it
289 # anyway later. So it should be safe to
290 # try to load it here.
291 case "$host_os" in
292 linux*)
293 modprobe -q efivars 2>/dev/null || true ;;
294 esac
295 if [ -d /sys/firmware/efi ]; then
296 target="x86_64-efi"
297 else
298 target=i386-pc
301 x"i"?"86"*)
302 # On Linux, we need the efivars kernel modules.
303 # If no EFI is available this module just does nothing
304 # besides a small hello and if we detect efi we'll load it
305 # anyway later. So it should be safe to
306 # try to load it here.
307 case "$host_os" in
308 linux*)
309 modprobe -q efivars 2>/dev/null || true ;;
310 esac
311 if [ -d /sys/firmware/efi ]; then
312 target="i386-efi"
313 elif [ -e /proc/device-tree ]; then
314 target=i386-pc
315 for x in /proc/device-tree/*; do
316 if [ -e "$x" ]; then
317 target="i386-ieee1275"
319 done
320 else
321 target=i386-pc
325 gettext "Unable to determine your platform. Use --target." ;
326 echo ;;
327 esac
329 source_dir="${libdir}/@PACKAGE@/$target"
332 if ! [ -d "$source_dir" ]; then
333 gettext_printf "%s doesn't exist. Please specify --target or --directory\\n" "source_dir"
334 exit 1
337 . "${source_dir}"/modinfo.sh
339 if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] ; then
340 if [ x$disk_module = xunspecified ]; then
341 disk_module=biosdisk
343 elif [ "${grub_modinfo_platform}" = "ieee1275" ] || [ "${grub_modinfo_platform}" = "efi" ] || [ "${grub_modinfo_platform}" = "arc" ] ; then
344 disk_module=
345 else
346 disk_module=native
349 if test "x$grub_setup" = x && [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ]; then
350 grub_setup="${sbindir}/`echo grub-bios-setup | sed ${transform}`"
353 if test "x$grub_setup" = x && [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "sparc64-ieee1275" ]; then
354 grub_setup="${sbindir}/`echo grub-sparc64-setup | sed ${transform}`"
357 if test "x$install_device" = x && ([ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] \
358 || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "sparc64-ieee1275" ]); then
359 gettext "Install device isn't specified." 1>&2
360 echo 1>&2
361 usage
362 exit 1
365 if ! ([ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] \
366 || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "sparc64-ieee1275" ] \
367 || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "powerpc-ieee1275" ] \
368 || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "mips-arc" ]); then
369 install_device=
372 # If the debugging feature is enabled, print commands.
373 setup_verbose=
374 if test x"$debug" = xyes; then
375 set -x
376 setup_verbose="--verbose"
377 efi_quiet=-q
380 if [ -z "$bootdir" ]; then
381 # Default bootdir if bootdir not initialized.
382 bootdir="/@bootdirname@"
384 if [ -n "$rootdir" ] ; then
385 # Initialize bootdir if rootdir was initialized.
386 bootdir="${rootdir}/@bootdirname@"
390 grubdir="`echo "${bootdir}/@grubdirname@" | sed 's,//*,/,g'`"
391 device_map="${grubdir}/device.map"
394 # Check if GRUB is installed.
395 if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "sparc64-ieee1275" ] ; then
396 set $grub_setup dummy
397 if test -f "$1"; then
399 else
400 echo "$1: Not found." 1>&2
401 exit 1
405 set "$grub_mkimage" dummy
406 if test -f "$1"; then
408 else
409 echo "$1: Not found." 1>&2
410 exit 1
413 if [ x"$grub_modinfo_platform" = xefi ]; then
414 # Find the EFI System Partition.
415 if test -n "$efidir"; then
416 install_device="`"$grub_probe" --target=device --device-map= "${efidir}"`"
417 else
418 if test -d "${bootdir}/efi"; then
419 install_device="`"$grub_probe" --target=device --device-map= "${bootdir}/efi"`"
420 # Is it a mount point?
421 if test "x$install_device" != "x`"$grub_probe" --target=device --device-map= "${bootdir}"`"; then
422 efidir="${bootdir}/efi"
424 elif test -d "${bootdir}/EFI"; then
425 install_device="`"$grub_probe" --target=device --device-map= "${bootdir}/EFI"`"
426 # Is it a mount point?
427 if test "x$install_device" != "x`"$grub_probe" --target=device --device-map= "${bootdir}"`"; then
428 efidir="${bootdir}/EFI"
430 elif test -n "$rootdir" && test "x$rootdir" != "x/"; then
431 # The EFI System Partition may have been given directly using
432 # --root-directory.
433 install_device="`"$grub_probe" --target=device --device-map= "${rootdir}"`"
434 # Is it a mount point?
435 if test "x$install_device" != "x`"$grub_probe" --target=device --device-map= "${rootdir}/.."`"; then
436 efidir="${rootdir}"
440 if test -n "$efidir"; then
441 efi_fs=`"$grub_probe" --target=fs "--device-map=${device_map}" "${efidir}"`
442 if test "x$efi_fs" = xfat; then :; else
443 gettext_printf "%s doesn't look like an EFI partition.\n" "${efidir}" 1>&2
444 efidir=
449 if test -n "$efidir"; then
450 # The EFI specification requires that an EFI System Partition must
451 # contain an "EFI" subdirectory, and that OS loaders are stored in
452 # subdirectories below EFI. Vendors are expected to pick names that do
453 # not collide with other vendors. To minimise collisions, we use the
454 # name of our distributor if possible.
455 efi_distributor="$bootloader_id"
456 if test $removable = yes; then
457 # The specification makes stricter requirements of removable
458 # devices, in order that only one image can be automatically loaded
459 # from them. The image must always reside under /EFI/BOOT, and it
460 # must have a specific file name depending on the architecture.
461 efi_distributor=BOOT
462 case "$grub_modinfo_target_cpu" in
463 i386)
464 efi_file=BOOTIA32.EFI ;;
465 x86_64)
466 efi_file=BOOTX64.EFI ;;
467 # GRUB does not yet support these architectures, but they're defined
468 # by the specification so we include them here to ease future
469 # expansion.
470 ia64)
471 efi_file=BOOTIA64.EFI ;;
472 esac
473 else
474 # It is convenient for each architecture to have a different
475 # efi_file, so that different versions can be installed in parallel.
476 case "$grub_modinfo_target_cpu" in
477 i386)
478 efi_file=grubia32.efi ;;
479 x86_64)
480 efi_file=grubx64.efi ;;
481 # GRUB does not yet support these architectures, but they're defined
482 # by the specification so we include them here to ease future
483 # expansion.
484 ia64)
485 efi_file=grubia64.efi ;;
487 efi_file=grub.efi ;;
488 esac
489 # TODO: We should also use efibootmgr, if available, to add a Boot
490 # entry for ourselves.
492 efidir="$efidir/EFI/$efi_distributor"
493 mkdir -p "$efidir" || exit 1
494 else
495 # We don't know what's going on. Fall back to traditional
496 # (non-specification-compliant) behaviour.
497 efidir="$grubdir"
498 efi_distributor=
499 efi_file=grub.efi
503 # Create the GRUB directory if it is not present.
504 mkdir -p "$grubdir" || exit 1
505 mkdir -p "$grubdir/${grub_modinfo_target_cpu}-$grub_modinfo_platform" || exit 1
507 # If --recheck is specified, remove the device map, if present.
508 if test $recheck = yes; then
509 rm -f "$device_map"
512 # Create the device map file if it is not present.
513 if test -f "$device_map"; then
514 # Make sure that there is no duplicated entry.
515 tmp=`sed -n '/^([fh]d[0-9]*)/s/\(^(.*)\).*/\1/p' "$device_map" \
516 | sort | uniq -d | sed -n 1p`
517 if test -n "$tmp"; then
518 gettext_printf "The drive %s is defined multiple times in the device map %s\n" "$tmp" "$device_map" 1>&2
519 exit 1
521 else
522 device_map=
525 # Copy the GRUB images to the GRUB directory.
526 for file in "${grubdir}"/*.mod "${grubdir}"/*.lst "${grubdir}"/*.img "${grubdir}"/efiemu??.o "${grubdir}"/${grub_modinfo_target_cpu}-$grub_modinfo_platform/*.mod "${grubdir}"/${grub_modinfo_target_cpu}-$grub_modinfo_platform/*.lst "${grubdir}"/${grub_modinfo_target_cpu}-$grub_modinfo_platform/*.img "${grubdir}"/${grub_modinfo_target_cpu}-$grub_modinfo_platform/efiemu??.o; do
527 if test -f "$file" && [ "`basename $file`" != menu.lst ]; then
528 rm -f "$file" || exit 1
530 done
531 for file in "${source_dir}"/*.mod "${source_dir}"/*.lst; do
532 cp -f "$file" "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform" || exit 1
533 done
534 if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "sparc64-ieee1275" ] ; then
535 for file in "${source_dir}"/*.img "${source_dir}"/efiemu??.o; do
536 if test -f "$file"; then
537 cp -f "$file" "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform" || exit 1
539 done
542 # Copy gettext files
543 mkdir -p "${grubdir}"/locale/
544 for dir in "${localedir}"/*; do
545 if test -f "$dir/LC_MESSAGES/grub.mo"; then
546 cp -f "$dir/LC_MESSAGES/grub.mo" "${grubdir}/locale/${dir##*/}.mo"
548 done
550 if test -f "${pkgdatadir}"/themes/starfield/theme.txt; then
551 mkdir -p "${grubdir}"/themes/starfield
552 cp "${pkgdatadir}"/themes/starfield/* "${grubdir}"/themes/starfield
555 if test -f "${pkgdatadir}"/unicode.pf2; then
556 mkdir -p "${grubdir}"/fonts
557 cp "${pkgdatadir}"/unicode.pf2 "${grubdir}"/fonts
560 if ! is_path_readable_by_grub "${grubdir}"; then
561 gettext_printf "Path \`%s' is not readable by GRUB on boot. Installation is impossible. Aborting.\n" "${grubdir}" 1>&2
562 exit 1
565 # Write device to a variable so we don't have to traverse /dev every time.
566 grub_device="`"$grub_probe" --device-map="${device_map}" --target=device "${grubdir}"`" || exit 1
568 if ! test -f "${grubdir}"/grubenv; then
569 "$grub_editenv" "${grubdir}"/grubenv create
572 # Create the core image. First, auto-detect the filesystem module.
573 fs_module="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=fs --device `"
574 if test "x$fs_module" = x ; then
575 gettext_printf "Auto-detection of a filesystem of %s failed.\n" "${grub_device}" 1>&2
576 gettext "Try with --recheck." 1>&2
577 echo 1>&2
578 gettext_printf "If the problem persists please report this together with the output of %s to <%s>" "\"$grub_probe --device-map=\"${device_map}\" --target=fs -v ${grubdir}\"" "bug-grub@gnu.org" 1>&2
579 exit 1
582 # Then the partition map module. In order to support partition-less media,
583 # this command is allowed to fail (--target=fs already grants us that the
584 # filesystem will be accessible).
585 partmap_module=
586 for x in `echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=partmap --device 2> /dev/null`; do
587 case "$x" in
588 netbsd | openbsd)
589 partmap_module="$partmap_module part_bsd";;
590 "") ;;
592 partmap_module="$partmap_module part_$x";;
593 esac
594 done
596 # Device abstraction module, if any (lvm, raid).
597 devabstraction_module="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=abstraction --device`"
599 if [ "x$disk_module" = xata ]; then
600 disk_module=pata
603 if [ "x$disk_module" = xnative ]; then
604 disk_module="pata ahci ohci"
605 if [ "x$grub_modinfo_target_cpu" = "xi386" ] || [ "x$grub_modinfo_target_cpu" = "xx86_64" ]; then
606 disk_module="$disk_module uhci"
608 disk_module="$disk_module usbms"
611 # The order in this list is critical. Be careful when modifying it.
612 modules="$modules $disk_module"
613 modules="$modules $fs_module $partmap_module $devabstraction_module"
615 relative_grubdir="`"$grub_mkrelpath" "${grubdir}"`" || exit 1
616 if [ "x${relative_grubdir}" = "x" ] ; then
617 relative_grubdir=/
620 prefix_drive=
621 config_opt_file=
623 rm -f "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
625 if [ "x${debug_image}" != x ]; then
626 echo "set debug='${debug_image}'" >> "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
627 config_opt_file="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
630 if [ "x${devabstraction_module}" = "x" ] ; then
631 if [ x"${install_device}" != x ]; then
632 if echo "${install_device}" | grep -qx "(.*)" ; then
633 install_drive="${install_device}"
634 else
635 install_drive="`"$grub_probe" --device-map="${device_map}" --target=drive --device "${install_device}"`" || exit 1
637 install_drive="`echo "${install_drive}" | sed -e 's/^(\(\([^,\\\\]\|\\\\\\\\\|\\\\,\)*\)\(\(,[a-zA-Z0-9]*\)*\))$/\1/'`"
639 grub_drive="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=drive --device`" || exit 1
641 # Strip partition number
642 grub_partition="`echo "${grub_drive}" | sed -e 's/^(\(\([^,\\\\]\|\\\\\\\\\|\\\\,\)*\)\(\(,[a-zA-Z0-9]*\)*\))$/\3/'`"
643 grub_drive="`echo "${grub_drive}" | sed -e 's/^(\(\([^,\\\\]\|\\\\\\\\\|\\\\,\)*\)\(\(,[a-zA-Z0-9]*\)*\))$/\1/'`"
645 if [ x"${install_device}" = x ] && [ x"${grub_modinfo_target_cpu}-$grub_modinfo_platform" = x"powerpc-ieee1275" ]; then
646 install_drive="$grub_drive"
649 if ([ "x$disk_module" != x ] && [ "x$disk_module" != xbiosdisk ]) || [ "x${grub_drive}" != "x${install_drive}" ] || ([ "x$grub_modinfo_platform" != xefi ] && [ "x$grub_modinfo_platform" != xpc ] && [ x"${grub_modinfo_platform}" != x"ieee1275" ]); then
650 # generic method (used on coreboot and ata mod)
651 uuid=
652 if [ x"$force_file_id" != xy ]; then
653 uuid="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=fs_uuid --device`"
656 if [ x"$disk_module" != x ] && [ x"$disk_module" != xbiosdisk ]; then
657 hints="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=baremetal_hints --device`"
658 elif [ x"$grub_modinfo_platform" = xpc ]; then
659 hints="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=bios_hints --device`"
660 elif [ x"$grub_modinfo_platform" = xefi ]; then
661 hints="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=efi_hints --device`"
662 elif [ x"$grub_modinfo_platform" = xieee1275 ]; then
663 hints="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=ieee1275_hints --device`"
664 elif [ x"$grub_modinfo_platform" = xloongson ] || [ x"$grub_modinfo_platform" = xqemu ] || [ x"$grub_modinfo_platform" = xcoreboot ] || [ x"$grub_modinfo_platform" = xmultiboot ] || [ x"$grub_modinfo_platform" = xqemu-mips ]; then
665 hints="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=baremetal_hints --device`"
666 else
667 gettext "No hints available for your platform. Expect reduced performance." 1>&2
668 echo 1>&2
669 hints=
671 if [ x"$uuid" != x ]; then
672 echo "search.fs_uuid ${uuid} root $hints " >> "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
673 search_module=search_fs_uuid
674 else
675 mkdir -p "${grubdir}/uuid"
676 file="`mktemp "${grubdir}/uuid/XXXXXXXXXXXXXXXXXXXXXXXXX"`"
677 relfile="`${grub_mkrelpath} "$file"`"
678 echo "search.file '${relfile}' root $hints " >> "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
679 search_module=search_fs_file
681 echo 'set prefix=($root)'"$(echo "${relative_grubdir}" | sed "s,\\([ \"'\\\\]\\),\\\\\\1,g")" >> "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
682 config_opt_file="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
683 modules="$modules $search_module"
684 else
685 # we need to hardcode the partition number in the core image's prefix.
686 if [ x"$grub_partition" = x ]; then
687 prefix_drive="()"
688 else
689 # Comma is already there
690 prefix_drive="($grub_partition)"
693 else
694 if [ x$GRUB_CRYPTODISK_ENABLE = xy ]; then
695 for uuid in "`echo "${grub_device}" | xargs "${grub_probe}" --target=cryptodisk_uuid --device`"; do
696 echo "cryptomount -u $uuid" >> "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
697 done
698 config_opt_file="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
701 prefix_drive=`"$grub_probe" --device-map="${device_map}" --target=drive --device "${grub_device}"` || exit 1
704 case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
705 sparc64-ieee1275) mkimage_target=sparc64-ieee1275-raw ;;
706 mipsel-loongson) mkimage_target=mipsel-loongson-elf ;;
707 *) mkimage_target="${grub_modinfo_target_cpu}-${grub_modinfo_platform}" ;;
708 esac
710 case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
711 i386-efi | x86_64-efi) imgext=efi ;;
712 mipsel-loongson | i386-coreboot | i386-multiboot | i386-ieee1275 \
713 | powerpc-ieee1275) imgext=elf ;;
714 *) imgext=img ;;
715 esac
717 if [ x"$config_opt_file" = x ]; then
718 "$grub_mkimage" -d "${source_dir}" -O "${mkimage_target}" --output="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" --prefix="${prefix_drive}${relative_grubdir}" $modules || exit 1
719 else
720 "$grub_mkimage" -c "${config_opt_file}" -d "${source_dir}" -O "${mkimage_target}" --output="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" --prefix="${prefix_drive}${relative_grubdir}" $modules || exit 1
723 # Backward-compatibility kludges
724 if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "mipsel-loongson" ]; then
725 cp "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" "${bootdir}"/grub.elf
726 elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-ieee1275" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "powerpc-ieee1275" ]; then
727 cp "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" "${grubdir}/grub"
728 elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-efi" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "x86_64-efi" ]; then
730 if [ x"$config_opt_file" = x ]; then
731 "$grub_mkimage" -d "${source_dir}" -O "${mkimage_target}" --output="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/grub.efi" --prefix="" $modules || exit 1
732 else
733 "$grub_mkimage" -c "${config_opt_file}" -d "${source_dir}" -O "${mkimage_target}" --output="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/grub.efi" --prefix="" $modules || exit 1
738 # Perform the grub_modinfo_platform-dependent install
739 if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "sparc64-ieee1275" ] ; then
740 # Now perform the installation.
741 "$grub_setup" ${allow_floppy} ${setup_verbose} ${setup_force} --directory="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform" \
742 --device-map="${device_map}" "${install_device}" || exit 1
743 elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-ieee1275" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "powerpc-ieee1275" ]; then
745 # If a install device is defined, copy the core.elf to PReP partition.
746 if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "powerpc-ieee1275" ] && [ -n "${install_device}" ]; then
747 if [ "$("${grub_probe}" -m "${device_map}" -d "${install_device}" -t msdos_parttype)" != "41" ]; then
748 gettext "The chosen partition is not a PReP partition." 1>&2
749 echo 1>&2
750 exit 1
753 if [ "$(file -s "${install_device}" -b | awk '{ print $1 }')" = ELF ] || [ x$("${grub_probe}" -m "${device_map}" -d "${install_device}" -t zero_check) = xtrue ]; then
754 dd if="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" of="${install_device}" status=noxfer || {
755 gettext "Failed to copy Grub to the PReP partition." 1>&2
756 echo 1>&2
757 exit 1
759 else
760 gettext "The PReP partition is not empty. If you are sure you want to use it, run dd to clear it:" 1>&2
761 echo 1>&2
762 echo " dd if=/dev/zero of=${install_device}"
763 exit 1
767 if [ x"$update_nvram" = xyes ]; then
768 ofpathname="`which ofpathname`"
769 nvsetenv="`which nvsetenv`"
770 set "$ofpathname" dummy
771 if test -f "$1"; then
773 else
774 echo "$1: Not found." 1>&2
775 exit 1
777 set "$nvsetenv" dummy
778 if test -f "$1"; then
780 else
781 echo "$1: Not found." 1>&2
782 exit 1
784 if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" != "powerpc-ieee1275" ] \
785 || [ -z "${install_device}" ]; then
786 # Get the Open Firmware device tree path translation.
787 dev="`echo $grub_device | sed -e 's/\/dev\///' -e 's/[0-9]\+//'`"
788 partno="`echo $grub_device | sed -e 's/.*[^0-9]\([0-9]\+\)$/\1/'`"
789 ofpath="`$ofpathname $dev`" || {
790 # TRANSLATORS: "device tree path" is the name of the device
791 # for IEEE1275
792 gettext_printf "Couldn't find IEEE1275 device tree path for %s.\nYou will have to set \`boot-device' variable manually.\n" "$dev" 1>&2
793 exit 1
796 # Point boot-device at the new grub install
797 boot_device="$ofpath:$partno,"`"$grub_mkrelpath" "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" | sed 's,/,\\\\,g'`
799 else
801 dev="`echo "${install_device}" | sed -e 's/\/dev\///' -e 's/[0-9]\+//'`"
802 boot_device="`$ofpathname "$dev"`" || {
803 # TRANSLATORS: "device tree path" is the name of the device
804 # for IEEE1275
805 gettext_printf "Couldn't find IEEE1275 device tree path for %s.\nYou will have to set \`boot-device' variable manually.\n" "$dev" 1>&2
806 exit 1
810 "$nvsetenv" boot-device "$boot_device" || {
811 # TRANSLATORS: The %s will be replaced by an external program name.
812 gettext_printf "\`%s' failed.\n" "$nvsetenv" 1>&2
813 gettext "You will have to set \`boot-device' variable manually. At the IEEE1275 prompt, type:" 1>&2
814 echo 1>&2
815 echo " setenv boot-device $boot_device" 1>&2
816 exit 1
819 elif [ x"${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = xmips-arc ]; then
820 dvhtool -d "${install_device}" --unix-to-vh "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" grub
821 gettext "You will have to set \`SystemPartition' and \`OSLoader' manually." 1>&2
822 echo 1>&2
823 elif [ x"$grub_modinfo_platform" = xefi ]; then
824 cp "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" "${efidir}/${efi_file}"
825 # For old macs. Suggested by Peter Jones.
826 if [ x$grub_modinfo_target_cpu = xi386 ]; then
827 cp "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" "${efidir}/boot.efi"
830 # Try to make this image bootable using the EFI Boot Manager, if available.
831 efibootmgr="`which efibootmgr`"
832 if test "$removable" = no && test -n "$efi_distributor" && \
833 test -n "$efibootmgr"; then
834 # On Linux, we need the efivars kernel modules.
835 case "$host_os" in
836 linux*)
837 modprobe -q efivars 2>/dev/null || true ;;
838 esac
840 # Delete old entries from the same distributor.
841 for bootnum in `efibootmgr | grep '^Boot[0-9]' | \
842 fgrep -i " $efi_distributor" | cut -b5-8`; do
843 efibootmgr $efi_quiet -b "$bootnum" -B
844 done
846 # Add a new entry for the image we just created. efibootmgr needs to be
847 # given the disk device and partition number separately, so we have to
848 # fiddle about with grub-probe to get hold of this reasonably reliably.
849 # Use fresh device map text to avoid any problems with stale data, since
850 # all we need here is a one-to-one mapping.
851 efidir_drive="$("$grub_probe" --target=drive --device-map= "$efidir")"
852 efidir_disk="$("$grub_probe" --target=disk --device-map= "$efidir")"
853 if test -z "$efidir_drive" || test -z "$efidir_disk"; then
854 gettext_printf "Can't find GRUB drive for %s; unable to create EFI Boot Manager entry.\n" "$efidir" >&2
855 else
856 efidir_part="$(echo "$efidir_drive" | sed 's/^([^,]*,[^0-9]*//; s/[^0-9].*//')"
857 efibootmgr $efi_quiet -c -d "$efidir_disk" -p "$efidir_part" -w \
858 -L "$bootloader_id" -l "\\EFI\\$efi_distributor\\$efi_file"
861 else
862 gettext "WARNING: no platform-specific install was performed" 1>&2
863 echo 1>&2
866 gettext "Installation finished. No error reported." 1>&2
867 echo 1>&2
869 # Bye.
870 exit 0