~ubuntu-branches/ubuntu/trusty/grub2/trusty-updates

« back to all changes in this revision

Viewing changes to util/i386/efi/grub-install.in

Tags: upstream-1.99~20101122
ImportĀ upstreamĀ versionĀ 1.99~20101122

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /bin/sh
2
 
 
3
 
# Install GRUB on your EFI partition.
4
 
# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008  Free Software Foundation, Inc.
5
 
#
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.
10
 
#
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.
15
 
#
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/>.
18
 
 
19
 
# Initialize some variables.
20
 
transform="@program_transform_name@"
21
 
 
22
 
prefix=@prefix@
23
 
exec_prefix=@exec_prefix@
24
 
sbindir=@sbindir@
25
 
bindir=@bindir@
26
 
libdir=@libdir@
27
 
PACKAGE_NAME=@PACKAGE_NAME@
28
 
PACKAGE_TARNAME=@PACKAGE_TARNAME@
29
 
PACKAGE_VERSION=@PACKAGE_VERSION@
30
 
target_cpu=@target_cpu@
31
 
platform=@platform@
32
 
host_os=@host_os@
33
 
pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`
34
 
 
35
 
grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}`
36
 
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
37
 
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
38
 
grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
39
 
rootdir=
40
 
grub_prefix=`echo /boot/grub | sed ${transform}`
41
 
modules=
42
 
 
43
 
no_floppy=
44
 
force_lba=
45
 
recheck=no
46
 
debug=no
47
 
 
48
 
# Usage: usage
49
 
# Print the usage.
50
 
usage () {
51
 
    cat <<EOF
52
 
Usage: grub-install [OPTION]
53
 
Install GRUB on your EFI partition.
54
 
 
55
 
  -h, --help              print this message and exit
56
 
  -v, --version           print the version information and exit
57
 
  --modules=MODULES       pre-load specified modules MODULES
58
 
  --root-directory=DIR    install GRUB images under the directory DIR
59
 
                          instead of the root directory
60
 
  --grub-mkimage=FILE     use FILE as grub-mkimage
61
 
  --grub-mkdevicemap=FILE use FILE as grub-mkdevicemap
62
 
  --grub-probe=FILE       use FILE as grub-probe
63
 
  --no-floppy             do not probe any floppy drive
64
 
  --recheck               probe a device map even if it already exists
65
 
 
66
 
grub-install copies GRUB images into the DIR/boot directory specified by
67
 
--root-directory.
68
 
 
69
 
Report bugs to <bug-grub@gnu.org>.
70
 
EOF
71
 
}
72
 
 
73
 
# Check the arguments.
74
 
for option in "$@"; do
75
 
    case "$option" in
76
 
    -h | --help)
77
 
        usage
78
 
        exit 0 ;;
79
 
    -v | --version)
80
 
        echo "grub-install (GNU GRUB ${PACKAGE_VERSION})"
81
 
        exit 0 ;;
82
 
    --modules=*)
83
 
        modules=`echo "$option" | sed 's/--modules=//'` ;;
84
 
    --root-directory=*)
85
 
        rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
86
 
    --grub-mkimage=*)
87
 
        grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
88
 
    --grub-mkdevicemap=*)
89
 
        grub_mkdevicemap=`echo "$option" | sed 's/--grub-mkdevicemap=//'` ;;
90
 
    --grub-probe=*)
91
 
        grub_probe=`echo "$option" | sed 's/--grub-probe=//'` ;;
92
 
    --no-floppy)
93
 
        no_floppy="--no-floppy" ;;
94
 
    --recheck)
95
 
        recheck=yes ;;
96
 
    # This is an undocumented feature...
97
 
    --debug)
98
 
        debug=yes ;;
99
 
    *)
100
 
        echo "Unrecognized option \`$option'" 1>&2
101
 
        usage
102
 
        exit 1
103
 
        ;;
104
 
    esac
105
 
done
106
 
 
107
 
# If the debugging feature is enabled, print commands.
108
 
if test $debug = yes; then
109
 
    set -x
110
 
fi
111
 
 
112
 
# Initialize these directories here, since ROOTDIR was initialized.
113
 
case "$host_os" in
114
 
netbsd* | openbsd*)
115
 
    # Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub
116
 
    # instead of /boot/grub.
117
 
    grub_prefix=`echo /grub | sed ${transform}`
118
 
    bootdir=${rootdir}
119
 
    ;;
120
 
*)
121
 
    # Use /boot/grub by default.
122
 
    bootdir=${rootdir}/boot
123
 
    ;;
124
 
esac
125
 
 
126
 
grubdir=${bootdir}/`echo grub | sed ${transform}`
127
 
device_map=${grubdir}/device.map
128
 
 
129
 
# Check if GRUB is installed.
130
 
set $grub_mkimage dummy
131
 
if test -f "$1"; then
132
 
    :
133
 
else
134
 
    echo "$1: Not found." 1>&2
135
 
    exit 1
136
 
fi
137
 
 
138
 
set $grub_mkdevicemap dummy
139
 
if test -f "$1"; then
140
 
    :
141
 
else
142
 
    echo "$1: Not found." 1>&2
143
 
    exit 1
144
 
fi
145
 
 
146
 
# Create the GRUB directory if it is not present.
147
 
test -d "$bootdir" || mkdir "$bootdir" || exit 1
148
 
test -d "$grubdir" || mkdir "$grubdir" || exit 1
149
 
 
150
 
# If --recheck is specified, remove the device map, if present.
151
 
if test $recheck = yes; then
152
 
    rm -f $device_map
153
 
fi
154
 
 
155
 
# Create the device map file if it is not present.
156
 
if test -f "$device_map"; then
157
 
    :
158
 
else
159
 
    # Create a safe temporary file.
160
 
    test -n "$mklog" && log_file=`$mklog`
161
 
 
162
 
    $grub_mkdevicemap --device-map=$device_map $no_floppy || exit 1
163
 
fi
164
 
 
165
 
# Make sure that there is no duplicated entry.
166
 
tmp=`sed -n '/^([fh]d[0-9]*)/s/\(^(.*)\).*/\1/p' $device_map \
167
 
    | sort | uniq -d | sed -n 1p`
168
 
if test -n "$tmp"; then
169
 
    echo "The drive $tmp is defined multiple times in the device map $device_map" 1>&2
170
 
    exit 1
171
 
fi
172
 
 
173
 
# Copy the GRUB images to the GRUB directory.
174
 
for file in ${grubdir}/*.mod ${grubdir}/*.lst; do
175
 
    if test -f $file && [ "`basename $file`" != menu.lst ]; then
176
 
        rm -f $file || exit 1
177
 
    fi
178
 
done
179
 
for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do
180
 
    cp -f $file ${grubdir} || exit 1
181
 
done
182
 
 
183
 
if ! test -f ${grubdir}/grubenv; then
184
 
    $grub_editenv ${grubdir}/grubenv create
185
 
fi
186
 
 
187
 
# Create the core image. First, auto-detect the filesystem module.
188
 
fs_module=`$grub_probe --target=fs --device-map=${device_map} ${grubdir}`
189
 
if test "x$fs_module" = xfat; then :; else
190
 
    echo "${grubdir} doesn't look like an EFI partition." 1>&2
191
 
    exit 1
192
 
fi
193
 
 
194
 
# Then the partition map module.  In order to support partition-less media,
195
 
# this command is allowed to fail (--target=fs already grants us that the
196
 
# filesystem will be accessible).
197
 
partmap_module=`$grub_probe --target=partmap --device-map=${device_map} ${grubdir} 2> /dev/null`
198
 
 
199
 
# Device abstraction module, if any (lvm, raid).
200
 
devabstraction_module=`$grub_probe --target=abstraction --device-map=${device_map} ${grubdir}`
201
 
 
202
 
# The order in this list is critical.  Be careful when modifying it.
203
 
modules="$modules $fs_module $partmap_module $devabstraction_module"
204
 
 
205
 
$grub_mkimage --output=${grubdir}/grub.efi $modules || exit 1
206
 
 
207
 
# Prompt the user to check if the device map is correct.
208
 
echo "Installation finished. No error reported."
209
 
echo "This is the contents of the device map $device_map."
210
 
echo "Check if this is correct or not. If any of the lines is incorrect,"
211
 
echo "fix it and re-run the script \`grub-install'."
212
 
echo
213
 
 
214
 
cat $device_map
215
 
 
216
 
# Bye.
217
 
exit 0