]>
Commit | Line | Data |
---|---|---|
075a1650 | 1 | #! /bin/sh |
2 | ||
3 | # Install GRUB on your drive. | |
05568c2e | 4 | # Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006 Free Software Foundation, Inc. |
075a1650 | 5 | # |
6 | # This file is free software; you can redistribute it and/or modify it | |
7 | # under the terms of the GNU General Public License as published by | |
8 | # the Free Software Foundation; either version 2 of the License, or | |
9 | # (at your option) any later version. | |
10 | # | |
11 | # This program is distributed in the hope that it will be useful, but | |
12 | # WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | # General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin St - Suite 330, Boston, MA 02110, USA. | |
19 | ||
20 | # Initialize some variables. | |
21 | prefix=@prefix@ | |
22 | exec_prefix=@exec_prefix@ | |
23 | sbindir=@sbindir@ | |
577b4050 | 24 | bindir=@bindir@ |
05568c2e | 25 | libdir=@libdir@ |
075a1650 | 26 | PACKAGE_NAME=@PACKAGE_NAME@ |
27 | PACKAGE_TARNAME=@PACKAGE_TARNAME@ | |
28 | PACKAGE_VERSION=@PACKAGE_VERSION@ | |
29 | host_cpu=@host_cpu@ | |
05568c2e | 30 | platform=@platform@ |
31 | pkglibdir=${libdir}/${PACKAGE_TARNAME}/${host_cpu}-${platform} | |
075a1650 | 32 | |
33 | grub_setup=${sbindir}/grub-setup | |
577b4050 | 34 | grub_mkimage=${bindir}/grub-mkimage |
075a1650 | 35 | grub_mkdevicemap=${sbindir}/grub-mkdevicemap |
0e143073 | 36 | grub_probefs=${sbindir}/grub-probefs |
075a1650 | 37 | rootdir= |
38 | grub_prefix=/boot/grub | |
0e143073 | 39 | modules= |
075a1650 | 40 | |
41 | install_device= | |
42 | no_floppy= | |
43 | force_lba= | |
44 | recheck=no | |
45 | debug=no | |
46 | ||
47 | # Usage: usage | |
48 | # Print the usage. | |
49 | usage () { | |
50 | cat <<EOF | |
51 | Usage: grub-install [OPTION] install_device | |
52 | Install GRUB on your drive. | |
53 | ||
54 | -h, --help print this message and exit | |
55 | -v, --version print the version information and exit | |
0e143073 | 56 | --modules=MODULES pre-load specified modules MODULES |
075a1650 | 57 | --root-directory=DIR install GRUB images under the directory DIR |
58 | instead of the root directory | |
59 | --grub-setup=FILE use FILE as grub-setup | |
60 | --grub-mkimage=FILE use FILE as grub-mkimage | |
61 | --grub-mkdevicemap=FILE use FILE as grub-mkdevicemap | |
0e143073 | 62 | --grub-probefs=FILE use FILE as grub-probefs |
075a1650 | 63 | --no-floppy do not probe any floppy drive |
64 | --recheck probe a device map even if it already exists | |
65 | ||
66 | INSTALL_DEVICE can be a GRUB device name or a system device filename. | |
67 | ||
68 | grub-install copies GRUB images into the DIR/boot directory specfied by | |
69 | --root-directory, and uses grub-setup to install grub into the boot | |
70 | sector. | |
71 | ||
72 | Report bugs to <bug-grub@gnu.org>. | |
73 | EOF | |
74 | } | |
75 | ||
76 | # Check the arguments. | |
77 | for option in "$@"; do | |
78 | case "$option" in | |
79 | -h | --help) | |
80 | usage | |
81 | exit 0 ;; | |
82 | -v | --version) | |
83 | echo "grub-install (GNU GRUB ${PACKAGE_VERSION})" | |
84 | exit 0 ;; | |
0e143073 | 85 | --modules=*) |
86 | modules=`echo "$option" | sed 's/--modules=//'` ;; | |
075a1650 | 87 | --root-directory=*) |
88 | rootdir=`echo "$option" | sed 's/--root-directory=//'` ;; | |
89 | --grub-setup=*) | |
90 | grub_setup=`echo "$option" | sed 's/--grub-setup=//'` ;; | |
91 | --grub-mkimage=*) | |
92 | grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;; | |
93 | --grub-mkdevicemap=*) | |
0e143073 | 94 | grub_mkdevicemap=`echo "$option" | sed 's/--grub-mkdevicemap=//'` ;; |
95 | --grub-probefs=*) | |
96 | grub_probefs=`echo "$option" | sed 's/--grub-probefs=//'` ;; | |
075a1650 | 97 | --no-floppy) |
98 | no_floppy="--no-floppy" ;; | |
99 | --recheck) | |
100 | recheck=yes ;; | |
101 | # This is an undocumented feature... | |
102 | --debug) | |
103 | debug=yes ;; | |
104 | -*) | |
105 | echo "Unrecognized option \`$option'" 1>&2 | |
106 | usage | |
107 | exit 1 | |
108 | ;; | |
109 | *) | |
110 | if test "x$install_device" != x; then | |
111 | echo "More than one install_devices?" 1>&2 | |
112 | usage | |
113 | exit 1 | |
114 | fi | |
115 | install_device="${option}" ;; | |
116 | esac | |
117 | done | |
118 | ||
119 | if test "x$install_device" = x; then | |
120 | echo "install_device not specified." 1>&2 | |
121 | usage | |
122 | exit 1 | |
123 | fi | |
124 | ||
125 | # If the debugging feature is enabled, print commands. | |
126 | if test $debug = yes; then | |
127 | set -x | |
128 | fi | |
129 | ||
130 | # Initialize these directories here, since ROOTDIR was initialized. | |
131 | case "$host_os" in | |
132 | netbsd* | openbsd*) | |
133 | # Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub | |
134 | # instead of /boot/grub. | |
135 | grub_prefix=/grub | |
136 | bootdir=${rootdir} | |
137 | ;; | |
138 | *) | |
139 | # Use /boot/grub by default. | |
140 | bootdir=${rootdir}/boot | |
141 | ;; | |
142 | esac | |
143 | ||
144 | grubdir=${bootdir}/grub | |
145 | device_map=${grubdir}/device.map | |
146 | ||
147 | # Check if GRUB is installed. | |
148 | set $grub_setup dummy | |
149 | if test -f "$1"; then | |
150 | : | |
151 | else | |
152 | echo "$1: Not found." 1>&2 | |
153 | exit 1 | |
154 | fi | |
155 | ||
156 | set $grub_mkimage dummy | |
157 | if test -f "$1"; then | |
158 | : | |
159 | else | |
160 | echo "$1: Not found." 1>&2 | |
161 | exit 1 | |
162 | fi | |
163 | ||
164 | set $grub_mkdevicemap dummy | |
165 | if test -f "$1"; then | |
166 | : | |
167 | else | |
168 | echo "$1: Not found." 1>&2 | |
169 | exit 1 | |
170 | fi | |
171 | ||
172 | # Create the GRUB directory if it is not present. | |
173 | test -d "$bootdir" || mkdir "$bootdir" || exit 1 | |
174 | test -d "$grubdir" || mkdir "$grubdir" || exit 1 | |
175 | ||
176 | # If --recheck is specified, remove the device map, if present. | |
177 | if test $recheck = yes; then | |
178 | rm -f $device_map | |
179 | fi | |
180 | ||
181 | # Create the device map file if it is not present. | |
182 | if test -f "$device_map"; then | |
183 | : | |
184 | else | |
185 | # Create a safe temporary file. | |
186 | test -n "$mklog" && log_file=`$mklog` | |
187 | ||
188 | $grub_mkdevicemap --device-map=$device_map $no_floppy || exit 1 | |
189 | fi | |
190 | ||
191 | # Make sure that there is no duplicated entry. | |
192 | tmp=`sed -n '/^([fh]d[0-9]*)/s/\(^(.*)\).*/\1/p' $device_map \ | |
193 | | sort | uniq -d | sed -n 1p` | |
194 | if test -n "$tmp"; then | |
195 | echo "The drive $tmp is defined multiple times in the device map $device_map" 1>&2 | |
196 | exit 1 | |
197 | fi | |
198 | ||
199 | # Copy the GRUB images to the GRUB directory. | |
200 | for file in ${grubdir}/*.mod ${grubdir}/*.lst ${grubdir}/*.img; do | |
201 | if test -f $file; then | |
202 | rm -f $file || exit 1 | |
203 | fi | |
204 | done | |
05568c2e | 205 | for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst ${pkglibdir}/*.img; do |
075a1650 | 206 | cp -f $file ${grubdir} || exit 1 |
207 | done | |
208 | ||
0e143073 | 209 | # Create the core image. First, auto-detect the filesystme module. |
210 | fs_module=`$grub_probefs --device-map=${device_map} ${grubdir}` | |
211 | if test "x$fs_module" = x -a "x$modules" = x; then | |
212 | echo "Auto-detection of a filesystem module failed." 1>&2 | |
6de53d26 | 213 | echo "Please specify the module with the option \`--modules' explicitly." 1>&2 |
0e143073 | 214 | exit 1 |
215 | fi | |
216 | ||
217 | # Typically, _chain and pc are required. | |
218 | modules="$modules $fs_module _chain pc" | |
219 | ||
075a1650 | 220 | $grub_mkimage --output=${grubdir}/core.img $modules || exit 1 |
221 | ||
222 | # Now perform the installation. | |
f4917dfd | 223 | $grub_setup --directory=${grubdir} --device-map=${device_map} \ |
224 | ${install_device} || exit 1 | |
075a1650 | 225 | |
226 | # Prompt the user to check if the device map is correct. | |
227 | echo "Installation finished. No error reported." | |
228 | echo "This is the contents of the device map $device_map." | |
229 | echo "Check if this is correct or not. If any of the lines is incorrect," | |
230 | echo "fix it and re-run the script \`grub-install'." | |
231 | echo | |
232 | ||
233 | cat $device_map | |
234 | ||
235 | # Bye. | |
236 | exit 0 |