3 # Install GRUB on your drive.
4 # Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 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@"
23 exec_prefix
=@exec_prefix@
27 PACKAGE_NAME
=@PACKAGE_NAME@
28 PACKAGE_TARNAME
=@PACKAGE_TARNAME@
29 PACKAGE_VERSION
=@PACKAGE_VERSION@
30 target_cpu
=@target_cpu@
33 font
=@datadir@
/@PACKAGE_TARNAME@
/ascii.pf2
34 pkglibdir
=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`
36 grub_setup=${sbindir}/`echo grub-setup |
sed ${transform}`
37 if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] || [ "${target_cpu}-${platform}" = "mips-yeeloong" ] ; then
38 grub_mkimage=${bindir}/`echo grub-mkimage |
sed ${transform}`
40 grub_mkimage=${bindir}/`echo grub-mkelfimage |
sed ${transform}`
42 grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap |
sed ${transform}`
43 grub_probe=${sbindir}/`echo grub-probe |
sed ${transform}`
44 grub_editenv=${bindir}/`echo grub-editenv |
sed ${transform}`
46 grub_prefix=`echo /boot
/grub |
sed ${transform}`
55 if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
57 elif [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
67 Usage: grub-install [OPTION] install_device
68 Install GRUB on your drive.
70 -h, --help print this message and exit
71 -v, --version print the version information and exit
72 --modules=MODULES pre-load specified modules MODULES
73 --root-directory=DIR install GRUB images under the directory DIR
74 instead of the root directory
75 --grub-setup=FILE use FILE as grub-setup
76 --grub-mkimage=FILE use FILE as grub-mkimage
77 --grub-mkdevicemap=FILE use FILE as grub-mkdevicemap
78 --grub-probe=FILE use FILE as grub-probe
79 --no-floppy do not probe any floppy drive
80 --recheck probe a device map even if it already exists
81 --force install even if problems are detected
83 if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
85 --disk-module=MODULE disk module to use
88 if [ "${target_cpu}-${platform}" = "mips-yeeloong" ] ; then
90 --font=FILE font file to use
95 INSTALL_DEVICE can be a GRUB device name or a system device filename.
97 grub-install copies GRUB images into /boot/grub (or /grub on NetBSD and
98 OpenBSD), and uses grub-setup to install grub into the boot sector.
100 If the --root-directory option is used, then grub-install will copy
101 images into the operating system installation rooted at that directory.
103 Report bugs to <bug-grub@gnu.org>.
107 # Check the arguments.
108 for option in "$@"; do
114 echo "grub-install (GNU GRUB ${PACKAGE_VERSION})"
117 modules=`echo "$option" |
sed 's/--modules=//'` ;;
119 font=`echo "$option" |
sed 's/--font=//'` ;;
121 rootdir=`echo "$option" |
sed 's/--root-directory=//'` ;;
123 grub_setup=`echo "$option" |
sed 's/--grub-setup=//'` ;;
125 grub_mkimage=`echo "$option" |
sed 's/--grub-mkimage=//'` ;;
126 --grub-mkdevicemap=*)
127 grub_mkdevicemap=`echo "$option" |
sed 's/--grub-mkdevicemap=//'` ;;
129 grub_probe=`echo "$option" |
sed 's/--grub-probe=//'` ;;
131 no_floppy="--no-floppy" ;;
135 if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
136 disk_module=`echo "$option" |
sed 's/--disk-module=//'`
138 # This is an undocumented feature...
142 setup_force="--force" ;;
144 echo "Unrecognized option \`$option'" 1>&2
149 if test "x$install_device" != x; then
150 echo "More than one install_devices?" 1>&2
154 install_device="${option}" ;;
158 # for make_system_path_relative_to_its_root()
159 . ${libdir}/grub/grub-mkconfig_lib
161 if test "x$install_device" = x && test "${target_cpu}-${platform}" != "mips-yeeloong"; then
162 echo "install_device not specified." 1>&2
167 # If the debugging feature is enabled, print commands.
169 if test $debug = yes; then
171 setup_verbose="--verbose"
174 # Initialize these directories here, since ROOTDIR was initialized.
177 # Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub
178 # instead of /boot/grub.
179 grub_prefix=`echo /grub | sed ${transform}`
183 # Use /boot/grub by default.
184 bootdir=${rootdir}/boot
188 grubdir=${bootdir}/`echo grub | sed ${transform}`
189 device_map=${grubdir}/device.map
191 grub_probe="${grub_probe} --device-map=${device_map}"
193 # Check if GRUB is installed.
194 if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
195 set $grub_setup dummy
196 if test -f "$1"; then
199 echo "$1: Not found." 1>&2
204 set $grub_mkimage dummy
205 if test -f "$1"; then
208 echo "$1: Not found." 1>&2
212 set $grub_mkdevicemap dummy
213 if test -f "$1"; then
216 echo "$1: Not found." 1>&2
220 # Create the GRUB directory if it is not present.
221 test -d "$bootdir" || mkdir "$bootdir" || exit 1
222 test -d "$grubdir" || mkdir "$grubdir" || exit 1
224 # If --recheck is specified, remove the device map, if present.
225 if test $recheck = yes; then
229 # Create the device map file if it is not present.
230 if test -f "$device_map"; then
233 # Create a safe temporary file.
234 test -n "$mklog" && log_file=`$mklog`
236 $grub_mkdevicemap --device-map=$device_map $no_floppy || exit 1
239 # Make sure that there is no duplicated entry.
240 tmp=`sed -n '/^
([fh
]d
[0-9]*)/s
/\
(^
(.
*)\
).
*/\
1/p
' $device_map \
241 | sort | uniq -d | sed -n 1p`
242 if test -n "$tmp"; then
243 echo "The drive $tmp is defined multiple times in the device map $device_map" 1>&2
247 # Copy the GRUB images to the GRUB directory.
248 for file in ${grubdir}/*.mod ${grubdir}/*.lst ${grubdir}/*.img ${grubdir}/efiemu??.o; do
249 if test -f $file && [ "`basename $file`" != menu.lst ]; then
250 rm -f $file || exit 1
253 for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do
254 cp -f $file ${grubdir} || exit 1
256 if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
257 for file in ${pkglibdir}/*.img ${pkglibdir}/efiemu??.o; do
258 if test -f $file; then
259 cp -f $file ${grubdir} || exit 1
265 mkdir -p ${grubdir}/locale/
266 for file in ${grubdir}/locale/*.mo ${pkglibdir}/locale/*.mo; do
267 if test -f "$file"; then
268 cp -f "$file" ${grubdir}/locale/
272 # Write device to a variable so we don't have to traverse
/dev every
time.
273 grub_device
=`$grub_probe --target=device ${grubdir}`
275 if ! test -f ${grubdir}/grubenv
; then
276 $grub_editenv ${grubdir}/grubenv create
279 # Create the core image. First, auto-detect the filesystem module.
280 fs_module
=`$grub_probe --target=fs --device ${grub_device}`
281 if test "x$fs_module" = x
-a "x$modules" = x
; then
282 echo "Auto-detection of a filesystem module failed." 1>&2
283 echo "Please specify the module with the option \`--modules' explicitly." 1>&2
287 # Then the partition map module. In order to support partition-less media,
288 # this command is allowed to fail (--target=fs already grants us that the
289 # filesystem will be accessible).
290 partmap_module
=`$grub_probe --target=partmap --device ${grub_device} 2> /dev/null`
292 # Device abstraction module, if any (lvm, raid).
293 devabstraction_module
=`$grub_probe --target=abstraction --device ${grub_device}`
295 # The order in this list is critical. Be careful when modifying it.
296 modules
="$modules $disk_module"
297 modules
="$modules $fs_module $partmap_module $devabstraction_module"
299 relative_grubdir
=`make_system_path_relative_to_its_root ${grubdir}` ||
exit 1
300 if [ "x${relative_grubdir}" = "x" ] ; then
307 if [ "x${devabstraction_module}" = "x" ] ; then
308 if [ x
"${install_device}" != x
]; then
309 if echo "${install_device}" |
grep -qx "(.*)" ; then
310 install_drive
="${install_device}"
312 install_drive
="`$grub_probe --target=drive --device ${install_device}`"
314 install_drive
="`echo ${install_drive} | sed -e s/,[0-9]*[a-z]*//g`"
316 grub_drive
="`$grub_probe --target=drive --device ${grub_device}`"
318 # Strip partition number
319 grub_drive
="`echo ${grub_drive} | sed -e s/,[0-9]*[a-z]*//g`"
320 if [ "$disk_module" = ata
] ; then
321 # generic method (used on coreboot and ata mod)
322 uuid
="`$grub_probe --target=fs_uuid --device ${grub_device}`"
323 if [ "x${uuid}" = "x" ] ; then
324 echo "UUID needed with ata mod, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2
327 echo "search.fs_uuid ${uuid} root " > ${grubdir}/load.cfg
328 echo 'set prefix=($root)'"${relative_grubdir}" >> ${grubdir}/load.cfg
329 config_opt
="-c ${grubdir}/load.cfg "
330 modules
="$modules search_fs_uuid"
331 elif [ "x${grub_drive}" != "x${install_drive}" ] ; then
332 uuid
="`$grub_probe --target=fs_uuid --device ${grub_device}`"
333 if [ "x${uuid}" = "x" ] ; then
334 echo "You attempted a cross-disk install, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2
337 echo "search.fs_uuid ${uuid} root " > ${grubdir}/load.cfg
338 echo 'set prefix=($root)'"${relative_grubdir}" >> ${grubdir}/load.cfg
339 config_opt
="-c ${grubdir}/load.cfg "
340 modules
="$modules search_fs_uuid"
343 prefix_drive
=`$grub_probe --target=drive --device ${grub_device}`
346 if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
347 $grub_mkimage ${config_opt} --output=${grubdir}/core.img --prefix=${prefix_drive}${relative_grubdir} $modules ||
exit 1
349 # Now perform the installation.
350 $grub_setup ${setup_verbose} ${setup_force} --directory=${grubdir} --device-map=${device_map} \
351 ${install_device} ||
exit 1
352 elif [ "${target_cpu}-${platform}" = "mips-yeeloong" ] ; then
353 $grub_mkimage ${config_opt} -f ${font} -d ${pkglibdir} -O elf --output=/boot/grub.elf --prefix=${prefix_drive}${relative_grubdir} $modules ||
exit 1
355 $grub_mkimage ${config_opt} -d ${pkglibdir} --output=/boot/multiboot.img --prefix=${prefix_drive}${relative_grubdir} $modules ||
exit 1
358 echo "Installation finished. No error reported."