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@"
27 sysconfdir
="@sysconfdir@"
28 PACKAGE_NAME
=@PACKAGE_NAME@
29 PACKAGE_TARNAME
=@PACKAGE_TARNAME@
30 PACKAGE_VERSION
=@PACKAGE_VERSION@
31 target_cpu
=@target_cpu@
34 datarootdir
=@datarootdir@
35 pkglibdir
="${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`"
36 localedir
="@datadir@/locale"
40 grub_setup
="${sbindir}/`echo grub-setup | sed ${transform}`"
41 grub_mkimage
="${bindir}/`echo grub-mkimage | sed ${transform}`"
42 grub_mkdevicemap
="${sbindir}/`echo grub-mkdevicemap | sed ${transform}`"
43 grub_probe
="${sbindir}/`echo grub-probe | sed ${transform}`"
44 grub_editenv
="${bindir}/`echo grub-editenv | sed ${transform}`"
45 grub_mkrelpath
="${bindir}/`echo grub-mkrelpath | sed ${transform}`"
48 grubdir
="`echo "/@bootdirname@
/@grubdirname@
" | sed 's,//*,/,g'`"
63 # Get GRUB_DISTRIBUTOR.
64 if test -f "${sysconfdir}/default/grub" ; then
65 .
"${sysconfdir}/default/grub"
68 bootloader_id
="$(echo "$GRUB_DISTRIBUTOR" | tr 'A-Z' 'a-z' | cut -d' ' -f1)"
69 if test -z "$bootloader_id"; then
73 if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
75 elif [ "${platform}" = "ieee1275" ] ||
[ "${platform}" = "efi" ] ; then
84 if [ "${target_cpu}-${platform}" = "i386-pc" ] \
85 ||
[ "${target_cpu}-${platform}" = "sparc64-ieee1275" ]; then
87 Usage: $self [OPTION] install_device
91 Usage: $self [OPTION] [install_device]
95 Install GRUB on your drive.
97 -h, --help print this message and exit
98 -v, --version print the version information and exit
99 --modules=MODULES pre-load specified modules MODULES
100 --boot-directory=DIR install GRUB images under the directory DIR/@grubdirname@
101 instead of the $grubdir directory
102 --grub-setup=FILE use FILE as grub-setup
103 --grub-mkimage=FILE use FILE as grub-mkimage
104 --grub-mkrelpath=FILE use FILE as grub-mkrelpath
105 --grub-mkdevicemap=FILE use FILE as grub-mkdevicemap
106 --grub-probe=FILE use FILE as grub-probe
107 --no-floppy do not probe any floppy drive
108 --allow-floppy Make the drive also bootable as floppy
109 (default for fdX devices). May break on some BIOSes.
110 --recheck delete device map if it already exists
111 --force install even if problems are detected
113 if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
115 --disk-module=MODULE disk module to use (biosdisk or native)
118 if [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${platform}" = "powerpc-ieee1275" ] ; then
120 --no-nvram don't update the boot-device NVRAM variable
123 if [ "${platform}" = "efi" ]; then
125 --removable the installation device is removable
126 --bootloader-id=ID the ID of bootloader.
131 INSTALL_DEVICE can be a GRUB device name or a system device filename.
133 $self copies GRUB images into $grubdir, and uses grub-setup
134 to install grub into the boot sector.
136 Report bugs to <bug-grub@gnu.org>.
144 if test $# -eq 0; then
145 echo "$0: option requires an argument -- '$opt'" 1>&2
153 # Check the arguments.
164 echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
168 modules
=`argument $option "$@"`; shift;;
170 modules
=`echo "$option" | sed 's/--modules=//'` ;;
172 # Accept and ignore for compatibility
178 # Accept for compatibility
180 rootdir
="`argument $option "$@
"`"; shift;;
182 rootdir
="`echo "$option" | sed 's/--root-directory=//'`" ;;
185 bootdir
="`argument $option "$@
"`"; shift;;
187 bootdir
="`echo "$option" | sed 's/--boot-directory=//'`" ;;
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=//'`" ;;
210 grub_mkdevicemap
="`argument "$option" "$@
"`"; shift;;
211 --grub-mkdevicemap=*)
212 grub_mkdevicemap
="`echo "$option" | sed 's/--grub-mkdevicemap=//'`" ;;
215 grub_probe
="`argument "$option" "$@
"`"; shift;;
217 grub_probe
="`echo "$option" | sed 's/--grub-probe=//'`" ;;
220 no_floppy
="--no-floppy" ;;
227 allow_floppy
="--allow-floppy" ;;
230 if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
231 disk_module
="`argument "$option" "$@
"`"; shift;
234 if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
235 disk_module
="`echo "$option" | sed 's/--disk-module=//'`"
241 # This is an undocumented feature...
245 debug_image
="`argument "$option" "$@
"`"; shift;;
247 debug_image
="`echo "$option" | sed 's/--debug-image=//'`" ;;
250 setup_force
="--force" ;;
253 echo "Unrecognized option \`$option'" 1>&2
258 if test "x$install_device" != x
; then
259 echo "More than one install_devices?" 1>&2
263 install_device
="${option}" ;;
267 .
${libdir}/@PACKAGE@
/grub-mkconfig_lib
269 if test "x$install_device" = x
&& ([ "${target_cpu}-${platform}" = "i386-pc" ] \
270 ||
[ "${target_cpu}-${platform}" = "sparc64-ieee1275" ]); then
271 echo "install_device not specified." 1>&2
276 if ! ([ "${target_cpu}-${platform}" = "i386-pc" ] \
277 ||
[ "${target_cpu}-${platform}" = "sparc64-ieee1275" ]); then
281 # If the debugging feature is enabled, print commands.
283 if test x
"$debug" = xyes
; then
285 setup_verbose
="--verbose"
289 if [ -z "$bootdir" ]; then
290 # Default bootdir if bootdir not initialized.
291 bootdir
="/@bootdirname@"
293 if [ -n "$rootdir" ] ; then
294 # Initialize bootdir if rootdir was initialized.
295 bootdir
="${rootdir}/@bootdirname@"
299 grubdir
="`echo "${bootdir}/@grubdirname@
" | sed 's,//*,/,g'`"
300 device_map
="${grubdir}/device.map"
303 # Check if GRUB is installed.
304 if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
305 set $grub_setup dummy
306 if test -f "$1"; then
309 echo "$1: Not found." 1>&2
314 set "$grub_mkimage" dummy
315 if test -f "$1"; then
318 echo "$1: Not found." 1>&2
322 set "$grub_mkdevicemap" dummy
323 if test -f "$1"; then
326 echo "$1: Not found." 1>&2
330 if [ x
"$platform" = xefi
]; then
331 # Find the EFI System Partition.
333 if test -d "${bootdir}/efi"; then
334 install_device
="`"$grub_mkdevicemap" --device-map=/dev/stdout | "$grub_probe" --target=device --device-map=/dev/stdin "${bootdir}/efi
"`"
335 # Is it a mount point?
336 if test "x$install_device" != "x`"$grub_mkdevicemap" --device-map=/dev/stdout | "$grub_probe" --target=device --device-map=/dev/stdin "${bootdir}"`"; then
337 efidir
="${bootdir}/efi"
339 elif test -d "${bootdir}/EFI"; then
340 install_device
="`"$grub_mkdevicemap" --device-map=/dev/stdout | "$grub_probe" --target=device --device-map=/dev/stdin "${bootdir}/EFI
"`"
341 # Is it a mount point?
342 if test "x$install_device" != "x`"$grub_mkdevicemap" --device-map=/dev/stdout | "$grub_probe" --target=device --device-map=/dev/stdin "${bootdir}"`"; then
343 efidir
="${bootdir}/EFI"
345 elif test -n "$rootdir" && test "x$rootdir" != "x/"; then
346 # The EFI System Partition may have been given directly using
348 install_device
="`"$grub_mkdevicemap" --device-map=/dev/stdout | "$grub_probe" --target=device --device-map=/dev/stdin "${rootdir}"`"
349 # Is it a mount point?
350 if test "x$install_device" != "x`"$grub_mkdevicemap" --device-map=/dev/stdout | "$grub_probe" --target=device --device-map=/dev/stdin "${rootdir}/..
"`"; then
355 if test -n "$efidir"; then
356 efi_fs
=`"$grub_probe" --target=fs "--device-map=${device_map}" "${efidir}"`
357 if test "x$efi_fs" = xfat
; then :; else
358 echo "${efidir} doesn't look like an EFI partition." 1>&2
363 if test -n "$efidir"; then
364 # The EFI specification requires that an EFI System Partition must
365 # contain an "EFI" subdirectory, and that OS loaders are stored in
366 # subdirectories below EFI. Vendors are expected to pick names that do
367 # not collide with other vendors. To minimise collisions, we use the
368 # name of our distributor if possible.
369 efi_distributor
="$bootloader_id"
370 if test $removable = yes; then
371 # The specification makes stricter requirements of removable
372 # devices, in order that only one image can be automatically loaded
373 # from them. The image must always reside under /EFI/BOOT, and it
374 # must have a specific file name depending on the architecture.
376 case "$target_cpu" in
378 efi_file
=BOOTIA32.EFI
;;
380 efi_file
=BOOTX64.EFI
;;
381 # GRUB does not yet support these architectures, but they're defined
382 # by the specification so we include them here to ease future
385 efi_file
=BOOTIA64.EFI
;;
388 # It is convenient for each architecture to have a different
389 # efi_file, so that different versions can be installed in parallel.
390 case "$target_cpu" in
392 efi_file
=grubia32.efi
;;
394 efi_file
=grubx64.efi
;;
395 # GRUB does not yet support these architectures, but they're defined
396 # by the specification so we include them here to ease future
399 efi_file
=grubia64.efi
;;
403 # TODO: We should also use efibootmgr, if available, to add a Boot
404 # entry for ourselves.
406 efidir
="$efidir/EFI/$efi_distributor"
407 mkdir
-p "$efidir" ||
exit 1
409 # We don't know what's going on. Fall back to traditional
410 # (non-specification-compliant) behaviour.
417 # Create the GRUB directory if it is not present.
418 mkdir
-p "$grubdir" ||
exit 1
420 # If --recheck is specified, remove the device map, if present.
421 if test $recheck = yes; then
425 # Create the device map file if it is not present.
426 if test -f "$device_map"; then
427 # Make sure that there is no duplicated entry.
428 tmp
=`sed -n '/^([fh]d[0-9]*)/s/\(^(.*)\).*/\1/p' "$device_map" \
429 | sort | uniq -d | sed -n 1p`
430 if test -n "$tmp"; then
431 echo "The drive $tmp is defined multiple times in the device map $device_map" 1>&2
438 # Copy the GRUB images to the GRUB directory.
439 for file in "${grubdir}"/*.mod "${grubdir}"/*.lst "${grubdir}"/*.img "${grubdir}"/efiemu??.o
; do
440 if test -f "$file" && [ "`basename $file`" != menu.lst
]; then
441 rm -f "$file" ||
exit 1
444 for file in "${pkglibdir}"/*.mod
"${pkglibdir}"/*.lst
; do
445 cp -f "$file" "${grubdir}" ||
exit 1
447 if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
448 for file in "${pkglibdir}"/*.img
"${pkglibdir}"/efiemu??.o
; do
449 if test -f "$file"; then
450 cp -f "$file" "${grubdir}" ||
exit 1
456 mkdir
-p "${grubdir}"/locale
/
457 for dir
in "${localedir}"/*; do
458 if test -f "$dir/LC_MESSAGES/grub.mo"; then
459 cp -f "$dir/LC_MESSAGES/grub.mo" "${grubdir}/locale/${dir##*/}.mo"
463 is_path_readable_by_grub
"${grubdir}" ||
(echo "${grubdir}" not readable
1>&2 ; exit 1)
465 # Write device to a variable so we don't have to traverse /dev every time.
466 grub_device
="`"$grub_probe" --device-map="${device_map}" --target=device "${grubdir}"`" ||
exit 1
468 if ! test -f "${grubdir}"/grubenv
; then
469 "$grub_editenv" "${grubdir}"/grubenv create
472 # Create the core image. First, auto-detect the filesystem module.
473 fs_module
="`"$grub_probe" --device-map="${device_map}" --target=fs --device "${grub_device}"`"
474 if test "x$fs_module" = x
; then
475 echo "Auto-detection of a filesystem of ${grub_device} failed." 1>&2
476 echo "Try with --recheck." 1>&2
477 echo "If the problem persists please report this together with the output of \"$grub_probe --device-map=\"${device_map}\" --target=fs -v ${grubdir}\" to <bug-grub@gnu.org>" 1>&2
481 # Then the partition map module. In order to support partition-less media,
482 # this command is allowed to fail (--target=fs already grants us that the
483 # filesystem will be accessible).
485 for x
in `"$grub_probe" --device-map="${device_map}" --target=partmap --device "${grub_device}" 2> /dev/null`; do
488 partmap_module
="$partmap_module part_bsd";;
491 partmap_module
="$partmap_module part_$x";;
495 # Device abstraction module, if any (lvm, raid).
496 devabstraction_module
="`"$grub_probe" --device-map="${device_map}" --target=abstraction --device "${grub_device}"`"
498 if [ "x$disk_module" = xata
]; then
502 if [ "x$disk_module" = xnative
]; then
503 disk_module
="pata ahci ohci"
504 if [ "x$target_cpu" = "xi386" ] ||
[ "x$target_cpu" = "xx86_64" ]; then
505 disk_module
="$disk_module uhci"
507 disk_module
="$disk_module usbms"
510 # The order in this list is critical. Be careful when modifying it.
511 modules
="$modules $disk_module"
512 modules
="$modules $fs_module $partmap_module $devabstraction_module"
514 relative_grubdir
="`"$grub_mkrelpath" "${grubdir}"`" ||
exit 1
515 if [ "x${relative_grubdir}" = "x" ] ; then
522 rm -f "${grubdir}/load.cfg"
524 if [ "x${debug_image}" != x
]; then
525 echo "set debug='${debug_image}'" >> "${grubdir}/load.cfg"
526 config_opt
="-c ${grubdir}/load.cfg "
529 if [ "x${devabstraction_module}" = "x" ] ; then
530 if [ x
"${install_device}" != x
]; then
531 if echo "${install_device}" |
grep -qx "(.*)" ; then
532 install_drive
="${install_device}"
534 install_drive
="`"$grub_probe" --device-map="${device_map}" --target=drive --device "${install_device}"`" ||
exit 1
536 install_drive
="`echo "${install_drive}" | sed -e 's/^(\(\([^,\\\\]\|\\\\\\\\\|\\\\,\)*\)\(\(,[a-zA-Z0-9]*\)*\))$/\1/'`"
538 grub_drive
="`"$grub_probe" --device-map="${device_map}" --target=drive --device "${grub_device}"`" ||
exit 1
540 # Strip partition number
541 grub_partition
="`echo "${grub_drive}" | sed -e 's/^(\(\([^,\\\\]\|\\\\\\\\\|\\\\,\)*\)\(\(,[a-zA-Z0-9]*\)*\))$/\3/'`"
542 grub_drive
="`echo "${grub_drive}" | sed -e 's/^(\(\([^,\\\\]\|\\\\\\\\\|\\\\,\)*\)\(\(,[a-zA-Z0-9]*\)*\))$/\1/'`"
543 if ([ "x$disk_module" != x
] && [ "x$disk_module" != xbiosdisk
]) ||
[ "x${grub_drive}" != "x${install_drive}" ] || ([ "x$platform" != xefi ] && [ "x$platform" != xpc ] && [ x"${platform}" != x
"ieee1275" ]); then
544 # generic method (used on coreboot and ata mod)
545 uuid
="`"$grub_probe" --device-map="${device_map}" --target=fs_uuid --device "${grub_device}"`"
546 if [ "x${uuid}" = "x" ] ; then
547 if [ "x$platform" != xefi
] && [ "x$platform" != xpc
] && [ x
"${platform}" != x
"ieee1275" ]; then
548 echo "UUID needed with $platform, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2
549 elif [ "$disk_module" = ata
]; then
550 echo "UUID needed with ata mod, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2
552 echo "UUID needed with cross-disk installs, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2
558 if [ x
"$disk_module" != x
] && [ x
"$disk_module" != xbiosdisk
]; then
559 hints
="`"$grub_probe" --device-map="${device_map}" --target=baremetal_hints --device "${grub_device}"`"
560 elif [ x
"$platform" = xpc
]; then
561 hints
="`"$grub_probe" --device-map="${device_map}" --target=bios_hints --device "${grub_device}"`"
562 elif [ x
"$platform" = xefi
]; then
563 hints
="`"$grub_probe" --device-map="${device_map}" --target=efi_hints --device "${grub_device}"`"
564 elif [ x
"$platform" = xieee1275
]; then
565 hints
="`"$grub_probe" --device-map="${device_map}" --target=ieee1275_hints --device "${grub_device}"`"
566 elif [ x
"$platform" = xloongson
] ||
[ x
"$platform" = xqemu
] ||
[ x
"$platform" = xcoreboot
] ||
[ x
"$platform" = xmultiboot
] ||
[ x
"$platform" = xqemu-mips
]; then
567 hints
="`"$grub_probe" --device-map="${device_map}" --target=baremetal_hints --device "${grub_device}"`"
569 echo "No hints available for your platform. Expect reduced performance"
572 echo "search.fs_uuid ${uuid} root $hints " >> "${grubdir}/load.cfg"
573 echo 'set prefix=($root)'"${relative_grubdir}" >> "${grubdir}/load.cfg"
574 config_opt
="-c ${grubdir}/load.cfg "
575 modules
="$modules search_fs_uuid"
577 # we need to hardcode the partition number in the core image's prefix.
578 if [ x
"$grub_partition" = x
]; then
581 # Comma is already there
582 prefix_drive
="($grub_partition)"
586 if [ x
$GRUB_CRYPTODISK_ENABLE = xy
]; then
587 for uuid
in "`"${grub_probe}" --device "${grub_device}" --target=cryptodisk_uuid`"; do
588 echo "cryptomount -u $uuid" >> "${grubdir}/load.cfg"
590 config_opt
="-c ${grubdir}/load.cfg "
593 prefix_drive
=`"$grub_probe" --device-map="${device_map}" --target=drive --device "${grub_device}"` ||
exit 1
596 case "${target_cpu}-${platform}" in
597 sparc64-ieee1275
) mkimage_target
=sparc64-ieee1275-raw
;;
598 mipsel-loongson
) mkimage_target
=mipsel-loongson-elf
;;
599 *) mkimage_target
="${target_cpu}-${platform}" ;;
602 case "${target_cpu}-${platform}" in
603 i386-efi | x86_64-efi
) imgext
=efi
;;
604 mipsel-loongson | i386-coreboot | i386-multiboot | i386-ieee1275 \
605 | powerpc-ieee1275
) imgext
=elf
;;
610 "$grub_mkimage" ${config_opt} -d "${pkglibdir}" -O ${mkimage_target} --output="${grubdir}/core.${imgext}" --prefix="${prefix_drive}${relative_grubdir}" $modules || exit 1
612 # Backward-compatibility kludges
613 if [ "${target_cpu}-${platform}" = "mipsel-loongson
" ]; then
614 cp "${grubdir}/core.${imgext}" "${bootdir}"/grub.elf
615 elif [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${platform}" = "powerpc-ieee1275
" ]; then
616 cp "${grubdir}/core.${imgext}" "${grubdir}/grub
"
617 elif [ "${target_cpu}-${platform}" = "i386-efi" ] || [ "${target_cpu}-${platform}" = "x86_64-efi
" ]; then
618 "$grub_mkimage" ${config_opt} -d "${pkglibdir}" -O ${mkimage_target} --output="${grubdir}/grub.efi" --prefix="" $modules ||
exit 1
622 # Perform the platform-dependent install
623 if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
624 # Now perform the installation.
625 "$grub_setup" ${allow_floppy} ${setup_verbose} ${setup_force} --directory="${grubdir}" \
626 --device-map="${device_map}" "${install_device}" || exit 1
627 elif [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${platform}" = "powerpc-ieee1275
" ]; then
628 if [ x"$update_nvram" = xyes ]; then
629 ofpathname="`which ofpathname`"
630 nvsetenv="`which nvsetenv`"
631 set "$ofpathname" dummy
632 if test -f "$1"; then
635 echo "$1: Not found.
" 1>&2
638 set "$nvsetenv" dummy
639 if test -f "$1"; then
642 echo "$1: Not found.
" 1>&2
645 # Get the Open Firmware device tree path translation.
646 dev="`echo $grub_device | sed -e 's/\/dev\///' -e 's/[0-9]\+//'`"
647 partno="`echo $grub_device | sed -e 's/.*[^0-9]\([0-9]\+\)$/\1/'`"
648 ofpath="`$ofpathname $dev`" || {
649 echo "Couldn
't find Open Firmware device tree path for $dev."
650 echo "You will have to set boot-device manually."
654 # Point boot-device at the new grub install
655 boot_device="$ofpath:$partno,"`"$grub_mkrelpath" "${grubdir}/core.${imgext}" | sed 's
,/,\\\\,g
'`
656 "$nvsetenv" boot-device "$boot_device" || {
657 echo "$nvsetenv failed."
658 echo "You will have to set boot-device manually. At the Open Firmware prompt, type:"
659 echo " setenv boot-device $boot_device"
663 elif [ x"${target_cpu}-${platform}" = xmips-arc ]; then
664 dvhtool -d "${install_device}" --unix-to-vh "{grubdir}/core.${imgext}" grub
665 echo "You will have to set SystemPartition and OSLoader manually."
666 elif [ x"$platform" = xefi ]; then
667 cp "${grubdir}/core.${imgext}" "${efidir}/${efi_file}"
668 # For old macs. Suggested by Peter Jones.
669 if [ x$target_cpu = xi386 ]; then
670 cp "${grubdir}/core.${imgext}" "${efidir}/boot.efi"
673 # Try to make this image bootable using the EFI Boot Manager, if available.
674 efibootmgr="`which efibootmgr`"
675 if test "$removable" = no && test -n "$efi_distributor" && \
676 test -n "$efibootmgr"; then
677 # On Linux, we need the efivars kernel modules.
680 modprobe -q efivars 2>/dev/null || true ;;
683 # Delete old entries from the same distributor.
684 for bootnum in `efibootmgr | grep '^Boot
[0-9]' | \
685 fgrep -i " $efi_distributor" | cut -b5-8`; do
686 efibootmgr $efi_quiet -b "$bootnum" -B
689 # Add a new entry for the image we just created. efibootmgr needs to be
690 # given the disk device and partition number separately, so we have to
691 # fiddle about with grub-probe to get hold of this reasonably reliably.
692 # Use fresh device map text to avoid any problems with stale data, since
693 # all we need here is a one-to-one mapping.
694 clean_devmap="$($grub_mkdevicemap --device-map=/dev/stdout)"
695 efidir_drive="$(echo "$clean_devmap" | "$grub_probe" --device-map="${device_map}" --target=drive --device-map=/dev/stdin "$efidir")"
696 if test -z "$efidir_drive"; then
697 echo "Can't
find GRUB drive
for $efidir; unable to create EFI Boot Manager entry.
" >&2
699 efidir_disk="$
(echo "$clean_devmap" |
grep "^$(echo "$efidir_drive" | sed 's/,[^)]*//')" | cut
-f2)"
700 efidir_part="$
(echo "$efidir_drive" |
sed 's/^([^,]*,[^0-9]*//; s/[^0-9].*//')"
701 efibootmgr $efi_quiet -c -d "$efidir_disk" -p "$efidir_part" -w \
702 -L "$bootloader_id" -l "\\EFI
\\$efi_distributor\\$efi_file"
707 echo "Installation finished. No error reported.
"