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
43 if [ "${ROOTDEV}" = "" ]; then
46 if [ "${PART_ROOT}" = "" ]; then
47 PART_ROOT
=$
(mount |
grep "on /boot type" | cut
-d' ' -f 1)
49 if [ "$PART_ROOT" = "" ]; then
50 PART_ROOT
=$
(mount |
grep "on / type" | cut
-d' ' -f 1)
52 if [ "${PART_ROOT}" = "" ]; then
53 echo "error: could not determine BOOT_DEVICE, please specify manually" >&2
59 [ -e /tmp
/dev.map
] && rm /tmp
/dev.map
60 /sbin
/grub
--no-floppy --device-map /tmp
/dev.map
>/tmp
/grub.log
2>&1 <<EOF
68 devs
=$
(cat /tmp
/dev.map |
grep -v fd |
sed 's/ *\t/ /' |
sed ':a;$!N;$!ba;s/\n/ /g')
69 linuxdevice
=$
(echo $1 | cut
-b1-8)
70 if [ "$(echo ${1} | egrep '[0-9]$')" ]; then
72 pnum
=$
(echo ${1} | cut
-b9-)
76 for dev
in ${devs}; do
77 if [ "(" = $
(echo ${dev} | cut
-b1) ]; then
80 if [ "${dev}" = "${linuxdevice}" ]; then
86 if [ "${device_found}" = "1" ]; then
87 if [ "${partition_flag}" = "0" ]; then
90 grubdevice_stringlen
=${#grubdevice}
91 let grubdevice_stringlen--
92 grubdevice
=$
(echo $grubdevice | cut
-b1-$grubdevice_stringlen)
93 echo "${grubdevice},${pnum})"
96 echo " DEVICE NOT FOUND"
102 if [ ! -f /boot
/grub
/menu.lst
]; then
103 echo "Error: Couldn't find /boot/grub/menu.lst. Is GRUB installed?"
106 # try to auto-configure GRUB...
107 if [ "${PART_ROOT}" != "" -a "$S_GRUB" != "1" ]; then
108 grubdev
=$
(mapdev
${PART_ROOT})
109 # look for a separately-mounted /boot partition
110 bootdev
=$
(mount |
grep /boot | cut
-d' ' -f 1)
111 if [ "${grubdev}" != "" -o "${bootdev}" != "" ]; then
112 cp /boot
/grub
/menu.lst
/tmp
/.menu.lst
113 # remove the default entries by truncating the file at our little tag (#-*)
114 head -n $
(cat /tmp
/.menu.lst |
grep -n '#-\*' | cut
-d: -f 1) /tmp
/.menu.lst
>/boot
/grub
/menu.lst
117 for kernel
in /boot
/vmlinuz-linux
* /boot
/vmlinuz26-
*; do
118 if [ ${kernel} == "/boot/vmlinuz-linux*" ] ||
[ ${kernel} == "/boot/vmlinuz26-*" ] ; then
121 VMLINUZ
=$
( echo ${kernel} | cut
-c 7- )
123 if [ "$( echo ${VMLINUZ} | cut -c -13 )" = "vmlinuz-linux" ]; then # new naming scheme for linux > 3.0
124 extension
=$
( echo ${VMLINUZ} | cut
-c 14- )
125 INITRAMFS_BASENAME
=initramfs-linux
${extension}
126 else # old naming scheme for lts kernel
127 extension
=$
( echo ${VMLINUZ} | cut
-c 10- )
128 INITRAMFS_BASENAME
=kernel26
${extension}
131 echo "" >>/boot
/grub
/menu.lst
132 echo "# (0) Arch Linux" >>/boot
/grub
/menu.lst
133 echo "title Arch Linux - ${VMLINUZ}" >>/boot
/grub
/menu.lst
135 if [ "${bootdev}" != "" ]; then
136 grubdev
=$
(mapdev
${bootdev})
140 echo "root ${grubdev}" >>/boot
/grub
/menu.lst
141 echo "kernel ${subdir}/${VMLINUZ} root=${PART_ROOT} ro" >>/boot
/grub
/menu.lst
142 echo "initrd ${subdir}/${INITRAMFS_BASENAME}.img" >>/boot
/grub
/menu.lst
143 echo "" >>/boot
/grub
/menu.lst
145 # adding fallback/full image
146 echo "# (1) Arch Linux" >>/boot
/grub
/menu.lst
147 echo "title Arch Linux Fallback - ${VMLINUZ}" >>/boot
/grub
/menu.lst
148 echo "root ${grubdev}" >>/boot
/grub
/menu.lst
149 echo "kernel ${subdir}/${VMLINUZ} root=${PART_ROOT} ro" >>/boot
/grub
/menu.lst
150 echo "initrd ${subdir}/${INITRAMFS_BASENAME}-fallback.img" >>/boot
/grub
/menu.lst
151 echo "" >>/boot
/grub
/menu.lst
157 echo "Installing the GRUB bootloader..."
158 cp -a /usr
/lib
/grub
/i386-pc
/* /boot
/grub
/
161 # freeze xfs filesystems to enable grub installation on xfs filesystems
162 if [ -x /usr
/sbin
/xfs_freeze
]; then
163 [ "$(stat -fLc %T /boot)" == "xfs" ] && /usr
/sbin
/xfs_freeze
-f /boot
> /dev
/null
2>&1
164 [ "$(stat -fLc %T /)" == "xfs" ] && /usr
/sbin
/xfs_freeze
-f / > /dev
/null
2>&1
167 # look for a separately-mounted /boot partition
168 bootpart
=$
(mount |
grep /boot | cut
-d' ' -f 1)
169 if [ "${bootpart}" = "" ]; then
170 bootpart
=${PART_ROOT}
172 bootpart
=$
(mapdev
${bootpart})
173 bootdev
=$
(mapdev
${ROOTDEV})
174 if [ "${bootpart}" = "" ]; then
175 echo "Error: Missing/Invalid root device: ${bootpart}"
181 /sbin
/grub
--no-floppy --batch >/tmp
/grub.log
2>&1 <<EOF
188 # unfreeze xfs filesystems
189 if [ -x /usr
/sbin
/xfs_freeze
]; then
190 [ "$(stat -fLc %T /boot)" == "xfs" ] && /usr
/sbin
/xfs_freeze
-u /boot
> /dev
/null
2>&1
191 [ "$(stat -fLc %T /)" == "xfs" ] && /usr
/sbin
/xfs_freeze
-u / > /dev
/null
2>&1
193 if grep "Error [0-9]*: " /tmp
/grub.log
>/dev
/null
; then
194 echo "Error installing GRUB. (see /tmp/grub.log for output)"
197 echo "GRUB was successfully installed."