4 # This is a little helper script that tries to convert linux-style device
5 # names to grub-style. It's not very smart, so it
6 # probably won't work for more complicated setups.
8 # If it doesn't work for you, try installing grub manually:
10 # # mkdir -p /boot/grub
11 # # cp /usr/lib/grub/i386-pc/* /boot/grub/
13 # Then start up the 'grub' shell and run something like the following:
18 # The "root" line should point to the partition your kernel is located on,
19 # /boot if you have a separate boot partition, otherwise your root (/).
21 # The "setup" line tells grub which disc/partition to install the
22 # bootloader to. In the example above, it will install to the MBR of the
23 # primary master hard drive.
27 echo "usage: install-grub <install_device> [boot_device]"
29 echo "where <install_device> is the device where Grub will be installed"
30 echo "and [boot_device] is the partition that contains the /boot"
31 echo "directory (auto-detected if omitted)"
33 echo "examples: install-grub /dev/hda"
34 echo " install-grub /dev/hda /dev/hda1"
39 ## new install-grub, code was taken from setup script
44 if [ "$ROOTDEV" = "" ]; then
47 if [ "$PART_ROOT" = "" ]; then
48 PART_ROOT
=$
(mount |
grep "on /boot type" | cut
-d' ' -f 1)
50 if [ "$PART_ROOT" = "" ]; then
51 PART_ROOT
=$
(mount |
grep "on / type" | cut
-d' ' -f 1)
53 if [ "$PART_ROOT" = "" ]; then
54 echo "error: could not determine BOOT_DEVICE, please specify manually" >&2
60 [ -e /tmp
/dev.map
] && rm /tmp
/dev.map
61 /sbin
/grub
--no-floppy --device-map /tmp
/dev.map
>/tmp
/grub.log
2>&1 <<EOF
69 devs
=$
(cat /tmp
/dev.map |
grep -v fd |
sed 's/ *\t/ /' |
sed ':a;$!N;$!ba;s/\n/ /g')
70 linuxdevice
=$
(echo $1 | cut
-b1-8)
71 if [ "$(echo $1 | egrep '[0-9]$')" ]; then
73 pnum
=$
(echo $1 | cut
-b9-)
79 if [ "(" = $
(echo $dev | cut
-b1) ]; then
82 if [ "$dev" = "$linuxdevice" ]; then
88 if [ "$device_found" = "1" ]; then
89 if [ "$partition_flag" = "0" ]; then
92 grubdevice_stringlen
=${#grubdevice}
93 let grubdevice_stringlen--
94 grubdevice
=$
(echo $grubdevice | cut
-b1-$grubdevice_stringlen)
95 echo "$grubdevice,$pnum)"
98 echo " DEVICE NOT FOUND"
104 if [ ! -f /boot
/grub
/menu.lst
]; then
105 echo "Error: Couldn't find /boot/grub/menu.lst. Is GRUB installed?"
108 # try to auto-configure GRUB...
109 if [ "$PART_ROOT" != "" -a "$S_GRUB" != "1" ]; then
110 grubdev
=$
(mapdev
$PART_ROOT)
111 # look for a separately-mounted /boot partition
112 bootdev
=$
(mount |
grep /boot | cut
-d' ' -f 1)
113 if [ "$grubdev" != "" -o "$bootdev" != "" ]; then
114 cp /boot
/grub
/menu.lst
/tmp
/.menu.lst
115 # remove the default entries by truncating the file at our little tag (#-*)
116 head -n $
(cat /tmp
/.menu.lst |
grep -n '#-\*' | cut
-d: -f 1) /tmp
/.menu.lst
>/boot
/grub
/menu.lst
118 echo "" >>/boot
/grub
/menu.lst
119 echo "# (0) Arch Linux" >>/boot
/grub
/menu.lst
120 echo "title Arch Linux" >>/boot
/grub
/menu.lst
122 if [ "$bootdev" != "" ]; then
123 grubdev
=$
(mapdev
$bootdev)
127 echo "root $grubdev" >>/boot
/grub
/menu.lst
128 echo "kernel $subdir/$VMLINUZ root=$PART_ROOT ro" >>/boot
/grub
/menu.lst
129 if [ "$VMLINUZ" = "vmlinuz26" ]; then
130 echo "initrd $subdir/kernel26.img" >>/boot
/grub
/menu.lst
132 echo "" >>/boot
/grub
/menu.lst
133 # adding fallback/full image
134 echo "# (1) Arch Linux" >>/boot
/grub
/menu.lst
135 echo "title Arch Linux Fallback" >>/boot
/grub
/menu.lst
136 echo "root $grubdev" >>/boot
/grub
/menu.lst
137 echo "kernel $subdir/$VMLINUZ root=$PART_ROOT ro" >>/boot
/grub
/menu.lst
138 if [ "$VMLINUZ" = "vmlinuz26" ]; then
139 echo "initrd $subdir/kernel26-fallback.img" >>/boot
/grub
/menu.lst
141 echo "" >>/boot
/grub
/menu.lst
145 echo "Installing the GRUB bootloader..."
146 cp -a /usr
/lib
/grub
/i386-pc
/* /boot
/grub
/
148 # freeze xfs filesystems to enable grub installation on xfs filesystems
149 if [ -x /usr
/sbin
/xfs_freeze
]; then
150 /usr
/sbin
/xfs_freeze
-f /boot
> /dev
/null
2>&1
151 /usr
/sbin
/xfs_freeze
-f / > /dev
/null
2>&1
153 # look for a separately-mounted /boot partition
154 bootpart
=$
(mount |
grep /boot | cut
-d' ' -f 1)
155 if [ "$bootpart" = "" ]; then
158 bootpart
=$
(mapdev
$bootpart)
159 bootdev
=$
(mapdev
$ROOTDEV)
160 if [ "$bootpart" = "" ]; then
161 echo "Error: Missing/Invalid root device: $bootpart"
164 /sbin
/grub
--no-floppy --batch >/tmp
/grub.log
2>&1 <<EOF
170 # unfreeze xfs filesystems
171 if [ -x /usr
/sbin
/xfs_freeze
]; then
172 /usr
/sbin
/xfs_freeze
-u /boot
> /dev
/null
2>&1
173 /usr
/sbin
/xfs_freeze
-u / > /dev
/null
2>&1
176 if grep "Error [0-9]*: " /tmp
/grub.log
>/dev
/null
; then
177 echo "Error installing GRUB. (see /tmp/grub.log for output)"
180 echo "GRUB was successfully installed."