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 # This script uses `ofpathname', which is downloadable from
20 # http://ppc64-utils.ozlabs.org .
22 # Initialize some variables.
23 transform
="@program_transform_name@"
26 exec_prefix
=@exec_prefix@
30 PACKAGE_NAME
=@PACKAGE_NAME@
31 PACKAGE_TARNAME
=@PACKAGE_TARNAME@
32 PACKAGE_VERSION
=@PACKAGE_VERSION@
33 target_cpu
=@target_cpu@
35 pkglibdir
=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`
37 grub_mkimage=${bindir}/`echo grub-mkelfimage |
sed ${transform}`
38 grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap |
sed ${transform}`
39 grub_probe=${sbindir}/`echo grub-probe |
sed ${transform}`
41 grub_prefix=`echo /boot
/grub |
sed ${transform}`
48 ofpathname=/usr/sbin/ofpathname
49 nvsetenv=/sbin/nvsetenv
55 Usage: grub-install [OPTION] [install_device]
56 Install GRUB on your drive.
58 -h, --help print this message and exit
59 -v, --version print the version information and exit
60 --modules=MODULES pre-load specified modules MODULES
61 --root-directory=DIR install GRUB images under the directory DIR
62 instead of the root directory
63 --grub-mkdevicemap=FILE use FILE as grub-mkdevicemap
64 --grub-mkimage=FILE use FILE as grub-mkimage
65 --grub-probe=FILE use FILE as grub-probe
66 --no-nvram don't update the boot-device NVRAM variable
68 grub-install copies GRUB images into the DIR/boot directory specified by
69 --root-directory, and uses nvsetenv to set the Open Firmware boot-device
72 Report bugs to <bug-grub@gnu.org>.
76 # Check the arguments.
77 for option in "$@"; do
83 echo "grub-install (GNU GRUB ${PACKAGE_VERSION})"
86 modules=`echo "$option" |
sed 's/--modules=//'` ;;
88 rootdir=`echo "$option" |
sed 's/--root-directory=//'` ;;
90 grub_mkdevicemap=`echo "$option" |
sed 's/--grub-mkdevicemap=//'` ;;
92 grub_mkimage=`echo "$option" |
sed 's/--grub-mkimage=//'` ;;
94 grub_probe=`echo "$option" |
sed 's/--grub-probe=//'` ;;
97 # This is an undocumented feature...
101 echo "Unrecognized option \`$option'" 1>&2
106 if test "x$install_device" != x; then
107 echo "More than one install_devices?" 1>&2
111 install_device="${option}" ;;
115 # If the debugging feature is enabled, print commands.
116 if test $debug = yes; then
120 # Initialize these directories here, since ROOTDIR was initialized.
121 bootdir=${rootdir}/boot
122 grubdir=${bootdir}/`echo grub | sed ${transform}`
123 device_map=${grubdir}/device.map
125 set $grub_mkimage dummy
126 if test -f "$1"; then
129 echo "$1: Not found." 1>&2
133 # Find the partition at the right mount point.
134 install_device=`$grub_mkdevicemap --device-map=/dev/stdout | $grub_probe --target=device --device-map=/dev/stdin ${grubdir}`
136 if test "x$install_device" = "x`$grub_mkdevicemap --device-map=/dev/stdout | $grub_probe --target=device --device-map=/dev/stdin ${bootdir}`"; then
137 echo "$grubdir must be a mount point."
140 # XXX warn on firmware-unreadable filesystems?
142 # Create the GRUB directory if it is not present.
143 test -d "$bootdir" || mkdir "$bootdir" || exit 1
144 test -d "$grubdir" || mkdir "$grubdir" || exit 1
146 # Create the device map file if it is not present.
147 if test -f "$device_map"; then
150 # Create a safe temporary file.
151 test -n "$mklog" && log_file=`$mklog`
153 $grub_mkdevicemap --device-map=$device_map $no_floppy || exit 1
156 # Copy the GRUB images to the GRUB directory.
157 for file in ${grubdir}/*.mod ${grubdir}/*.lst ; do
158 if test -f $file; then
159 rm -f $file || exit 1
162 for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst ; do
163 cp -f $file ${grubdir} || exit 1
166 # Create the core image. First, auto-detect the filesystem module.
167 fs_module=`$grub_probe --target=fs --device-map=${device_map} ${grubdir}`
168 if test "x$fs_module" = x -a "x$modules" = x; then
169 echo "Auto-detection of a filesystem module failed." 1>&2
170 echo "Please specify the module with the option \`--modules' explicitly.
" 1>&2
174 # Then the partition map module. In order to support partition-less media,
175 # this command is allowed to fail (--target=fs already grants us that the
176 # filesystem will be accessible).
177 partmap_module=`$grub_probe --target=partmap --device-map=${device_map} ${grubdir} 2> /dev/null`
179 # Device abstraction module, if any (lvm, raid).
180 devabstraction_module=`$grub_probe --target=abstraction --device-map=${device_map} ${grubdir}`
182 modules="$modules $fs_module $partmap_module $devabstraction_module"
184 # Now perform the installation.
185 "$grub_mkimage" --directory=${pkglibdir} --output=${grubdir}/grub $modules || exit 1
187 if test $update_nvram = yes; then
188 set $ofpathname dummy
189 if test -f "$1"; then
192 echo "$1: Not found.
" 1>&2
197 if test -f "$1"; then
200 echo "$1: Not found.
" 1>&2
204 # Get the Open Firmware device tree path translation.
205 dev=`echo $install_device | sed -e 's/\/dev\///' -e 's/[0-9]\+//'`
206 partno=`echo $install_device | sed -e 's/.*[^0-9]\([0-9]\+\)$/\1/'`
207 ofpath=`$ofpathname $dev` || {
208 echo "Couldn
't find Open Firmware device tree path for $dev."
209 echo "You will have to set boot-device manually."
213 # Point boot-device at the new grub install
214 boot_device="boot-device $ofpath:$partno,\\grub"
215 "$nvsetenv" "$boot_device" || {
216 echo "$nvsetenv failed."
217 echo "You will have to set boot-device manually. At the Open Firmware prompt, type:"
218 echo " setenv $boot_device"
223 # Prompt the user to check if the device map is correct.
224 echo "Installation finished. No error reported."
225 echo "This is the contents of the device map $device_map."
226 echo "Check if this is correct or not. If any of the lines is incorrect,"
227 echo "fix it and re-run the script \`grub-install'.
"