make the linux-ppc packags be in synch with other platforms
[tangerine.git] / arch / common / boot / grub2 / util / i386 / efi / grub-install.in
blobfae15172f67c44e4c5845f4e4b547042d137f92e
1 #! /bin/sh
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@"
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 pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`
34 grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}`
35 grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
36 grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
37 rootdir=
38 grub_prefix=`echo /boot/grub | sed ${transform}`
39 modules=
41 no_floppy=
42 force_lba=
43 recheck=no
44 debug=no
46 # Usage: usage
47 # Print the usage.
48 usage () {
49 cat <<EOF
50 Usage: grub-install [OPTION]
51 Install GRUB on your EFI partition.
53 -h, --help print this message and exit
54 -v, --version print the version information and exit
55 --modules=MODULES pre-load specified modules MODULES
56 --root-directory=DIR install GRUB images under the directory DIR
57 instead of the root directory
58 --grub-mkimage=FILE use FILE as grub-mkimage
59 --grub-mkdevicemap=FILE use FILE as grub-mkdevicemap
60 --grub-probe=FILE use FILE as grub-probe
61 --no-floppy do not probe any floppy drive
62 --recheck probe a device map even if it already exists
64 grub-install copies GRUB images into the DIR/boot directory specified by
65 --root-directory.
67 Report bugs to <bug-grub@gnu.org>.
68 EOF
71 # Check the arguments.
72 for option in "$@"; do
73 case "$option" in
74 -h | --help)
75 usage
76 exit 0 ;;
77 -v | --version)
78 echo "grub-install (GNU GRUB ${PACKAGE_VERSION})"
79 exit 0 ;;
80 --modules=*)
81 modules=`echo "$option" | sed 's/--modules=//'` ;;
82 --root-directory=*)
83 rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
84 --grub-mkimage=*)
85 grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
86 --grub-mkdevicemap=*)
87 grub_mkdevicemap=`echo "$option" | sed 's/--grub-mkdevicemap=//'` ;;
88 --grub-probe=*)
89 grub_probe=`echo "$option" | sed 's/--grub-probe=//'` ;;
90 --no-floppy)
91 no_floppy="--no-floppy" ;;
92 --recheck)
93 recheck=yes ;;
94 # This is an undocumented feature...
95 --debug)
96 debug=yes ;;
98 echo "Unrecognized option \`$option'" 1>&2
99 usage
100 exit 1
102 esac
103 done
105 # If the debugging feature is enabled, print commands.
106 if test $debug = yes; then
107 set -x
110 # Initialize these directories here, since ROOTDIR was initialized.
111 case "$host_os" in
112 netbsd* | openbsd*)
113 # Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub
114 # instead of /boot/grub.
115 grub_prefix=`echo /grub | sed ${transform}`
116 bootdir=${rootdir}
119 # Use /boot/grub by default.
120 bootdir=${rootdir}/boot
122 esac
124 grubdir=${bootdir}/`echo grub | sed ${transform}`
125 device_map=${grubdir}/device.map
127 # Check if GRUB is installed.
128 set $grub_mkimage dummy
129 if test -f "$1"; then
131 else
132 echo "$1: Not found." 1>&2
133 exit 1
136 set $grub_mkdevicemap dummy
137 if test -f "$1"; then
139 else
140 echo "$1: Not found." 1>&2
141 exit 1
144 # Create the GRUB directory if it is not present.
145 test -d "$bootdir" || mkdir "$bootdir" || exit 1
146 test -d "$grubdir" || mkdir "$grubdir" || exit 1
148 # If --recheck is specified, remove the device map, if present.
149 if test $recheck = yes; then
150 rm -f $device_map
153 # Create the device map file if it is not present.
154 if test -f "$device_map"; then
156 else
157 # Create a safe temporary file.
158 test -n "$mklog" && log_file=`$mklog`
160 $grub_mkdevicemap --device-map=$device_map $no_floppy || exit 1
163 # Make sure that there is no duplicated entry.
164 tmp=`sed -n '/^([fh]d[0-9]*)/s/\(^(.*)\).*/\1/p' $device_map \
165 | sort | uniq -d | sed -n 1p`
166 if test -n "$tmp"; then
167 echo "The drive $tmp is defined multiple times in the device map $device_map" 1>&2
168 exit 1
171 # Copy the GRUB images to the GRUB directory.
172 for file in ${grubdir}/*.mod ${grubdir}/*.lst; do
173 if test -f $file && [ "`basename $file`" != menu.lst ]; then
174 rm -f $file || exit 1
176 done
177 for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do
178 cp -f $file ${grubdir} || exit 1
179 done
181 # Create the core image. First, auto-detect the filesystem module.
182 fs_module=`$grub_probe --target=fs --device-map=${device_map} ${grubdir}`
183 if test "x$fs_module" = xfat; then :; else
184 echo "${grubdir} doesn't look like an EFI partition." 1>&2
185 exit 1
188 # Then the partition map module. In order to support partition-less media,
189 # this command is allowed to fail (--target=fs already grants us that the
190 # filesystem will be accessible).
191 partmap_module=`$grub_probe --target=partmap --device-map=${device_map} ${grubdir} 2> /dev/null`
193 # Device abstraction module, if any (lvm, raid).
194 devabstraction_module=`$grub_probe --target=abstraction --device-map=${device_map} ${grubdir}`
196 # _chain is often useful
197 modules="$modules $fs_module $partmap_module $devabstraction_module _chain"
199 $grub_mkimage --output=${grubdir}/grub.efi $modules || exit 1
201 # Prompt the user to check if the device map is correct.
202 echo "Installation finished. No error reported."
203 echo "This is the contents of the device map $device_map."
204 echo "Check if this is correct or not. If any of the lines is incorrect,"
205 echo "fix it and re-run the script \`grub-install'."
206 echo
208 cat $device_map
210 # Bye.
211 exit 0