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@"
23 exec_prefix
="@exec_prefix@"
24 datarootdir
="@datarootdir@"
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@"
40 if [ "x$pkgdatadir" = x
]; then
41 pkgdatadir
="${datadir}/@PACKAGE@"
43 localedir
="@datadir@/locale"
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}`"
53 grubdir
="`echo "/@bootdirname@
/@grubdirname@
" | sed 's,//*,/,g'`"
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
77 disk_module
=unspecified
79 .
"${pkgdatadir}/grub-mkconfig_lib"
84 # TRANSLATORS: INSTALL_DEVICE isn't an identifier and is the DEVICE you
86 gettext_printf
"Usage: %s [OPTION] [INSTALL_DEVICE]" "$self"
88 gettext "Install GRUB on your drive." ; 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.
")"
116 gettext "INSTALL_DEVICE must be system device filename.";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
122 gettext "Report bugs to <bug-grub@gnu.org>."; echo
129 if test $# -eq 0; then
130 gettext_printf
"%s: option requires an argument -- \`%s'\n" "$0" "$opt" 1>&2
140 # Check the arguments.
151 echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
155 modules
=`argument $option "$@"`; shift;;
157 modules
=`echo "$option" | sed 's/--modules=//'` ;;
162 # Accept and ignore for compatibility
168 # Accept for compatibility
170 rootdir
="`argument $option "$@
"`"; shift;;
172 rootdir
="`echo "$option" | sed 's/--root-directory=//'`" ;;
175 bootdir
="`argument $option "$@
"`"; shift;;
177 bootdir
="`echo "$option" | sed 's/--boot-directory=//'`" ;;
180 efidir
="`argument $option "$@
"`"; shift;;
182 efidir
="`echo "$option" | sed 's/--efi-directory=//'`" ;;
185 source_dir
="`argument $option "$@
"`"; shift;;
187 source_dir
="`echo "$option" | sed 's/--directory=//'`" ;;
190 target
="`argument $option "$@
"`"; shift;;
192 target
="`echo "$option" | sed 's/--target=//'`" ;;
195 grub_setup
="`argument "$option" "$@
"`"; shift;;
197 grub_setup
="`echo "$option" | sed 's/--grub-setup=//'`" ;;
200 bootloader_id
="`argument $option "$@
"`"; shift;;
202 bootloader_id
="`echo "$option" | sed 's/--bootloader-id=//'`" ;;
205 grub_mkimage
="`argument $option "$@
"`"; shift;;
207 grub_mkimage
="`echo "$option" | sed 's/--grub-mkimage=//'`" ;;
210 grub_mkrelpath
="`argument "$option" "$@
"`"; shift;;
212 grub_mkrelpath
="`echo "$option" | sed 's/--grub-mkrelpath=//'`" ;;
214 # Ignore: for compatibility
217 --grub-mkdevicemap=*)
221 grub_probe
="`argument "$option" "$@
"`"; shift;;
223 grub_probe
="`echo "$option" | sed 's/--grub-probe=//'`" ;;
233 allow_floppy
="--allow-floppy" ;;
236 disk_module
="`argument "$option" "$@
"`"; shift;
239 disk_module
="`echo "$option" | sed 's/--disk-module=//'`"
245 # This is an undocumented feature...
249 debug_image
="`argument "$option" "$@
"`"; shift;;
251 debug_image
="`echo "$option" | sed 's/--debug-image=//'`" ;;
254 setup_force
="--force" ;;
257 gettext_printf
"Unrecognized option \`%s'\n" "$option" 1>&2
262 if test "x$install_device" != x
; then
263 gettext "More than one install device?" 1>&2
268 install_device
="${option}" ;;
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";;
278 target
="sparc64-ieee1275";;
280 target
="mipsel-loongson";;
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.
293 modprobe
-q efivars
2>/dev
/null || true
;;
295 if [ -d /sys
/firmware
/efi
]; then
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.
309 modprobe
-q efivars
2>/dev
/null || true
;;
311 if [ -d /sys
/firmware
/efi
]; then
313 elif [ -e /proc
/device-tree
]; then
315 for x
in /proc
/device-tree
/*; do
317 target
="i386-ieee1275"
325 gettext "Unable to determine your platform. Use --target." ;
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"
337 .
"${source_dir}"/modinfo.sh
339 if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] ; then
340 if [ x
$disk_module = xunspecified
]; then
343 elif [ "${grub_modinfo_platform}" = "ieee1275" ] || [ "${grub_modinfo_platform}" = "efi" ] || [ "${grub_modinfo_platform}" = "arc" ] ; then
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
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
372 # If the debugging feature is enabled, print commands.
374 if test x
"$debug" = xyes
; then
376 setup_verbose
="--verbose"
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
400 echo "$1: Not found." 1>&2
405 set "$grub_mkimage" dummy
406 if test -f "$1"; then
409 echo "$1: Not found." 1>&2
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}"`"
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
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
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
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.
462 case "$grub_modinfo_target_cpu" in
464 efi_file
=BOOTIA32.EFI
;;
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
471 efi_file
=BOOTIA64.EFI
;;
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
478 efi_file
=grubia32.efi
;;
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
485 efi_file
=grubia64.efi
;;
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
495 # We don't know what's going on. Fall back to traditional
496 # (non-specification-compliant) behaviour.
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
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
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
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
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
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
"
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
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
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
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).
586 for x in `echo "${grub_device}" |
xargs "$grub_probe" --device-map="${device_map}" --target=partmap
--device 2> /dev
/null
`; do
589 partmap_module="$partmap_module part_bsd";;
592 partmap_module="$partmap_module part_$x";;
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
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
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}"
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)
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`"
667 gettext "No hints available for your platform. Expect reduced performance." 1>&2
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
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"
685 # we need to hardcode the partition number in the core image's prefix.
686 if [ x"$grub_partition" = x ]; then
689 # Comma is already there
690 prefix_drive="($grub_partition)"
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"
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}" ;;
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 ;;
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
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
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
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
760 gettext "The PReP partition is not empty. If you are sure you want to use it, run dd to clear it:" 1>&2
762 echo " dd if=/dev/zero of=${install_device}"
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
774 echo "$1: Not found." 1>&2
777 set "$nvsetenv" dummy
778 if test -f "$1"; then
781 echo "$1: Not found." 1>&2
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
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
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
'`
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
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
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
815 echo " setenv boot-device
$boot_device" 1>&2
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
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.
837 modprobe -q efivars 2>/dev/null || true ;;
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
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
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"
862 gettext "WARNING
: no platform-specific
install was performed
" 1>&2
866 gettext "Installation finished. No error reported.
" 1>&2