# Install GRUB on your drive.
# Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
#
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Initialize some variables.
# look for secure tempfile creation wrappers on this platform
else
mklog=""
mkimg=""
fi
# Usage: usage
# Print the usage.
cat <<EOF
Usage: grub-install [OPTION] install_device
Install GRUB on your drive.
-h, --help print this message and exit
-v, --version print the version information and exit
--root-directory=DIR install GRUB images under the directory DIR
instead of the root directory
--grub-shell=FILE use FILE as the grub shell
--no-floppy do not probe any floppy drive
--force-lba force GRUB to use LBA mode even for a buggy
BIOS
--recheck probe a device map even if it already exists
INSTALL_DEVICE can be a GRUB device name or a system device filename.
grub-install copies GRUB images into the DIR/boot directory specfied by
--root-directory, and uses the grub shell to install grub into the boot
sector.
Report bugs to <bug-grub@gnu.org>.
EOF
}
# Usage: convert os_device
# Convert an OS device to the corresponding GRUB drive.
# This part is OS-specific.
# First, check if the device file exists.
if test -e "$1"; then
:
else
echo "$1: Not found or not a block device." 1>&2
exit 1
fi
# Break the device name into the disk part and the partition part.
linux*)
-e 's%\(d[0-9]*\)p[0-9]*$%\1%' \
-e 's%\(fd[0-9]*\)$%\1%' \
-e 's%/part[0-9]*$%/disc%' \
-e 's%\(c[0-7]d[0-9]*\).*$%\1%'`
-e 's%.*d[0-9]*p%%' \
-e 's%.*/fd[0-9]*$%%' \
-e 's%.*/floppy/[0-9]*$%%' \
-e 's%.*/\(disc\|part\([0-9]*\)\)$%\2%' \
-e 's%.*c[0-7]d[0-9]*p%%'`
;;
gnu*)
;;
;;
*)
echo "grub-install does not support your OS yet." 1>&2
exit 1 ;;
esac
# Get the drive name.
# If not found, print an error message and exit.
echo "$1 does not have any corresponding BIOS drive." 1>&2
exit 1
fi
# If a partition is specified, we need to translate it into the
# GRUB's syntax.
linux*)
gnu*)
tmp_pc_slice=`echo $tmp_part \
fi
fi
tmp_pc_slice=`echo $tmp_part \
fi
fi
fi
esac
else
# If no partition is specified, just print the drive name.
echo "$tmp_drive"
fi
}
# Usage: resolve_symlink file
tmp_fname=$1
# Resolve symlinks
while test -L $tmp_fname; do
echo "Unrecognized ls output" 2>&1
exit 1
fi
# Convert relative symlinks
case $tmp_new_fname in
/*) tmp_fname="$tmp_new_fname"
;;
;;
esac
done
echo "$tmp_fname"
}
# Usage: find_device file
# Find block device on which the file resides.
# For now, this uses the program `df' to get the device name, but is
# this really portable?
echo "Could not find device for $1" 2>&1
exit 1
fi
echo "$tmp_fname"
}
# Check the arguments.
-h | --help)
exit 0 ;;
-v | --version)
echo "grub-install (GNU GRUB ${VERSION})"
exit 0 ;;
no_floppy="--no-floppy" ;;
force_lba="--force-lba" ;;
--recheck)
# This is an undocumented feature...
--debug)
-*)
exit 1
;;
*)
if test "x$install_device" != x; then
echo "More than one install_devices?" 1>&2
exit 1
fi
install_device="${option}" ;;
esac
done
if test "x$install_device" = x; then
echo "install_device not specified." 1>&2
exit 1
fi
# If the debugging feature is enabled, print commands.
set -x
fi
# Initialize these directories here, since ROOTDIR was initialized.
# Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub
;;
*)
;;
esac
# Check if GRUB is installed.
# This is necessary, because the user can specify "grub --read-only".
set $grub_shell dummy
if test -f "$1"; then
:
else
echo "$1: Not found." 1>&2
exit 1
fi
if test -f "$pkglibdir/stage1"; then
:
else
echo "${pkglibdir}/stage1: Not found." 1>&2
exit 1
fi
if test -f "$pkglibdir/stage2"; then
:
else
echo "${pkglibdir}/stage2: Not found." 1>&2
exit 1
fi
# Don't check for *stage1_5, because it is not fatal even if any
# Stage 1.5 does not exist.
# 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
:
else
# Create a safe temporary file.
quit
EOF
exit 1
fi
fi
# Make sure that there is no duplicated entry.
if test -n "$tmp"; then
exit 1
fi
# Check for INSTALL_DEVICE.
case "$install_device" in
/dev/*)
# I don't know why, but some shells wouldn't die if exit is
# called in a function.
if test "x$install_drive" = x; then
exit 1
fi ;;
# The GRUB format with no parenthesis.
install_drive="($install_device)" ;;
*)
echo "Format of install_device not recognized." 1>&2
exit 1 ;;
esac
# Get the root drive.
# Check if the boot directory is in the same device as the root directory.
if test "x$root_device" != "x$bootdir_device"; then
# Perhaps the user has a separate boot partition.
grub_prefix="/grub"
fi
# Convert the root device to a GRUB drive.
if test "x$root_drive" = x; then
exit 1
fi
# Check if the root directory exists in the same device as the grub
# directory.
if test "x$grubdir_device" != "x$root_device"; then
# For now, cannot deal with this situation.
cat <<EOF 1>&2
You must set the root directory by the option --root-directory, because
$grubdir does not exist in the root device $root_device.
EOF
exit 1
fi
# Copy the GRUB images to the GRUB directory.
done
done
# Make a default file.
# Make sure that GRUB reads the same images as the host OS.
count=5
dump ${root_drive}${tmp} ${img_file}
quit
EOF
:
break
fi
sleep 1
done
exit 1
fi
done
# Create a safe temporary file.
# Now perform the installation.
root $root_drive
setup $force_lba --stage2=$grubdir/stage2 --prefix=$grub_prefix $install_drive
quit
EOF
exit 1
fi
# Prompt the user to check if the device map is correct.
echo "Installation finished. No error reported."
echo "This is the contents of the device map $device_map."
echo "Check if this is correct or not. If any of the lines is incorrect,"
echo "fix it and re-run the script \`grub-install'."
echo
# Bye.
exit 0