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.
21 exec_prefix
="@exec_prefix@"
22 datarootdir
="@datarootdir@"
26 sysconfdir
="@sysconfdir@"
27 PACKAGE_NAME
=@PACKAGE_NAME@
28 PACKAGE_TARNAME
=@PACKAGE_TARNAME@
29 PACKAGE_VERSION
=@PACKAGE_VERSION@
31 export TEXTDOMAIN
=@PACKAGE@
32 export TEXTDOMAINDIR
="@localedir@"
38 if [ "x$pkgdatadir" = x
]; then
39 pkgdatadir
="${datadir}/@PACKAGE@"
41 localedir
="@datadir@/locale"
45 grub_mkimage
="${bindir}/@grub_mkimage@"
46 grub_probe
="${sbindir}/@grub_probe@"
47 grub_editenv
="${bindir}/@grub_editenv@"
48 grub_mkrelpath
="${bindir}/@grub_mkrelpath@"
51 grubdir
="`echo "/@bootdirname@
/@grubdirname@
" | sed 's,//*,/,g'`"
65 # Get GRUB_DISTRIBUTOR.
66 if test -f "${sysconfdir}/default/grub" ; then
67 .
"${sysconfdir}/default/grub"
70 bootloader_id
="$(echo "$GRUB_DISTRIBUTOR" | tr 'A-Z' 'a-z' | cut -d' ' -f1)"
71 if test -z "$bootloader_id"; then
75 disk_module
=unspecified
77 .
"${pkgdatadir}/grub-mkconfig_lib"
82 # TRANSLATORS: INSTALL_DEVICE isn't an identifier and is the DEVICE you
84 gettext_printf
"Usage: %s [OPTION] [INSTALL_DEVICE]" "$self"
86 gettext "Install GRUB on your drive." ; echo
88 print_option_help
"-h, --help" "$(gettext "print this message and
exit")"
89 print_option_help
"-v, --version" "$(gettext "print the version information and
exit")"
90 print_option_help
"--modules=$(gettext "MODULES
")" "$(gettext "pre-load specified modules MODULES
")"
91 grub_print_install_files_help
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. On some platforms, it
120 may also install GRUB into the boot sector.\n" "$self" "$grubdir";echo
122 gettext "Report bugs to <bug-grub@gnu.org>."; echo
129 # Check the arguments.
132 grub_process_install_options
"$@"
133 case "$grub_process_install_options_consumed" in
135 2) shift; shift; continue;;
146 echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
150 modules
=`argument $option "$@"`; shift;;
152 modules
=`echo "$option" | sed 's/--modules=//'` ;;
157 # Accept and ignore for compatibility
163 # Accept for compatibility
165 rootdir
="`argument $option "$@
"`"; shift;;
167 rootdir
="`echo "$option" | sed 's/--root-directory=//'`" ;;
170 bootdir
="`argument $option "$@
"`"; shift;;
172 bootdir
="`echo "$option" | sed 's/--boot-directory=//'`" ;;
175 efidir
="`argument $option "$@
"`"; shift;;
177 efidir
="`echo "$option" | sed 's/--efi-directory=//'`" ;;
180 source_dir
="`argument $option "$@
"`"; shift;;
182 source_dir
="`echo "$option" | sed 's/--directory=//'`" ;;
185 target
="`argument $option "$@
"`"; shift;;
187 target
="`echo "$option" | sed 's/--target=//'`" ;;
190 grub_setup
="`argument "$option" "$@
"`"; shift;;
192 grub_setup
="`echo "$option" | sed 's/--grub-setup=//'`" ;;
195 bootloader_id
="`argument $option "$@
"`"; shift;;
197 bootloader_id
="`echo "$option" | sed 's/--bootloader-id=//'`" ;;
200 grub_mkimage
="`argument $option "$@
"`"; shift;;
202 grub_mkimage
="`echo "$option" | sed 's/--grub-mkimage=//'`" ;;
205 grub_mkrelpath
="`argument "$option" "$@
"`"; shift;;
207 grub_mkrelpath
="`echo "$option" | sed 's/--grub-mkrelpath=//'`" ;;
209 # Ignore: for compatibility
212 --grub-mkdevicemap=*)
216 grub_probe
="`argument "$option" "$@
"`"; shift;;
218 grub_probe
="`echo "$option" | sed 's/--grub-probe=//'`" ;;
228 allow_floppy
="--allow-floppy" ;;
231 disk_module
="`argument "$option" "$@
"`"; shift;
234 disk_module
="`echo "$option" | sed 's/--disk-module=//'`"
240 # This is an undocumented feature...
244 debug_image
="`argument "$option" "$@
"`"; shift;;
246 debug_image
="`echo "$option" | sed 's/--debug-image=//'`" ;;
249 setup_force
="--force" ;;
252 gettext_printf
"Unrecognized option \`%s'\n" "$option" 1>&2
257 if test "x$install_device" != x
; then
258 gettext "More than one install device?" 1>&2
263 install_device
="${option}" ;;
267 if [ x
$source_dir = x
]; then
268 if [ x
$target = x
]; then
269 case x
"`uname -m`" in
270 x
"powerpc"* | x
"ppc"*)
271 target
="powerpc-ieee1275";;
273 target
="sparc64-ieee1275";;
275 target
="mipsel-loongson";;
280 x
"x86_64"* | x
"amd64"*)
281 # On Linux, we need the efivars kernel modules.
282 # If no EFI is available this module just does nothing
283 # besides a small hello and if we detect efi we'll load it
284 # anyway later. So it should be safe to
285 # try to load it here.
288 modprobe
-q efivars
2>/dev
/null || true
;;
290 if [ -d /sys
/firmware
/efi
]; then
297 # On Linux, we need the efivars kernel modules.
298 # If no EFI is available this module just does nothing
299 # besides a small hello and if we detect efi we'll load it
300 # anyway later. So it should be safe to
301 # try to load it here.
304 modprobe
-q efivars
2>/dev
/null || true
;;
306 if [ -d /sys
/firmware
/efi
]; then
308 elif [ -e /proc
/device-tree
]; then
310 for x
in /proc
/device-tree
/*; do
312 target
="i386-ieee1275"
320 gettext "Unable to determine your platform. Use --target." ;
324 source_dir
="${libdir}/@PACKAGE@/$target"
327 if ! [ -d "$source_dir" ]; then
328 gettext_printf
"%s doesn't exist. Please specify --target or --directory\\n" "$source_dir"
332 .
"${source_dir}"/modinfo.sh
334 if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] ; then
335 if [ x
$disk_module = xunspecified
]; then
338 elif [ "${grub_modinfo_platform}" = "ieee1275" ] || [ "${grub_modinfo_platform}" = "efi" ] || [ "${grub_modinfo_platform}" = "arc" ] ; then
344 if test "x$grub_setup" = x
&& [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ]; then
345 grub_setup
="${sbindir}/@grub_bios_setup@"
348 if test "x$grub_setup" = x
&& [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "sparc64-ieee1275" ]; then
349 grub_setup
="${sbindir}/@grub_sparc64_setup@"
352 if test "x$install_device" = x
&& ([ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] \
353 ||
[ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "sparc64-ieee1275" ]); then
354 gettext "Install device isn't specified." 1>&2
360 if ! ([ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] \
361 ||
[ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "sparc64-ieee1275" ] \
362 ||
[ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "powerpc-ieee1275" ] \
363 ||
[ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "mips-arc" ]); then
367 # If the debugging feature is enabled, print commands.
369 if test x
"$debug" = xyes
; then
371 setup_verbose
="--verbose"
375 if [ -z "$bootdir" ]; then
376 # Default bootdir if bootdir not initialized.
377 bootdir
="/@bootdirname@"
379 if [ -n "$rootdir" ] ; then
380 # Initialize bootdir if rootdir was initialized.
381 bootdir
="${rootdir}/@bootdirname@"
385 grubdir
="`echo "${bootdir}/@grubdirname@
" | sed 's,//*,/,g'`"
386 device_map
="${grubdir}/device.map"
389 # Check if GRUB is installed.
390 if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "sparc64-ieee1275" ] ; then
391 set $grub_setup dummy
392 if test -f "$1"; then
395 echo "$1: Not found." 1>&2
400 set "$grub_mkimage" dummy
401 if test -f "$1"; then
404 echo "$1: Not found." 1>&2
408 if [ x
"$grub_modinfo_platform" = xefi
]; then
409 # Find the EFI System Partition.
410 if test -n "$efidir"; then
411 install_device
="`"$grub_probe" --target=device --device-map= "${efidir}"`"
413 if test -d "${bootdir}/efi"; then
414 install_device
="`"$grub_probe" --target=device --device-map= "${bootdir}/efi
"`"
415 # Is it a mount point?
416 if test "x$install_device" != "x`"$grub_probe" --target=device --device-map= "${bootdir}"`"; then
417 efidir
="${bootdir}/efi"
419 elif test -d "${bootdir}/EFI"; then
420 install_device
="`"$grub_probe" --target=device --device-map= "${bootdir}/EFI
"`"
421 # Is it a mount point?
422 if test "x$install_device" != "x`"$grub_probe" --target=device --device-map= "${bootdir}"`"; then
423 efidir
="${bootdir}/EFI"
425 elif test -n "$rootdir" && test "x$rootdir" != "x/"; then
426 # The EFI System Partition may have been given directly using
428 install_device
="`"$grub_probe" --target=device --device-map= "${rootdir}"`"
429 # Is it a mount point?
430 if test "x$install_device" != "x`"$grub_probe" --target=device --device-map= "${rootdir}/..
"`"; then
435 if test -n "$efidir"; then
436 efi_fs
=`"$grub_probe" --target=fs "--device-map=${device_map}" "${efidir}"`
437 if test "x$efi_fs" = xfat
; then :; else
438 gettext_printf
"%s doesn't look like an EFI partition.\n" "${efidir}" 1>&2
444 if test -n "$efidir"; then
445 # The EFI specification requires that an EFI System Partition must
446 # contain an "EFI" subdirectory, and that OS loaders are stored in
447 # subdirectories below EFI. Vendors are expected to pick names that do
448 # not collide with other vendors. To minimise collisions, we use the
449 # name of our distributor if possible.
450 efi_distributor
="$bootloader_id"
451 if test $removable = yes; then
452 # The specification makes stricter requirements of removable
453 # devices, in order that only one image can be automatically loaded
454 # from them. The image must always reside under /EFI/BOOT, and it
455 # must have a specific file name depending on the architecture.
457 case "$grub_modinfo_target_cpu" in
459 efi_file
=BOOTIA32.EFI
;;
461 efi_file
=BOOTX64.EFI
;;
462 # GRUB does not yet support these architectures, but they're defined
463 # by the specification so we include them here to ease future
466 efi_file
=BOOTIA64.EFI
;;
469 # It is convenient for each architecture to have a different
470 # efi_file, so that different versions can be installed in parallel.
471 case "$grub_modinfo_target_cpu" in
473 efi_file
=grubia32.efi
;;
475 efi_file
=grubx64.efi
;;
476 # GRUB does not yet support these architectures, but they're defined
477 # by the specification so we include them here to ease future
480 efi_file
=grubia64.efi
;;
485 efidir
="$efidir/EFI/$efi_distributor"
486 mkdir
-p "$efidir" ||
exit 1
488 # We don't know what's going on. Fall back to traditional
489 # (non-specification-compliant) behaviour.
496 # Create the GRUB directory if it is not present.
497 mkdir
-p "$grubdir" ||
exit 1
498 mkdir
-p "$grubdir/${grub_modinfo_target_cpu}-$grub_modinfo_platform" ||
exit 1
500 # If --recheck is specified, remove the device map, if present.
501 if test $recheck = yes; then
505 # Device map file is optional
506 if test -f "$device_map"; then
507 # Make sure that there is no duplicated entry.
508 tmp
=`sed -n '/^([fh]d[0-9]*)/s/\(^(.*)\).*/\1/p' "$device_map" \
509 | sort | uniq -d | sed -n 1p`
510 if test -n "$tmp"; then
511 gettext_printf
"The drive %s is defined multiple times in the device map %s\n" "$tmp" "$device_map" 1>&2
518 # Copy the GRUB images to the GRUB directory.
519 grub_install_files
"${source_dir}" "${grubdir}" "${grub_modinfo_target_cpu}-$grub_modinfo_platform" all
521 if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "sparc64-ieee1275" ] ; then
522 for file in "${source_dir}"/*.img
"${source_dir}"/efiemu??.o
; do
523 if test -f "$file"; then
524 cp -f "$file" "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform" ||
exit 1
529 if ! is_path_readable_by_grub
"${grubdir}"; then
530 gettext_printf
"Path \`%s' is not readable by GRUB on boot. Installation is impossible. Aborting.\n" "${grubdir}" 1>&2
534 # Write device to a variable so we don't have to traverse /dev every time.
535 grub_device
="`"$grub_probe" --device-map="${device_map}" --target=device "${grubdir}"`" ||
exit 1
537 if ! test -f "${grubdir}"/grubenv
; then
538 "$grub_editenv" "${grubdir}"/grubenv create
541 # Create the core image. First, auto-detect the filesystem module.
542 fs_module
="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=fs --device `"
543 if test "x$fs_module" = x
; then
544 gettext_printf
"Auto-detection of a filesystem of %s failed.\n" "${grub_device}" 1>&2
545 gettext "Try with --recheck." 1>&2
547 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
551 # Then the partition map module. In order to support partition-less media,
552 # this command is allowed to fail (--target=fs already grants us that the
553 # filesystem will be accessible).
555 for x
in `echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=partmap --device 2> /dev/null`; do
558 partmap_module
="$partmap_module part_bsd";;
561 partmap_module
="$partmap_module part_$x";;
565 # Device abstraction module, if any (lvm, raid).
566 devabstraction_module
="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=abstraction --device`"
568 if [ "x$disk_module" = xata
]; then
572 if [ "x$disk_module" = xnative
]; then
573 disk_module
="pata ahci ohci"
574 if [ "x$grub_modinfo_target_cpu" = "xi386" ] ||
[ "x$grub_modinfo_target_cpu" = "xx86_64" ]; then
575 disk_module
="$disk_module uhci"
577 disk_module
="$disk_module usbms"
580 # The order in this list is critical. Be careful when modifying it.
581 modules
="$modules $disk_module"
582 modules
="$modules $fs_module $partmap_module $devabstraction_module"
584 relative_grubdir
="`"$grub_mkrelpath" "${grubdir}"`" ||
exit 1
585 if [ "x${relative_grubdir}" = "x" ] ; then
592 rm -f "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
594 if [ "x${debug_image}" != x
]; then
595 echo "set debug='${debug_image}'" >> "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
596 config_opt_file
="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
599 if [ "x${devabstraction_module}" = "x" ] ; then
600 if [ x
"${install_device}" != x
]; then
601 if echo "${install_device}" |
grep -qx "(.*)" ; then
602 install_drive
="${install_device}"
604 install_drive
="`"$grub_probe" --device-map="${device_map}" --target=drive --device "${install_device}"`" ||
exit 1
606 install_drive
="`echo "${install_drive}" | sed -e 's/^(\(\([^,\\\\]\|\\\\\\\\\|\\\\,\)*\)\(\(,[a-zA-Z0-9]*\)*\))$/\1/'`"
608 grub_drive
="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=drive --device`" ||
exit 1
610 # Strip partition number
611 grub_partition
="`echo "${grub_drive}" | sed -e 's/^(\(\([^,\\\\]\|\\\\\\\\\|\\\\,\)*\)\(\(,[a-zA-Z0-9]*\)*\))$/\3/'`"
612 grub_drive
="`echo "${grub_drive}" | sed -e 's/^(\(\([^,\\\\]\|\\\\\\\\\|\\\\,\)*\)\(\(,[a-zA-Z0-9]*\)*\))$/\1/'`"
614 if [ x
"${install_device}" = x
] && [ x
"${grub_modinfo_target_cpu}-$grub_modinfo_platform" = x
"powerpc-ieee1275" ]; then
615 install_drive
="$grub_drive"
618 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
619 # generic method (used on coreboot and ata mod)
621 if [ x
"$force_file_id" != xy
]; then
622 uuid
="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=fs_uuid --device`"
625 if [ x
"$disk_module" != x
] && [ x
"$disk_module" != xbiosdisk
]; then
626 hints
="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=baremetal_hints --device`"
627 elif [ x
"$grub_modinfo_platform" = xpc
]; then
628 hints
="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=bios_hints --device`"
629 elif [ x
"$grub_modinfo_platform" = xefi
]; then
630 hints
="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=efi_hints --device`"
631 elif [ x
"$grub_modinfo_platform" = xieee1275
]; then
632 hints
="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=ieee1275_hints --device`"
633 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
634 hints
="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=baremetal_hints --device`"
636 gettext "No hints available for your platform. Expect reduced performance." 1>&2
640 if [ x
"$uuid" != x
]; then
641 echo "search.fs_uuid ${uuid} root $hints " >> "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
642 search_module
=search_fs_uuid
644 mkdir
-p "${grubdir}/uuid"
645 file="`mktemp "${grubdir}/uuid
/XXXXXXXXXXXXXXXXXXXXXXXXX
"`"
646 relfile
="`${grub_mkrelpath} "$file"`"
647 echo "search.file '${relfile}' root $hints " >> "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
648 search_module
=search_fs_file
650 echo 'set prefix=($root)'"$(echo "${relative_grubdir}" | sed "s,\\([ \"'\\\\]\\),\\\\\\1,g")" >> "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg
"
651 config_opt_file="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg
"
652 modules="$modules $search_module"
654 # we need to hardcode the partition number in the core image's prefix.
655 if [ x"$grub_partition" = x ]; then
658 # Comma is already there
659 prefix_drive="($grub_partition)"
663 if [ x$GRUB_CRYPTODISK_ENABLE = xy ]; then
664 for uuid in "`echo "${grub_device}" | xargs "${grub_probe}" --target=cryptodisk_uuid --device`"; do
665 echo "cryptomount
-u $uuid" >> "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg
"
667 config_opt_file="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg
"
670 prefix_drive=`"$grub_probe" --device-map="${device_map}" --target=drive --device "${grub_device}"` || exit 1
673 case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
674 sparc64-ieee1275) mkimage_target=sparc64-ieee1275-raw ;;
675 mipsel-loongson) mkimage_target=mipsel-loongson-elf ;;
676 *) mkimage_target="${grub_modinfo_target_cpu}-${grub_modinfo_platform}" ;;
679 case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
680 i386-efi | x86_64-efi) imgext=efi ;;
681 mipsel-loongson | i386-coreboot | i386-multiboot | i386-ieee1275 \
682 | powerpc-ieee1275) imgext=elf ;;
686 if [ x"$config_opt_file" = x ]; then
687 "$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
689 "$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
692 # Backward-compatibility kludges
693 if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "mipsel-loongson
" ]; then
694 cp "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" "${bootdir}"/grub.elf
695 elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-ieee1275" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "powerpc-ieee1275
" ]; then
696 cp "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" "${grubdir}/grub
"
697 elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-efi" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "x86_64-efi
" ]; then
699 if [ x"$config_opt_file" = x ]; then
700 "$grub_mkimage" -d "${source_dir}" -O "${mkimage_target}" --output="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/grub.efi
" --prefix="" $modules || exit 1
702 "$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
707 # Perform the grub_modinfo_platform-dependent install
708 if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "sparc64-ieee1275
" ] ; then
709 # Now perform the installation.
710 "$grub_setup" ${allow_floppy} ${setup_verbose} ${setup_force} --directory="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform" \
711 --device-map="${device_map}" "${install_device}" ||
exit 1
712 elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-ieee1275" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "powerpc-ieee1275" ]; then
714 # If a install device is defined, copy the core.elf to PReP partition.
715 if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "powerpc-ieee1275" ] && [ -n "${install_device}" ]; then
716 if [ "$("${grub_probe}" -m "${device_map}" -d "${install_device}" -t msdos_parttype)" != "41" ]; then
717 gettext "The chosen partition is not a PReP partition." 1>&2
722 if [ "$(file -s -b -L "${install_device}" | awk '{ print $1 }')" = ELF ] || [ x$("${grub_probe}" -m "${device_map}" -d "${install_device}" -t zero_check) = xtrue ]; then
723 dd if="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" of="${install_device}" status=noxfer || {
724 gettext "Failed to copy Grub to the PReP partition.
" 1>&2
729 gettext "The PReP partition is not empty. If you are sure you want to use it
, run
dd to
clear it
:" 1>&2
731 echo " dd if=/dev
/zero of
=${install_device}"
736 if [ x"$update_nvram" = xyes ]; then
737 ofpathname="`which ofpathname`"
738 nvsetenv="`which nvsetenv`"
739 set "$ofpathname" dummy
740 if test -f "$1"; then
743 echo "$1: Not found.
" 1>&2
746 set "$nvsetenv" dummy
747 if test -f "$1"; then
750 echo "$1: Not found.
" 1>&2
753 if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" != "powerpc-ieee1275
" ] \
754 || [ -z "${install_device}" ]; then
755 # Get the Open Firmware device tree path translation.
756 dev="`echo $grub_device | sed -e 's/\/dev\///' -e 's/[0-9]\+//'`"
757 partno="`echo $grub_device | sed -e 's/.*[^0-9]\([0-9]\+\)$/\1/'`"
758 ofpath="`$ofpathname $dev`" || {
759 # TRANSLATORS: "device tree path
" is the name of the device
761 gettext_printf "Couldn
't find IEEE1275 device tree path for %s.\nYou will have to set \`boot-device' variable manually.
\n" "$dev" 1>&2
765 # Point boot-device at the new grub install
766 boot_device="$ofpath:$partno,"`"$grub_mkrelpath" "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" | sed 's,/,\\\\,g'`
770 dev="`echo "${install_device}" | sed -e 's/\/dev\///' -e 's/[0-9]\+//'`"
771 boot_device="`$ofpathname "$dev"`" || {
772 # TRANSLATORS: "device tree path
" is the name of the device
774 gettext_printf "Couldn
't find IEEE1275 device tree path for %s.\nYou will have to set \`boot-device' variable manually.
\n" "$dev" 1>&2
779 "$nvsetenv" boot-device "$boot_device" || {
780 # TRANSLATORS: The %s will be replaced by an external program name.
781 gettext_printf "\
`%s' failed.\n" "$nvsetenv" 1>&2
782 gettext "You will have to set \`boot-device
' variable manually. At the IEEE1275 prompt, type:" 1>&2
784 echo " setenv boot-device $boot_device" 1>&2
788 elif [ x"${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = xmips-arc ]; then
789 dvhtool -d "${install_device}" --unix-to-vh "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" grub
790 gettext "You will have to set \`SystemPartition' and \
`OSLoader' manually." 1>&2
792 elif [ x"$grub_modinfo_platform" = xefi ]; then
793 cp "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" "${efidir}/${efi_file}"
794 # For old macs. Suggested by Peter Jones.
795 if [ x$grub_modinfo_target_cpu = xi386 ]; then
796 cp "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" "${efidir}/boot.efi"
799 # Try to make this image bootable using the EFI Boot Manager, if available.
800 efibootmgr="`which efibootmgr
`"
801 if test "$removable" = no && test -n "$efi_distributor" && \
802 test -n "$efibootmgr"; then
803 # On Linux, we need the efivars kernel modules.
806 modprobe -q efivars 2>/dev/null || true ;;
809 # Delete old entries from the same distributor.
810 for bootnum in `efibootmgr |
grep '^Boot[0-9]' | \
811 fgrep
-i " $efi_distributor" | cut
-b5-8`; do
812 efibootmgr $efi_quiet -b "$bootnum" -B
815 # Add a new entry for the image we just created. efibootmgr needs to be
816 # given the disk device and partition number separately, so we have to
817 # fiddle about with grub-probe to get hold of this reasonably reliably.
818 # Use fresh device map text to avoid any problems with stale data, since
819 # all we need here is a one-to-one mapping.
820 efidir_drive="$("$grub_probe" --target=drive --device-map= "$efidir")"
821 efidir_disk="$("$grub_probe" --target=disk --device-map= "$efidir")"
822 if test -z "$efidir_drive" || test -z "$efidir_disk"; then
823 gettext_printf "Can't find GRUB drive for %s; unable to create EFI Boot Manager entry.\n" "$efidir" >&2
825 efidir_part="$(echo "$efidir_drive" | sed 's/^([^,]*,[^0-9]*//; s/[^0-9].*//')"
826 efibootmgr $efi_quiet -c -d "$efidir_disk" -p "$efidir_part" -w \
827 -L "$bootloader_id" -l "\\EFI\\$efi_distributor\\$efi_file"
831 gettext "WARNING: no platform-specific install was performed" 1>&2
835 gettext "Installation finished. No error reported." 1>&2