# Install GRUB on your drive.
# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
#
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GRUB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
# Initialize some variables.
transform="@program_transform_name@"
prefix="@prefix@"
exec_prefix="@exec_prefix@"
sbindir="@sbindir@"
bindir="@bindir@"
libdir="@libdir@"
sysconfdir="@sysconfdir@"
localedir="@datadir@/locale"
# Get GRUB_DISTRIBUTOR.
fi
if test -z "$bootloader_id"; then
fi
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
elif [ "${platform}" = "ieee1275" ] || [ "${platform}" = "efi" ] ; then
else
fi
# Usage: usage
# Print the usage.
if [ "${target_cpu}-${platform}" = "i386-pc" ] \
|| [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ]; then
cat <<EOF
Usage: $self [OPTION] install_device
EOF
elif [ "${target_cpu}-${platform}" = "x86_64-efi" ] \
|| [ "${target_cpu}-${platform}" = "i386-efi" ]; then
cat <<EOF
Usage: $self [OPTION] install_directory
EOF
else
cat <<EOF
Usage: $self [OPTION] [install_device]
EOF
fi
cat <<EOF
Install GRUB on your drive.
-h, --help print this message and exit
-v, --version print the version information and exit
--modules=MODULES pre-load specified modules MODULES
--boot-directory=DIR install GRUB images under the directory DIR/grub
instead of the $grubdir directory
--grub-directory=DIR install GRUB images under the directory DIR
instead of the $grubdir directory (exclusive with
the --boot-directory argument)
--grub-setup=FILE use FILE as grub-setup
--grub-mkimage=FILE use FILE as grub-mkimage
--grub-mkrelpath=FILE use FILE as grub-mkrelpath
--grub-mkdevicemap=FILE use FILE as grub-mkdevicemap
--grub-probe=FILE use FILE as grub-probe
--no-floppy do not probe any floppy drive
--allow-floppy Make the drive also bootable as floppy
(default for fdX devices). May break on some BIOSes.
--recheck delete device map if it already exists
--force install even if problems are detected
EOF
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
cat <<EOF
--disk-module=MODULE disk module to use (biosdisk or native)
EOF
fi
if [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${platform}" = "powerpc-ieee1275" ] ; then
cat <<EOF
--no-nvram don't update the boot-device NVRAM variable
EOF
fi
if [ "${platform}" = "efi" ]; then
cat <<EOF
--removable the installation device is removable
--bootloader-id=ID the ID of bootloader.
EOF
fi
cat <<EOF
Solaris-specific options:
--force-mbr [i386-pc ONLY] GRUB first stage will be written to
the MBR instead of the PBR.
--pkglibdir=DIR Override the package library directory (where
grub-install copies modules from)
--no-embed-versioning Do not embed version sting in the core
image that's written to disk.
--no-check-versioning Do not check the version of GRUB installed package
INSTALL_DEVICE can be a GRUB device name or a system device filename.
INSTALL_DIRECTORY is a system path to the EFI system partition-hosted directory
into which the GRUB2 EFI boot application will be installed.
$self copies GRUB images into $grubdir, and uses grub-setup
to install grub into the boot sector.
Report bugs to <bug-grub@gnu.org>.
EOF
}
opt="$1"
shift
if test $# -eq 0; then
exit 1
fi
echo "$1"
}
allow_floppy=""
# Check the arguments.
while test $# -gt 0
do
option=$1
shift
-h | --help)
exit 0 ;;
-v | --version)
echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
exit 0 ;;
--modules)
--modules=*)
# Accept and ignore for compatibility
--font)
shift;;
--font=*)
;;
# Accept for compatibility
--bootloader-id)
--bootloader-id=*)
--grub-mkdevicemap)
--grub-mkdevicemap=*)
no_floppy="--no-floppy" ;;
--recheck)
--removable)
allow_floppy="--allow-floppy" ;;
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
fi ;;
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
fi ;;
update_nvram=no ;;
# Solaris-specific arguments:
--pkglibdir)
--pkglibdir=*)
force_mbr="--force-mbr" ;;
# This is an undocumented feature...
--debug)
-f | --force)
setup_force="--force" ;;
-*)
exit 1
;;
*)
if [ "${target_cpu}-${platform}" = "x86_64-efi" ] \
|| [ "${target_cpu}-${platform}" = "i386-efi" ]; then
if test "x$install_dir" != x; then
echo "More than one install_directory?" 1>&2
exit 1
fi
install_dir="${option}"
else
if test "x$install_device" != x; then
echo "More than one install_devices?" 1>&2
exit 1
fi
install_device="${option}"
fi
;;
esac
done
# Set versiondir here, since pkglibdir may have been set via command-line args:
versiondir="${pkglibdir}"
|| [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ]); then
echo "install_device not specified." 1>&2
exit 1
|| [ "${target_cpu}-${platform}" = "i386-efi" ]); then
echo "install_directory not specified." 1>&2
exit 1
fi
if ! ([ "${target_cpu}-${platform}" = "i386-pc" ] \
|| [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ]); then
fi
if ! ([ "${target_cpu}-${platform}" = "x86_64-efi" ] \
|| [ "${target_cpu}-${platform}" = "i386-efi" ]); then
fi
# If the debugging feature is enabled, print commands.
set -x
setup_verbose="--verbose"
efi_quiet=-q
fi
if [ -z "$bootdir" ]; then
# Default bootdir if bootdir not initialized.
bootdir="/@bootdirname@"
if [ -n "$rootdir" ] ; then
# Initialize bootdir if rootdir was initialized.
bootdir="${rootdir}/@bootdirname@"
fi
fi
grubdir="${bootdir}/@grubdirname@"
if ! test x"$grubdir_override" = x; then
if ! test -d "$grubdir_override"; then
exit 1
fi
fi
device_map="${grubdir}/device.map"
# Check if GRUB is installed.
if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
set $grub_setup dummy
if test -f "$1"; then
:
else
echo "$1: Not found." 1>&2
exit 1
fi
fi
set "$grub_mkimage" dummy
if test -f "$1"; then
:
else
echo "$1: Not found." 1>&2
exit 1
fi
set "$grub_mkdevicemap" dummy
if test -f "$1"; then
:
else
echo "$1: Not found." 1>&2
exit 1
fi
# Find the EFI System Partition.
if test -n "${install_dir}"; then
efidir="${install_dir}"
elif test -d "${bootdir}/efi"; then
install_device="`"$grub_mkdevicemap" --device-map=/dev/stdout | "$grub_probe" --target=device --device-map=/dev/stdin "${bootdir}/efi"`"
# Is it a mount point?
if test "x$install_device" != "x`"$grub_mkdevicemap" --device-map=/dev/stdout | "$grub_probe" --target=device --device-map=/dev/stdin "${bootdir}"`"; then
efidir="${bootdir}/efi"
fi
elif test -d "${bootdir}/EFI"; then
install_device="`"$grub_mkdevicemap" --device-map=/dev/stdout | "$grub_probe" --target=device --device-map=/dev/stdin "${bootdir}/EFI"`"
# Is it a mount point?
if test "x$install_device" != "x`"$grub_mkdevicemap" --device-map=/dev/stdout | "$grub_probe" --target=device --device-map=/dev/stdin "${bootdir}"`"; then
efidir="${bootdir}/EFI"
fi
# The EFI System Partition may have been given directly using
# --root-directory.
install_device="`"$grub_mkdevicemap" --device-map=/dev/stdout | "$grub_probe" --target=device --device-map=/dev/stdin "${rootdir}"`"
# Is it a mount point?
if test "x$install_device" != "x`"$grub_mkdevicemap" --device-map=/dev/stdout | "$grub_probe" --target=device --device-map=/dev/stdin "${rootdir}/.."`"; then
efidir="${rootdir}"
fi
fi
if test -n "$efidir"; then
echo "${efidir} doesn't look like an EFI partition." 1>&2
fi
fi
if test -n "$efidir"; then
# The EFI specification requires that an EFI System Partition must
# contain an "EFI" subdirectory, and that OS loaders are stored in
# subdirectories below EFI. Vendors are expected to pick names that do
# not collide with other vendors. To minimise collisions, we use the
# name of our distributor if possible.
if test $removable = yes; then
# The specification makes stricter requirements of removable
# devices, in order that only one image can be automatically loaded
# must have a specific file name depending on the architecture.
case "$target_cpu" in
i386)
# GRUB does not yet support these architectures, but they're defined
# by the specification so we include them here to ease future
# expansion.
ia64)
esac
else
# It is convenient for each architecture to have a different
# efi_file, so that different versions can be installed in parallel.
case "$target_cpu" in
i386)
# GRUB does not yet support these architectures, but they're defined
# by the specification so we include them here to ease future
# expansion.
ia64)
*)
esac
# TODO: We should also use efibootmgr, if available, to add a Boot
# entry for ourselves.
fi
if ! test -n "$install_dir"; then
# If the install_dir was specified, USE THAT DIR, not a derivation.
efidir="$efidir/EFI/$efi_distributor"
fi
else
# We don't know what's going on. Fall back to traditional
# (non-specification-compliant) behaviour.
fi
fi
# Create the GRUB directory if it is not present.
# If --recheck is specified, remove the device map, if present.
rm -f "$device_map"
fi
# Create the device map file if it is not present.
if test -f "$device_map"; then
# Make sure that there is no duplicated entry.
if test -n "$tmp"; then
exit 1
fi
else
fi
if ! test -f "${versiondir}"/version.lst; then
if test x"$do_embed_versioning" = xyes; then
if test x"$do_version_check" = xno; then
# Only emit a message if another one won't be emitted later on.
echo "WARNING: Versioning information not found in $versiondir"
echo " grub-install will not embed versioning information."
fi
fi
fi
if test x"$do_version_check" = xno; then
else # Check currently installed version.
# If the about to be installed GRUB2 version file is missing, that's an error.
if test x"$version_lst_present" = xno; then
echo "FATAL: Versioning information could not be found in ${versiondir}"
echo "Disable versioning or ensure that ${versiondir}/version.lst is"
echo "present."
exit 1
fi
# If the currently installed GRUB2 version file is missing, proceed with
# the installation.
if test -f "${grubdir}"/version.lst; then
# Both files are available, compare the two versions.
copy_version_lst="`"${grub_version_check}" --source="${versiondir}"/version.lst --dest="${grubdir}"/version.lst -t solaris_grub_version`"
if test x"$copy_version_lst" != xyes; then
echo "The version of GRUB2 installed at ${grubdir} is the same as or newer than the version currently available in ${versiondir}" 1>&2
exit 0
fi
fi
fi
# Before we proceed, we have to make sure that we are compatible with the modules
# being used:
# The source version information is built into grub-version-check:
mod_compat="`"${grub_version_check}" -t module_interface_version --dest="${versiondir}"/version.lst`"
if ! test "x$mod_compat" = xyes; then
exit 5
fi
# Copy the GRUB images to the GRUB directory.
fi
done
done
if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
if test -f "$file"; then
fi
done
fi
# Copy gettext files
if test -f "$dir/LC_MESSAGES/grub.mo"; then
cp -f "$dir/LC_MESSAGES/grub.mo" "${grubdir}/locale/${dir##*/}.mo"
fi
done
# Write device to a variable so we don't have to traverse /dev every time.
if ! test -f "${grubdir}"/grubenv; then
fi
# Create the core image. First, auto-detect the filesystem module.
if test "x$fs_module" = x ; then
echo "Auto-detection of a filesystem of ${grub_device} failed." 1>&2
echo "Try with --recheck." 1>&2
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
exit 1
fi
# Then the partition map module. In order to support partition-less media,
# this command is allowed to fail (--target=fs already grants us that the
# filesystem will be accessible).
for x in `"$grub_probe" --device-map="${device_map}" --target=partmap --device "${grub_device}" 2> /dev/null`; do
case "$x" in
partmap_module="$partmap_module part_bsd";;
"") ;;
*)
partmap_module="$partmap_module part_$x";;
esac
done
# Device abstraction module, if any (lvm, raid).
devabstraction_module="`"$grub_probe" --device-map="${device_map}" --target=abstraction --device "${grub_device}"`"
if [ "x$disk_module" = xata ]; then
fi
if [ "x$disk_module" = xnative ]; then
disk_module="pata ahci ohci"
disk_module="$disk_module uhci"
fi
disk_module="$disk_module usbms"
fi
# The order in this list is critical. Be careful when modifying it.
if [ "x${relative_grubdir}" = "x" ] ; then
fi
if [ "x${debug_image}" != x ]; then
echo "set debug='${debug_image}'" >> "${grubdir}/load.cfg"
config_opt="-c ${grubdir}/load.cfg "
fi
if [ "x${devabstraction_module}" = "x" ] ; then
if [ x"${install_device}" != x ]; then
install_drive="${install_device}"
else
install_drive="`"$grub_probe" --device-map="${device_map}" --target=drive --device "${install_device}"`" || exit 1
fi
install_drive="`echo "${install_drive}" | sed -e 's/^(\(\([^,\\\\]\|\\\\\\\\\|\\\\,\)*\)\(\(,[a-zA-Z0-9]*\)*\))$/\1/'`"
fi
grub_drive="`"$grub_probe" --device-map="${device_map}" --target=drive --device "${grub_device}"`" || exit 1
# Strip partition number
grub_partition="`echo "${grub_drive}" | sed -e 's/^(\(\([^,\\\\]\|\\\\\\\\\|\\\\,\)*\)\(\(,[a-zA-Z0-9]*\)*\))$/\3/'`"
grub_drive="`echo "${grub_drive}" | sed -e 's/^(\(\([^,\\\\]\|\\\\\\\\\|\\\\,\)*\)\(\(,[a-zA-Z0-9]*\)*\))$/\1/'`"
if [ "x$fs_module" == xzfs ] || ([ "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
# generic method (used on coreboot and ata mod)
if [ "x${uuid}" = "x" ] ; then
echo "UUID needed with $platform, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2
elif [ "$disk_module" = ata ]; then
echo "UUID needed with ata mod, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2
else
echo "UUID needed with cross-disk installs, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2
fi
exit 1
fi
hints="`"$grub_probe" --device-map="${device_map}" --target=baremetal_hints --device "${grub_device}"`"
hints="`"$grub_probe" --device-map="${device_map}" --target=ieee1275_hints --device "${grub_device}"`"
elif [ x"$platform" = xloongson ] || [ x"$platform" = xqemu ] || [ x"$platform" = xcoreboot ] || [ x"$platform" = xmultiboot ] || [ x"$platform" = xqemu-mips ]; then
hints="`"$grub_probe" --device-map="${device_map}" --target=baremetal_hints --device "${grub_device}"`"
else
echo "No hints available for your platform. Expect reduced performance"
fi
config_opt="-c ${grubdir}/load.cfg "
else
# we need to hardcode the partition number in the core image's prefix.
if [ x"$grub_partition" = x ]; then
prefix_drive="()"
else
# Comma is already there
fi
fi
else
if [ x$GRUB_CRYPTODISK_ENABLE = xy ]; then
done
config_opt="-c ${grubdir}/load.cfg "
fi
prefix_drive=`"$grub_probe" --device-map="${device_map}" --target=drive --device "${grub_device}"` || exit 1
fi
case "${target_cpu}-${platform}" in
*) mkimage_target="${target_cpu}-${platform}" ;;
esac
case "${target_cpu}-${platform}" in
esac
"$grub_mkimage" ${config_opt} -d "${pkglibdir}" -O ${mkimage_target} --output="${grubdir}/core.${imgext}" --prefix="${prefix_drive}${relative_grubdir}" $modules || exit 1
# Backward-compatibility kludges
if [ "${target_cpu}-${platform}" = "mipsel-loongson" ]; then
elif [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${platform}" = "powerpc-ieee1275" ]; then
cp "${grubdir}/core.${imgext}" "${grubdir}/grub"
elif [ "${target_cpu}-${platform}" = "i386-efi" ] || [ "${target_cpu}-${platform}" = "x86_64-efi" ]; then
"$grub_mkimage" ${config_opt} -d "${pkglibdir}" -O ${mkimage_target} --output="${grubdir}/grub.efi" --prefix="" $modules || exit 1
fi
# Perform the platform-dependent install
if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
version_string="`"${grub_version_check}" --source="${versiondir}"/version.lst -p -t solaris_grub_version`"
if [ -n "$version_string" ]; then
else
echo "Requested to embed version, but no version info is available. exiting" 1>&2
exit 1
fi
fi
# Now perform the installation.
"${install_device}" || exit 1
elif [ "${target_cpu}-${platform}" = "i386-ieee1275" ] || [ "${target_cpu}-${platform}" = "powerpc-ieee1275" ]; then
if [ x"$update_nvram" = xyes ]; then
set "$ofpathname" dummy
if test -f "$1"; then
:
else
echo "$1: Not found." 1>&2
exit 1
fi
if test -f "$1"; then
:
else
echo "$1: Not found." 1>&2
exit 1
fi
# Get the Open Firmware device tree path translation.
echo "Couldn't find Open Firmware device tree path for $dev."
echo "You will have to set boot-device manually."
exit 1
}
# Point boot-device at the new grub install
echo "$nvsetenv failed."
echo "You will have to set boot-device manually. At the Open Firmware prompt, type:"
echo " setenv boot-device $boot_device"
exit 1
}
fi
echo "You will have to set SystemPartition and OSLoader manually."
# For old macs. Suggested by Peter Jones.
if [ x$target_cpu = xi386 ]; then
fi
# Try to make this image bootable using the EFI Boot Manager, if available.
solaris*)
;;
*)
;;
esac
test -n "$efibootmgr"; then
# On Linux, we need the efivars kernel modules.
linux*)
esac
# Delete old entries from the same distributor.
done
# Add a new entry for the image we just created. efibootmgr needs to be
# given the disk device and partition number separately, so we have to
# fiddle about with grub-probe to get hold of this reasonably reliably.
# Use fresh device map text to avoid any problems with stale data, since
# all we need here is a one-to-one mapping.
efidir_drive="$(echo "$clean_devmap" | "$grub_probe" --device-map="${device_map}" --target=drive --device-map=/dev/stdin "$efidir")"
if test -z "$efidir_drive"; then
echo "Can't find GRUB drive for $efidir; unable to create EFI Boot Manager entry." >&2
else
efidir_disk="$(echo "$clean_devmap" | grep "^$(echo "$efidir_drive" | sed 's/,[^)]*//')" | cut -f2)"
-L "$bootloader_id" -l "\\EFI\\$efi_distributor\\$efi_file"
fi
fi
fi
# Update the version.lst file
if test x"$copy_version_lst" = xyes; then
fi
echo "Installation finished. No error reported."
# Bye.
exit 0