Updated PCI IDs to latest snapshot.
[tangerine.git] / arch / common / boot / grub2 / util / i386 / pc / grub-install.in
blob4b39cbfdd61f344dcda1ff8f0f20425a4cf1ced1
1 #! /bin/sh
3 # Install GRUB on your drive.
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_setup=${sbindir}/`echo grub-setup | sed ${transform}`
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 rootdir=
39 grub_prefix=`echo /boot/grub | sed ${transform}`
40 modules=
42 install_device=
43 no_floppy=
44 force_lba=
45 recheck=no
46 debug=no
48 # Usage: usage
49 # Print the usage.
50 usage () {
51 cat <<EOF
52 Usage: grub-install [OPTION] install_device
53 Install GRUB on your drive.
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-setup=FILE use FILE as grub-setup
61 --grub-mkimage=FILE use FILE as grub-mkimage
62 --grub-mkdevicemap=FILE use FILE as grub-mkdevicemap
63 --grub-probe=FILE use FILE as grub-probe
64 --no-floppy do not probe any floppy drive
65 --recheck probe a device map even if it already exists
67 INSTALL_DEVICE can be a GRUB device name or a system device filename.
69 grub-install copies GRUB images into the DIR/boot directory specified by
70 --root-directory, and uses grub-setup to install grub into the boot
71 sector.
73 Report bugs to <bug-grub@gnu.org>.
74 EOF
77 # Check the arguments.
78 for option in "$@"; do
79 case "$option" in
80 -h | --help)
81 usage
82 exit 0 ;;
83 -v | --version)
84 echo "grub-install (GNU GRUB ${PACKAGE_VERSION})"
85 exit 0 ;;
86 --modules=*)
87 modules=`echo "$option" | sed 's/--modules=//'` ;;
88 --root-directory=*)
89 rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
90 --grub-setup=*)
91 grub_setup=`echo "$option" | sed 's/--grub-setup=//'` ;;
92 --grub-mkimage=*)
93 grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
94 --grub-mkdevicemap=*)
95 grub_mkdevicemap=`echo "$option" | sed 's/--grub-mkdevicemap=//'` ;;
96 --grub-probe=*)
97 grub_probe=`echo "$option" | sed 's/--grub-probe=//'` ;;
98 --no-floppy)
99 no_floppy="--no-floppy" ;;
100 --recheck)
101 recheck=yes ;;
102 # This is an undocumented feature...
103 --debug)
104 debug=yes ;;
106 echo "Unrecognized option \`$option'" 1>&2
107 usage
108 exit 1
111 if test "x$install_device" != x; then
112 echo "More than one install_devices?" 1>&2
113 usage
114 exit 1
116 install_device="${option}" ;;
117 esac
118 done
120 # for make_system_path_relative_to_its_root()
121 . ${libdir}/grub/grub-mkconfig_lib
123 if test "x$install_device" = x; then
124 echo "install_device not specified." 1>&2
125 usage
126 exit 1
129 # If the debugging feature is enabled, print commands.
130 setup_verbose=
131 if test $debug = yes; then
132 set -x
133 setup_verbose="--verbose"
136 # Initialize these directories here, since ROOTDIR was initialized.
137 case "$host_os" in
138 netbsd* | openbsd*)
139 # Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub
140 # instead of /boot/grub.
141 grub_prefix=`echo /grub | sed ${transform}`
142 bootdir=${rootdir}
145 # Use /boot/grub by default.
146 bootdir=${rootdir}/boot
148 esac
150 grubdir=${bootdir}/`echo grub | sed ${transform}`
151 device_map=${grubdir}/device.map
153 grub_probe="${grub_probe} --device-map=${device_map}"
155 # Check if GRUB is installed.
156 set $grub_setup dummy
157 if test -f "$1"; then
159 else
160 echo "$1: Not found." 1>&2
161 exit 1
164 set $grub_mkimage dummy
165 if test -f "$1"; then
167 else
168 echo "$1: Not found." 1>&2
169 exit 1
172 set $grub_mkdevicemap dummy
173 if test -f "$1"; then
175 else
176 echo "$1: Not found." 1>&2
177 exit 1
180 # Create the GRUB directory if it is not present.
181 test -d "$bootdir" || mkdir "$bootdir" || exit 1
182 test -d "$grubdir" || mkdir "$grubdir" || exit 1
184 # If --recheck is specified, remove the device map, if present.
185 if test $recheck = yes; then
186 rm -f $device_map
189 # Create the device map file if it is not present.
190 if test -f "$device_map"; then
192 else
193 # Create a safe temporary file.
194 test -n "$mklog" && log_file=`$mklog`
196 $grub_mkdevicemap --device-map=$device_map $no_floppy || exit 1
199 # Make sure that there is no duplicated entry.
200 tmp=`sed -n '/^([fh]d[0-9]*)/s/\(^(.*)\).*/\1/p' $device_map \
201 | sort | uniq -d | sed -n 1p`
202 if test -n "$tmp"; then
203 echo "The drive $tmp is defined multiple times in the device map $device_map" 1>&2
204 exit 1
207 # Copy the GRUB images to the GRUB directory.
208 for file in ${grubdir}/*.mod ${grubdir}/*.lst ${grubdir}/*.img; do
209 if test -f $file && [ "`basename $file`" != menu.lst ]; then
210 rm -f $file || exit 1
212 done
213 for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst ${pkglibdir}/*.img; do
214 cp -f $file ${grubdir} || exit 1
215 done
217 # Write device to a variable so we don't have to traverse /dev every time.
218 grub_device=`$grub_probe --target=device ${grubdir}`
220 # Create the core image. First, auto-detect the filesystem module.
221 fs_module=`$grub_probe --target=fs --device ${grub_device}`
222 if test "x$fs_module" = x -a "x$modules" = x; then
223 echo "Auto-detection of a filesystem module failed." 1>&2
224 echo "Please specify the module with the option \`--modules' explicitly." 1>&2
225 exit 1
228 # Then the partition map module. In order to support partition-less media,
229 # this command is allowed to fail (--target=fs already grants us that the
230 # filesystem will be accessible).
231 partmap_module=`$grub_probe --target=partmap --device ${grub_device} 2> /dev/null`
233 # Device abstraction module, if any (lvm, raid).
234 devabstraction_module=`$grub_probe --target=abstraction --device ${grub_device}`
236 # The order in this list is critical. Be careful when modifying it.
237 modules="$modules $fs_module $partmap_module biosdisk $devabstraction_module"
239 prefix_drive=
240 if [ "x${devabstraction_module}" = "x" ] ; then
241 if echo "${install_device}" | grep -qx "(.*)" ; then
242 install_drive="${install_device}"
243 else
244 install_drive="`$grub_probe --target=drive --device ${install_device}`"
246 grub_drive="`$grub_probe --target=drive --device ${grub_device}`"
248 # Strip partition number
249 install_drive="`echo ${install_drive} | sed -e s/,[0-9]*//g`"
250 grub_drive="`echo ${grub_drive} | sed -e s/,[0-9]*//g`"
251 if [ "x${grub_drive}" != "x${install_drive}" ] ; then
252 uuid="`$grub_probe --target=fs_uuid --device ${grub_device}`"
253 if [ "x${uuid}" = "x" ] ; then
254 echo "You attempted a cross-disk install, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2
255 exit 1
257 prefix_drive="(UUID=${uuid})"
258 modules="$modules fs_uuid"
260 else
261 prefix_drive=`$grub_probe --target=drive --device ${grub_device}`
264 relative_grubdir=`make_system_path_relative_to_its_root ${grubdir}` || exit 1
265 if [ "x${relative_grubdir}" = "x" ] ; then
266 relative_grubdir=/
269 $grub_mkimage --output=${grubdir}/core.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
271 # Now perform the installation.
272 $grub_setup ${setup_verbose} --directory=${grubdir} --device-map=${device_map} \
273 ${install_device} || exit 1
275 # Prompt the user to check if the device map is correct.
276 echo "Installation finished. No error reported."
277 echo "This is the contents of the device map $device_map."
278 echo "Check if this is correct or not. If any of the lines is incorrect,"
279 echo "fix it and re-run the script \`grub-install'."
280 echo
282 cat $device_map
284 # Bye.
285 exit 0