3
# Install GRUB on your EFI partition.
4
# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008 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
PACKAGE_NAME=@PACKAGE_NAME@
28
PACKAGE_TARNAME=@PACKAGE_TARNAME@
29
PACKAGE_VERSION=@PACKAGE_VERSION@
30
target_cpu=@target_cpu@
33
pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`
34
localedir=@datadir@/locale
38
grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}`
39
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
40
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
41
grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
43
grub_prefix=`echo /boot/grub | sed ${transform}`
56
Install GRUB on your EFI partition.
58
-h, --help print this message and exit
59
-v, --version print the version information and exit
60
--modules=MODULES pre-load specified modules MODULES
61
--root-directory=DIR install GRUB images under the directory DIR
62
instead of the root directory
63
--grub-mkimage=FILE use FILE as grub-mkimage
64
--grub-mkdevicemap=FILE use FILE as grub-mkdevicemap
65
--grub-probe=FILE use FILE as grub-probe
66
--no-floppy do not probe any floppy drive
67
--recheck probe a device map even if it already exists
69
$self copies GRUB images into the DIR/boot directory specified by
72
Report bugs to <bug-grub@gnu.org>.
80
if test $# -eq 0; then
81
echo "$0: option requires an argument -- '$opt'" 1>&2
87
# Check the arguments.
98
echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
102
modules=`argument $option "$@"`; shift ;;
104
modules=`echo "$option" | sed 's/--modules=//'` ;;
107
rootdir=`argument $option "$@"`; shift ;;
109
rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
112
grub_mkimage=`argument $option "$@"`; shift ;;
114
grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
117
grub_mkdevicemap=`argument $option "$@"`; shift ;;
118
--grub-mkdevicemap=*)
119
grub_mkdevicemap=`echo "$option" | sed 's/--grub-mkdevicemap=//'` ;;
122
grub_probe=`argument $option "$@"`; shift ;;
124
grub_probe=`echo "$option" | sed 's/--grub-probe=//'` ;;
127
no_floppy="--no-floppy" ;;
130
# This is an undocumented feature...
134
echo "Unrecognized option \`$option'" 1>&2
141
# If the debugging feature is enabled, print commands.
142
if test $debug = yes; then
146
# Initialize these directories here, since ROOTDIR was initialized.
149
# Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub
150
# instead of /boot/grub.
151
grub_prefix=`echo /grub | sed ${transform}`
155
# Use /boot/grub by default.
156
bootdir=${rootdir}/boot
160
grubdir=${bootdir}/`echo grub | sed ${transform}`
161
device_map=${grubdir}/device.map
163
# Check if GRUB is installed.
164
set $grub_mkimage dummy
165
if test -f "$1"; then
168
echo "$1: Not found." 1>&2
172
set $grub_mkdevicemap dummy
173
if test -f "$1"; then
176
echo "$1: Not found." 1>&2
180
# Create the GRUB directory if it is not present.
181
mkdir -p "$grubdir" || exit 1
183
# If --recheck is specified, remove the device map, if present.
184
if test $recheck = yes; then
188
# Create the device map file if it is not present.
189
if test -f "$device_map"; then
192
# Create a safe temporary file.
193
test -n "$mklog" && log_file=`$mklog`
195
$grub_mkdevicemap --device-map=$device_map $no_floppy || exit 1
198
# Make sure that there is no duplicated entry.
199
tmp=`sed -n '/^([fh]d[0-9]*)/s/\(^(.*)\).*/\1/p' $device_map \
200
| sort | uniq -d | sed -n 1p`
201
if test -n "$tmp"; then
202
echo "The drive $tmp is defined multiple times in the device map $device_map" 1>&2
206
# Copy the GRUB images to the GRUB directory.
207
for file in ${grubdir}/*.mod ${grubdir}/*.lst; do
208
if test -f $file && [ "`basename $file`" != menu.lst ]; then
209
rm -f $file || exit 1
212
for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do
213
cp -f $file ${grubdir} || exit 1
217
mkdir -p ${grubdir}/locale/
218
for dir in ${localedir}/*; do
219
if test -f "$dir/LC_MESSAGES/grub.mo"; then
220
cp -f "$dir/LC_MESSAGES/grub.mo" "${grubdir}/locale/${dir##*/}.mo"
224
if ! test -f ${grubdir}/grubenv; then
225
$grub_editenv ${grubdir}/grubenv create
228
# Create the core image. First, auto-detect the filesystem module.
229
fs_module=`$grub_probe --target=fs --device-map=${device_map} ${grubdir}`
230
if test "x$fs_module" = xfat; then :; else
231
echo "${grubdir} doesn't look like an EFI partition." 1>&2
235
# Then the partition map module. In order to support partition-less media,
236
# this command is allowed to fail (--target=fs already grants us that the
237
# filesystem will be accessible).
239
for x in `$grub_probe --target=partmap --device-map=${device_map} ${grubdir} 2> /dev/null`; do
240
partmap_module="$partmap_module part_$x";
243
# Device abstraction module, if any (lvm, raid).
244
devabstraction_module=`$grub_probe --target=abstraction --device-map=${device_map} ${grubdir}`
246
# The order in this list is critical. Be careful when modifying it.
247
modules="$modules $fs_module $partmap_module $devabstraction_module"
249
$grub_mkimage -p "" -O ${target_cpu}-efi --output=${grubdir}/grub.efi $modules || exit 1
251
# Prompt the user to check if the device map is correct.
252
echo "Installation finished. No error reported."
253
echo "This is the contents of the device map $device_map."
254
echo "Check if this is correct or not. If any of the lines is incorrect,"
255
echo "fix it and re-run the script \`$self'."