]> git.proxmox.com Git - grub2.git/blame - util/i386/pc/grub-install.in
2006-05-29 Yoshinori K. Okuji <okuji@enbug.org>
[grub2.git] / util / i386 / pc / grub-install.in
CommitLineData
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.
21prefix=@prefix@
22exec_prefix=@exec_prefix@
23sbindir=@sbindir@
577b4050 24bindir=@bindir@
05568c2e 25libdir=@libdir@
075a1650 26PACKAGE_NAME=@PACKAGE_NAME@
27PACKAGE_TARNAME=@PACKAGE_TARNAME@
28PACKAGE_VERSION=@PACKAGE_VERSION@
b977bf01 29target_cpu=@target_cpu@
05568c2e 30platform=@platform@
b977bf01 31pkglibdir=${libdir}/${PACKAGE_TARNAME}/${target_cpu}-${platform}
075a1650 32
33grub_setup=${sbindir}/grub-setup
577b4050 34grub_mkimage=${bindir}/grub-mkimage
075a1650 35grub_mkdevicemap=${sbindir}/grub-mkdevicemap
0e143073 36grub_probefs=${sbindir}/grub-probefs
075a1650 37rootdir=
38grub_prefix=/boot/grub
0e143073 39modules=
075a1650 40
41install_device=
42no_floppy=
43force_lba=
44recheck=no
45debug=no
46
47# Usage: usage
48# Print the usage.
49usage () {
50 cat <<EOF
51Usage: grub-install [OPTION] install_device
52Install 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
66INSTALL_DEVICE can be a GRUB device name or a system device filename.
67
68grub-install copies GRUB images into the DIR/boot directory specfied by
69--root-directory, and uses grub-setup to install grub into the boot
70sector.
71
72Report bugs to <bug-grub@gnu.org>.
73EOF
74}
75
76# Check the arguments.
77for 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
117done
118
119if test "x$install_device" = x; then
120 echo "install_device not specified." 1>&2
121 usage
122 exit 1
123fi
124
125# If the debugging feature is enabled, print commands.
126if test $debug = yes; then
127 set -x
128fi
129
130# Initialize these directories here, since ROOTDIR was initialized.
131case "$host_os" in
132netbsd* | 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 ;;
142esac
143
144grubdir=${bootdir}/grub
145device_map=${grubdir}/device.map
146
147# Check if GRUB is installed.
148set $grub_setup dummy
149if test -f "$1"; then
150 :
151else
152 echo "$1: Not found." 1>&2
153 exit 1
154fi
155
156set $grub_mkimage dummy
157if test -f "$1"; then
158 :
159else
160 echo "$1: Not found." 1>&2
161 exit 1
162fi
163
164set $grub_mkdevicemap dummy
165if test -f "$1"; then
166 :
167else
168 echo "$1: Not found." 1>&2
169 exit 1
170fi
171
172# Create the GRUB directory if it is not present.
173test -d "$bootdir" || mkdir "$bootdir" || exit 1
174test -d "$grubdir" || mkdir "$grubdir" || exit 1
175
176# If --recheck is specified, remove the device map, if present.
177if test $recheck = yes; then
178 rm -f $device_map
179fi
180
181# Create the device map file if it is not present.
182if test -f "$device_map"; then
183 :
184else
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
189fi
190
191# Make sure that there is no duplicated entry.
192tmp=`sed -n '/^([fh]d[0-9]*)/s/\(^(.*)\).*/\1/p' $device_map \
193 | sort | uniq -d | sed -n 1p`
194if test -n "$tmp"; then
195 echo "The drive $tmp is defined multiple times in the device map $device_map" 1>&2
196 exit 1
197fi
198
199# Copy the GRUB images to the GRUB directory.
200for file in ${grubdir}/*.mod ${grubdir}/*.lst ${grubdir}/*.img; do
201 if test -f $file; then
202 rm -f $file || exit 1
203 fi
204done
05568c2e 205for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst ${pkglibdir}/*.img; do
075a1650 206 cp -f $file ${grubdir} || exit 1
207done
208
0e143073 209# Create the core image. First, auto-detect the filesystme module.
210fs_module=`$grub_probefs --device-map=${device_map} ${grubdir}`
211if 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
215fi
216
217# Typically, _chain and pc are required.
218modules="$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.
227echo "Installation finished. No error reported."
228echo "This is the contents of the device map $device_map."
229echo "Check if this is correct or not. If any of the lines is incorrect,"
230echo "fix it and re-run the script \`grub-install'."
231echo
232
233cat $device_map
234
235# Bye.
236exit 0