GrUB help please...

Discuss Applications
User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main »

If that's the boot loader you want to use then yes. Then in your Mandrake GRUB configuration file you would add the other OSs to boot. If you installed the boot loaders on the partitions that you installed your other OSes on you should be able to just point to the partition to boot in your GRUB configuration just like you do for booting Windows. Then the grub that you installed in your other OS will take over the boot process. Of course that is not the only way to do it. You can also copy all of your kernels from all of your other Linux installs into the /boot dir on your Mandrake partition and set up the boot entries for it in Mandrake's grub.conf but you shouldn't have to do it that way.

User avatar
Calum
guru
guru
Posts: 1349
Joined: Fri Jan 10, 2003 11:32 am
Location: Bonny Scotland
Contact:

Post by Calum »

i shouldn't and i would like to avoid it since it would mean the partitions being renumbered and me having a lot of trouble with windows not being on /dev/hda1

well, i made it so only hda5 was bootable and then tried to do 'grub-install /dev/hda' and i still get that exact error message that i got before about part5 not having a corresponding bios drive, and since i originally got that message i have uninstalled grub using rpm and installed the latest version from source, still same error message.
here's the real output of 'fdisk -l /dev/hda', third time lucky:

Code: Select all

Disk /dev/hda: 255 heads, 63 sectors, 1868 cylinders
Units = cylinders of 16065 * 512 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/hda1   *         1       252   2024158+   b  Win95 FAT32
/dev/hda2           253       412   1285200   83  Linux
/dev/hda3           413      1808  11213370    5  Extended
/dev/hda4          1809      1868    481950   82  Linux swap
/dev/hda5           413       767   2851506   83  Linux
/dev/hda6           768      1122   2851506   83  Linux
/dev/hda7          1123      1339   1743021   83  Linux
/dev/hda8          1340      1594   2048256   83  Linux
/dev/hda9          1595      1808   1718923+  83  Linux
i made hda1 bootable again in case i need to boot windows sometime. in the meantime i still use my trusty mandrake boot floppy under normal circumstances.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main »

What does your grub.conf (or menu.lst) file look like on /dev/hda5? I might have to set up a VMware session and partition a disk like what you have. I haven't messed with multi boot in quite some time and am getting rusty I guess. I have 6 machines here at home, all with Red Hat 8.0 only, no dual boot.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main »

Ok, I just did some playing with GRUB and multiple Linux installs in VMware. Here is my partition table:

Code: Select all

Disk /dev/sda: 255 heads, 63 sectors, 510 cylinders
Units = cylinders of 16065 * 512 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/sda1   *         1        13    104391   83  Linux
/dev/sda2            14       191   1429785   83  Linux
/dev/sda3           192       231    321300   82  Linux swap
/dev/sda4           232       510   2241067+   5  Extended
/dev/sda5           232       244    104391   83  Linux
/dev/sda6           245       510   2136613+  83  Linux
/dev/sda1 is a "/boot" partition containing the GRUB configuration for all OSs and the kernel for the OS that has the root file system on /dev/sda2. The second installation has "/boot" on /dev/sda5 which contains the kernel for the OS that has the root file system of "/dev/sda6". Of course you don't need separate /boot partitions, I just did it that way to make it a little more complex.

Here is what my menu.lst looks like on /dev/sda1:

Code: Select all

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/sda2
#          initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title RH8 1
        root (hd0,0)
        kernel /vmlinuz-2.4.18-14 ro root=/dev/sda2
        initrd /initrd-2.4.18-14.img
title RH8 2
        root (hd0,4)
        kernel /vmlinuz-2.4.18-14 ro root=/dev/sda6
        initrd /initrd-2.4.18-14.img

Instead of two copies of Red Hat I could just as well have had a copy of Red Hat and Mandrake. The easiest way to get all of this working would be at install time.

First install your Windows on /dev/hda1, then install the OS that you want to use GRUB to bootstrap all the others and have it install GRUB on /dev/hda. I would suggest using one of the primary partitions for your /boot containing this copy of GRUB. Now, when you install the next linux have it install to the partition rather than the MBR (not /dev/hda). In fact you really don't even need to install GRUB at all, just as long as the kernel gets installed, but if you do install grub you can copy the section out of the "menu.lst" and paste it into the first menu.lst from the first Linux installation. This should work for additional Linux installations. Hopefully that isn't too confusing.

User avatar
Calum
guru
guru
Posts: 1349
Joined: Fri Jan 10, 2003 11:32 am
Location: Bonny Scotland
Contact:

Post by Calum »

it's not confusing at all, and in fact it's what i have been doing up till now with no problems. as i say i have a windows partition, a freeBSD partition (not currently got freeBSD on it, it's hda2 at the moment and i think i left it as ext2 last time i reformatted everything)as primary partitions and all the linuces are within an extended partition. the freeBSD and windows partitions need to be on primary partitions because they cannot be booted from within an extended partition.

so inside the extended partition i have my mandrake / and my mandrake /home partitions, i also have some other linux partitions (lycoris, vectorlinux, debian et c) and every time i install a new one i just use vi to edit mandrake's menu.lst file (usually this will be located at /mnt/mandrake/boot/grub/menu.lst after i have edited my new linux' fstab and so on) and up till now this has worked fine. i just install a new OS and then edit mandrake's menu.lst file.

until one day, disaster struck. forced by fate to install windows, i was faced with a dillema. windows overwrote my MBR. no longer could i just update my menu.lst file, i also had to run grub-install /dev/hda but NO! when i try to do that i get this flaming error about a BIOS drive! as i say, last time i needed to install a grub boot sector it worked fine, but i have installed a lot of linuces and one windows since then, and i was hoping there would be a way to fix it all without a week of annoying reinstalling and editing by hand of fstab files again. maybe i will experiment with making a tgz file for use with pkginstall to autoreplace all the fstab files with ones i have saved from my current install. maybe that will cause more problems than it will solve! :D

well it looks like i might have to reinstall mandrake then to get it to work. what i might try and do is to put the swap partition (currently primary) inside the extended partition, thus giving me room to make the mandrake root partition (currently inside the extended partition) into a primary partition. still no /boot partition but hey, i'll just have to live dangerously.

thanks for all your help.
Last edited by Calum on Thu Mar 06, 2003 9:50 am, edited 2 times in total.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main »

Ok, I see your issue now. I'm a little slow and not very observant so please bear with me. You should be able to get this fixed without reinstalling mandrake. Let me do some more research.

User avatar
Calum
guru
guru
Posts: 1349
Joined: Fri Jan 10, 2003 11:32 am
Location: Bonny Scotland
Contact:

Post by Calum »

oh yeah! i could just do grub-install /dev/fd0 couldn't i? that would save me a few floppy disks sitting on top of the computer case!

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main »

Yes, you most certainly can create a GRUB boot disk with your existing menu.lst.

On my VMware test dual boot setup I just ran:

# grub-install /dev/hda

and I got that same BIOS error except it actually said "/dev/hda" and the device it had the problem with instead of "/dev/ide/*/*/*/part5" like in your case. I realize why I got the error, it's because I actually needed to use "/dev/sda" rather than "/dev/hda" which worked perfectly when I ran the command against the proper device. Now the question is, where is your machine getting this "/dev/ide/*/*/*/part5" crap from? It almost looks like what you would see in the 2.5 kernel with "devfs" turned on. Looking through the script the first thing that grub-install looks for is "/boot/grub/device.map" (depending on where you have grub installed). Here's what my device.map looks like:

Code: Select all

# this device map was generated by anaconda
(fd0)     /dev/fd0
(hd0)     /dev/sda
What does your's look like? Your's should have "/dev/hda" rather than "/dev/sda".

Also, what is the output of this command:

# grub-install --debug /dev/hda

And one last thing, what is the output of this command:

# df

I think with this information we'll be close to having it figured out.

User avatar
Calum
guru
guru
Posts: 1349
Joined: Fri Jan 10, 2003 11:32 am
Location: Bonny Scotland
Contact:

Post by Calum »

ok, here goes:

Code: Select all

root@localhost:/home/calum# cat /boot/grub/device.map
(fd0) /dev/fd0
(hd0) /dev/hda
root@localhost:/home/calum# grub-install --debug /dev/hda
+ bootdir=/boot
+ grubdir=/boot/grub
+ device_map=/boot/grub/device.map
+ test -f /usr/local/sbin/grub
+ :
+ test -f /usr/local/share/grub/i386-pc/stage1
+ :
+ test -f /usr/local/share/grub/i386-pc/stage2
+ :
+ test -d /boot
+ test -d /boot/grub
+ test no = yes
+ test -f /boot/grub/device.map
+ :
++ sed -n '/^([fh]d[0-9]*)/s/\(^(.*)\).*/\1/p' /boot/grub/device.map
++ sort
++ uniq -d
++ sed -n 1p
+ tmp=
+ test -n ''
++ convert /dev/hda
++ test -e /dev/hda
++ :
+++ echo /dev/hda
+++ sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' -e 's%\(fd[0-9]*\)$%\1%' -e 's%/part[0-9]*$%/disc%' -e 's%\(c[0-7]d[0-9]*\).*$%\1%'
++ tmp_disk=/dev/hda
+++ echo /dev/hda
+++ sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' -e 's%.*/fd[0-9]*$%%' -e 's%.*/floppy/[0-9]*$%%' -e 's%.*/\(disc\|part\([0-9]*\)\)$%\2%' -e 's%.*c[0-7]d[0-9]*p*%%'
++ tmp_part=
+++ grep -v '^#' /boot/grub/device.map
+++ grep '/dev/hda *$'
+++ sed 's%.*\(([hf]d[0-9][a-g0-9,]*)\).*%\1%'
++ tmp_drive=(hd0)
++ test 'x(hd0)' = x
++ test x '!=' x
++ echo '(hd0)'
+ install_drive=(hd0)
+ test 'x(hd0)' = x
++ find_device
+++ df /
+++ sed -n 's%.*\(/dev/[^       ]*\).*%\1%p'
++ tmp_fname=/dev/hda5
++ test -z /dev/hda5
++ test -L /dev/hda5
+++ ls -al /dev/hda5
+++ sed -n 's%.*-> %\1%p'
++ tmp_new_fname=ide/host0/bus0/target0/lun0/part5
++ test -z ide/host0/bus0/target0/lun0/part5
+++ echo /dev/hda5
+++ sed 's%/[^/]*$%%'
++ tmp_fname=/dev/ide/host0/bus0/target0/lun0/part5
++ test -L /dev/ide/host0/bus0/target0/lun0/part5
++ echo /dev/ide/host0/bus0/target0/lun0/part5
+ root_device=/dev/ide/host0/bus0/target0/lun0/part5
++ find_device /boot
+++ df /boot/
+++ sed -n 's%.*\(/dev/[^       ]*\).*%\1%p'
++ tmp_fname=/dev/hda5
++ test -z /dev/hda5
++ test -L /dev/hda5
+++ ls -al /dev/hda5
+++ sed -n 's%.*-> %\1%p'
++ tmp_new_fname=ide/host0/bus0/target0/lun0/part5
++ test -z ide/host0/bus0/target0/lun0/part5
+++ echo /dev/hda5
+++ sed 's%/[^/]*$%%'
++ tmp_fname=/dev/ide/host0/bus0/target0/lun0/part5
++ test -L /dev/ide/host0/bus0/target0/lun0/part5
++ echo /dev/ide/host0/bus0/target0/lun0/part5
+ bootdir_device=/dev/ide/host0/bus0/target0/lun0/part5
+ test x/dev/ide/host0/bus0/target0/lun0/part5 '!=' x/dev/ide/host0/bus0/target0/lun0/part5
++ convert /dev/ide/host0/bus0/target0/lun0/part5
++ test -e /dev/ide/host0/bus0/target0/lun0/part5
++ :
+++ echo /dev/ide/host0/bus0/target0/lun0/part5
+++ sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' -e 's%\(fd[0-9]*\)$%\1%' -e 's%/part[0-9]*$%/disc%' -e 's%\(c[0-7]d[0-9]*\).*$%\1%'
++ tmp_disk=/dev/ide/host0/bus0/target0/lun0/disc
+++ echo /dev/ide/host0/bus0/target0/lun0/part5
+++ sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' -e 's%.*/fd[0-9]*$%%' -e 's%.*/floppy/[0-9]*$%%' -e 's%.*/\(disc\|part\([0-9]*\)\)$%\2%' -e 's%.*c[0-7]d[0-9]*p*%%'
++ tmp_part=5
+++ grep -v '^#' /boot/grub/device.map
+++ grep '/dev/ide/host0/bus0/target0/lun0/disc *$'
+++ sed 's%.*\(([hf]d[0-9][a-g0-9,]*)\).*%\1%'
++ tmp_drive=
++ test x = x
++ echo '/dev/ide/host0/bus0/target0/lun0/part5 does not have any corresponding BIOS drive.'
/dev/ide/host0/bus0/target0/lun0/part5 does not have any corresponding BIOS drive.
++ exit 1
+ root_drive=
+ test x = x
+ exit 1
root@localhost:/home/calum# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hda5              2806664   1261828   1402264  48% /
/dev/hda6              2806664    490672   2173420  19% /home
/dev/hda9              1691880    149336   1456600  10% /mnt/debian
/dev/hda8              2015517   1194203    718902  63% /mnt/lycoris
/dev/hda7              1715588    476028   1152412  30% /mnt/peanut
/dev/hda1              2020196   1226724    793472  61% /C

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main »

Now I am confused. I thought you were using Mandrake. Why is it looking for GRUB stuff under "/usr/local"? You apparently are not running the stock GRUB that comes with Mandrake? I would suggest uninstalling the GRUB that is installed in /usr/local and making sure you have the stock Mandrake one installed and try it again. If it still doesn't work can you put a copy of your "grub-install" script somewhere where I can get it and look over it? It's obviously different than mine. Thanks.

User avatar
Calum
guru
guru
Posts: 1349
Joined: Fri Jan 10, 2003 11:32 am
Location: Bonny Scotland
Contact:

Post by Calum »

okay, here goes again.
now you mention it i think i actually was using grub 0.93 from gnu.org, however i have now installed grub0.92-mdk and am having the exact same problem. to whit:

Code: Select all

root@localhost:/home/calum# rpm --query grub
grub-0.92-1mdk
root@localhost:/home/calum# grub-install /dev/hda
/dev/ide/host0/bus0/target0/lun0/part5 does not have any corresponding BIOS drive.
root@localhost:/home/calum# grub-install --debug /dev/hda
+ bootdir=/boot
+ grubdir=/boot/grub
+ device_map=/boot/grub/device.map
+ test -f /usr/sbin/grub
+ :
+ test -d /boot
+ test -d /boot/grub
+ test no = yes
+ test -f /boot/grub/device.map
+ :
++ convert /dev/hda
++ test -e /dev/hda
++ :
+++ echo /dev/hda
+++ sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' -e 's%\(fd[0-9]*\)$%\1%' -e 's%/part[0-9]*$%/disc%' -e 's%\(c[0-7]d[0-9]*\).*$%\1%'
++ tmp_disk=/dev/hda
+++ echo /dev/hda
+++ sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' -e 's%.*/fd[0-9]*$%%' -e 's%.*/floppy/[0-9]*$%%' -e 's%.*/\(disc\|part\([0-9]*\)\)$%\2%' -e 's%.*c[0-7]d[0-9]*p*%%'
++ tmp_part=
+++ grep -v '^#' /boot/grub/device.map
+++ grep '/dev/hda *$'
+++ sed 's%.*\(([hf]d[0-9][a-g0-9,]*)\).*%\1%'
++ tmp_drive=(hd0)
++ test 'x(hd0)' = x
++ test x '!=' x
++ echo '(hd0)'
+ install_drive=(hd0)
+ test 'x(hd0)' = x
++ find_device
+++ df /
+++ sed -n 's%.*\(/dev/[^       ]*\).*%\1%p'
++ tmp_fname=/dev/hda5
++ test -z /dev/hda5
++ test -L /dev/hda5
+++ ls -al /dev/hda5
+++ sed -n 's%.*-> %\1%p'
++ tmp_new_fname=ide/host0/bus0/target0/lun0/part5
++ test -z ide/host0/bus0/target0/lun0/part5
+++ echo /dev/hda5
+++ sed 's%/[^/]*$%%'
++ tmp_fname=/dev/ide/host0/bus0/target0/lun0/part5
++ test -L /dev/ide/host0/bus0/target0/lun0/part5
++ echo /dev/ide/host0/bus0/target0/lun0/part5
+ root_device=/dev/ide/host0/bus0/target0/lun0/part5
++ find_device /boot
+++ df /boot/
+++ sed -n 's%.*\(/dev/[^       ]*\).*%\1%p'
++ tmp_fname=/dev/hda5
++ test -z /dev/hda5
++ test -L /dev/hda5
+++ ls -al /dev/hda5
+++ sed -n 's%.*-> %\1%p'
++ tmp_new_fname=ide/host0/bus0/target0/lun0/part5
++ test -z ide/host0/bus0/target0/lun0/part5
+++ echo /dev/hda5
+++ sed 's%/[^/]*$%%'
++ tmp_fname=/dev/ide/host0/bus0/target0/lun0/part5
++ test -L /dev/ide/host0/bus0/target0/lun0/part5
++ echo /dev/ide/host0/bus0/target0/lun0/part5
+ bootdir_device=/dev/ide/host0/bus0/target0/lun0/part5
+ test x/dev/ide/host0/bus0/target0/lun0/part5 '!=' x/dev/ide/host0/bus0/target0/lun0/part5
++ convert /dev/ide/host0/bus0/target0/lun0/part5
++ test -e /dev/ide/host0/bus0/target0/lun0/part5
++ :
+++ echo /dev/ide/host0/bus0/target0/lun0/part5
+++ sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' -e 's%\(fd[0-9]*\)$%\1%' -e 's%/part[0-9]*$%/disc%' -e 's%\(c[0-7]d[0-9]*\).*$%\1%'
++ tmp_disk=/dev/ide/host0/bus0/target0/lun0/disc
+++ echo /dev/ide/host0/bus0/target0/lun0/part5
+++ sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' -e 's%.*/fd[0-9]*$%%' -e 's%.*/floppy/[0-9]*$%%' -e 's%.*/\(disc\|part\([0-9]*\)\)$%\2%' -e 's%.*c[0-7]d[0-9]*p*%%'
++ tmp_part=5
+++ grep -v '^#' /boot/grub/device.map
+++ grep '/dev/ide/host0/bus0/target0/lun0/disc *$'
+++ sed 's%.*\(([hf]d[0-9][a-g0-9,]*)\).*%\1%'
++ tmp_drive=
++ test x = x
++ echo '/dev/ide/host0/bus0/target0/lun0/part5 does not have any corresponding BIOS drive.'
/dev/ide/host0/bus0/target0/lun0/part5 does not have any corresponding BIOS drive.
++ exit 1
+ root_drive=
+ test x = x
+ exit 1
root@localhost:/home/calum# cat /usr/sbin/grub-install
#! /bin/sh

# Install GRUB on your drive.
#   Copyright (C) 1999,2000,2001,2002 Free Software Foundation, Inc.
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

# Initialize some variables.
prefix=/usr
exec_prefix=/usr
sbindir=/usr/sbin
datadir=/usr/share
PACKAGE=grub
VERSION=0.92
host_cpu=i386
host_os=linux-gnu
host_vendor=mandrake
pkgdatadir=${datadir}/${PACKAGE}/${host_cpu}-${host_vendor}

grub_shell=${sbindir}/grub
log_file=/tmp/grub-install.log.$$
img_file=/tmp/grub-install.img.$$
rootdir=
grub_prefix=/boot/grub

install_device=
force_lba=
recheck=no
debug=no

# look for secure tempfile creation wrappers on this platform
if test -x /bin/tempfile; then
    mklog="/bin/tempfile --prefix=grub"
    mkimg="/bin/tempfile --prefix=grub"
elif test -x /bin/mktemp; then
    mklog="/bin/mktemp /tmp/grub-install.log.XXXXXX"
    mkimg="/bin/mktemp /tmp/grub-install.img.XXXXXX"
else
    mklog=""
    mkimg=""
fi

# Usage: usage
# Print the usage.
usage () {
    cat <<EOF
Usage: grub-install [OPTION] install_device
Install GRUB on your drive.

  -h, --help              print this message and exit
  -v, --version           print the version information and exit
  --root-directory=DIR    install GRUB images under the directory DIR
                          instead of the root directory
  --grub-shell=FILE       use FILE as the grub shell
  --force-lba             force GRUB to use LBA mode even for a buggy
                          BIOS
  --recheck               probe a device map even if it already exists

INSTALL_DEVICE can be a GRUB device name or a system device filename.

Report bugs to <bug-grub@gnu.org>.
EOF
}

# Usage: convert os_device
# Convert an OS device to the corresponding GRUB drive.
# This part is OS-specific.
convert () {
    # First, check if the device file exists.
    if test -e "$1"; then
        :
    else
        echo "$1: Not found or not a block device." 1>&2
        exit 1
    fi

    # Break the device name into the disk part and the partition part.
    case "$host_os" in
    linux*)
        tmp_disk=`echo "$1" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' \
                                  -e 's%\(fd[0-9]*\)$%\1%' \
                                  -e 's%/part[0-9]*$%/disc%' \
                                  -e 's%\(c[0-7]d[0-9]*\).*$%\1%'`
        tmp_part=`echo "$1" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' \
                                  -e 's%.*/fd[0-9]*$%%' \
                                  -e 's%.*/floppy/[0-9]*$%%' \
                                  -e 's%.*/\(disc\|part\([0-9]*\)\)$%\2%' \
                                  -e 's%.*c[0-7]d[0-9]*p*%%'`
        ;;
    gnu*)
        tmp_disk=`echo "$1" | sed 's%\([sh]d[0-9]*\).*%\1%'`
        tmp_part=`echo "$1" | sed "s%$tmp_disk%%"` ;;
    freebsd*)
        tmp_disk=`echo "$1" | sed 's%r\{0,1\}\([saw]d[0-9]*\).*$%r\1%' \
                            | sed 's%r\{0,1\}\(da[0-9]*\).*$%r\1%'`
        tmp_part=`echo "$1" \
            | sed "s%.*/r\{0,1\}[saw]d[0-9]\(s[0-9]*[a-h]\)%\1%" \
            | sed "s%.*/r\{0,1\}da[0-9]\(s[0-9]*[a-h]\)%\1%"`
        ;;
    netbsd*)
        tmp_disk=`echo "$1" | sed 's%r\{0,1\}\([sw]d[0-9]*\).*$%r\1d%' \
            | sed 's%r\{0,1\}\(fd[0-9]*\).*$%r\1a%'`
        tmp_part=`echo "$1" \
            | sed "s%.*/r\{0,1\}[sw]d[0-9]\([abe-p]\)%\1%"`
        ;;
    *)
        echo "grub-install does not support your OS yet." 1>&2
        exit 1 ;;
    esac

    # Get the drive name.
    tmp_drive=`grep -v '^#' $device_map | grep "$tmp_disk *$" \
        | sed 's%.*\(([hf]d[0-9][a-g0-9,]*)\).*%\1%'`

    # If not found, print an error message and exit.
    if test "x$tmp_drive" = x; then
        echo "$1 does not have any corresponding BIOS drive." 1>&2
        exit 1
    fi

    if test "x$tmp_part" != x; then
        # If a partition is specified, we need to translate it into the
        # GRUB's syntax.
        case "$host_os" in
        linux*)
            echo "$tmp_drive" | sed "s%)$%,`expr $tmp_part - 1`)%" ;;
        gnu*)
            if echo $tmp_part | grep "^s" >/dev/null; then
                tmp_pc_slice=`echo $tmp_part \
                    | sed "s%s\([0-9]*\)[a-g]*$%\1%"`
                tmp_drive=`echo "$tmp_drive" \
                    | sed "s%)%,\`expr "$tmp_pc_slice" - 1\`)%"`
            fi
            if echo $tmp_part | grep "[a-g]$" >/dev/null; then
                tmp_bsd_partition=`echo "$tmp_part" \
                    | sed "s%[^a-g]*\([a-g]\)$%\1%"`
                tmp_drive=`echo "$tmp_drive" \
                    | sed "s%)%,$tmp_bsd_partition)%"`
            fi
            echo "$tmp_drive" ;;
        freebsd*)
            if echo $tmp_part | grep "^s" >/dev/null; then
                tmp_pc_slice=`echo $tmp_part \
                    | sed "s%s\([0-9]*\)[a-h]*$%\1%"`
                tmp_drive=`echo "$tmp_drive" \
                    | sed "s%)%,\`expr "$tmp_pc_slice" - 1\`)%"`
            fi
            if echo $tmp_part | grep "[a-h]$" >/dev/null; then
                tmp_bsd_partition=`echo "$tmp_part" \
                    | sed "s%s\{0,1\}[0-9]*\([a-h]\)$%\1%"`
                tmp_drive=`echo "$tmp_drive" \
                    | sed "s%)%,$tmp_bsd_partition)%"`
            fi
            echo "$tmp_drive" ;;
        netbsd*)
            if echo $tmp_part | grep "^[abe-p]$" >/dev/null; then
                tmp_bsd_partition=`echo "$tmp_part" \
                    | sed "s%\([a-p]\)$%\1%"`
                tmp_drive=`echo "$tmp_drive" \
                    | sed "s%)%,$tmp_bsd_partition)%"`
            fi
            echo "$tmp_drive" ;;
        esac
    else
        # If no partition is specified, just print the drive name.
        echo "$tmp_drive"
    fi
}

# Usage: find_device file
# Find block device on which the file resides.
find_device () {
    # For now, this uses the program `df' to get the device name, but is
    # this really portable?
    tmp_fname=`df $1/ | sed -n 's%.*\(/dev/[^   ]*\).*%\1%p'`

    if test -z "$tmp_fname"; then
        echo "Could not find device for $1" 2>&1
        exit 1
    fi

    # Resolve symlinks
    while test -L $tmp_fname; do
        tmp_new_fname=`ls -al $tmp_fname | sed -n 's%.*-> %\1%p'`
        if test -z "$tmp_new_fname"; then
            echo "Unrecognized ls output" 2>&1
            exit 1
        fi

        # Convert relative symlinks
        case $tmp_new_fname in
            /*) tmp_fname="$tmp_new_fname" ;;
            *) tmp_fname="`echo $tmp_fname | sed 's%/[^/]*$%%'`/$tmp_new_fname" ;;
        esac
    done
    echo "$tmp_fname"
}

# Check the arguments.
for option in "$@"; do
    case "$option" in
    -h | --help)
        usage
        exit 0 ;;
    -v | --version)
        echo "grub-install (GNU GRUB ${VERSION})"
        exit 0 ;;
    --root-directory=*)
        rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
    --grub-shell=*)
        grub_shell=`echo "$option" | sed 's/--grub-shell=//'` ;;
    --force-lba)
        force_lba="--force-lba" ;;
    --recheck)
        recheck=yes ;;
    # This is an undocumented feature...
    --debug)
        debug=yes ;;
    -*)
        echo "Unrecognized option \`$option'" 1>&2
        usage
        exit 1
        ;;
    *)
        if test "x$install_device" != x; then
            echo "More than one install_devices?" 1>&2
            usage
            exit 1
        fi
        install_device="${option}" ;;
    esac
done

if test "x$install_device" = x; then
    echo "install_device not specified." 1>&2
    usage
    exit 1
fi

# If the debugging feature is enabled, print commands.
if test $debug = yes; then
    set -x
fi

# Initialize these directories here, since ROOTDIR was initialized.
case "$host_os" in
netbsd*)
    # Because /boot is used for the boot block in NetBSD, use /grub
    # instead of /boot/grub.
    grub_prefix=/grub
    bootdir=${rootdir}
    ;;
*)
    # Use /boot/grub by default.
    bootdir=${rootdir}/boot
    ;;
esac

grubdir=${bootdir}/grub
device_map=${grubdir}/device.map

# Check if GRUB is installed
if test -f "$grub_shell"; then
    :
else
    echo "${grub_shell}: Not found." 1>&2
    exit 1
fi

# Don't check for *stage1_5, because it is not fatal even if any
# Stage 1.5 does not exist.

# Create the GRUB directory if it is not present.
test -d "$bootdir" || mkdir "$bootdir" || exit 1
test -d "$grubdir" || mkdir "$grubdir" || exit 1

# If --recheck is specified, remove the device map, if present.
if test $recheck = yes; then
    rm -f $device_map
fi

# Create the device map file if it is not present.

if test -f "$device_map"; then
    :
else
    # Create a safe temporary file.
    test -n "$mklog" && log_file=`$mklog`

    $grub_shell --batch --device-map=$device_map <<EOF >$log_file
quit
EOF
    if grep "Error [0-9]*: " $log_file >/dev/null; then
        cat $log_file 1>&2
        exit 1
    fi

    rm -f $log_file
fi

# Check for INSTALL_DEVICE.
case "$install_device" in
/dev/*)
    install_drive=`convert "$install_device"`
    # I don't know why, but some shells wouldn't die if exit is
    # called in a function.
    if test "x$install_drive" = x; then
        exit 1
    fi ;;
\([hf]d[0-9]*\))
    install_drive="$install_device" ;;
*)
    echo "Format of install_device not recognized." 1>&2
    usage
    exit 1 ;;
esac

# Get the root drive.
root_device=`find_device ${rootdir}`
bootdir_device=`find_device ${bootdir}`

# Check if the boot directory is in the same device as the root directory.
if test "x$root_device" != "x$bootdir_device"; then
    # Perhaps the user has a separate boot partition.
    root_device=$bootdir_device
    grub_prefix="/grub"
fi

# Convert the root device to a GRUB drive.
root_drive=`convert "$root_device"`
if test "x$root_drive" = x; then
    exit 1
fi

# Check if the root directory exists in the same device as the grub
# directory.
grubdir_device=`find_device ${grubdir}`

if test "x$grubdir_device" != "x$root_device"; then
    # For now, cannot deal with this situation.
    cat <<EOF 1>&2
You must set the root directory by the option --root-directory, because
$grubdir does not exist in the root device $root_device.
EOF
    exit 1
fi

# Make sure that GRUB reads the same images as the host OS.
test -n "$mkimg" && img_file=`$mkimg`
test -n "$mklog" && log_file=`$mklog`

for file in ${grubdir}/stage1 ${grubdir}/stage2 ${grubdir}/*stage1_5; do
    count=5
    tmp=`echo $file | sed "s|^${grubdir}|${grub_prefix}|"`
    while test $count -gt 0; do
        $grub_shell --batch --device-map=$device_map <<EOF >$log_file
dump ${root_drive}${tmp} ${img_file}
quit
EOF
        if grep "Error [0-9]*: " $log_file >/dev/null; then
            :
        elif cmp $file $img_file >/dev/null; then
            break
        fi
        sleep 1
        count=`expr $count - 1`
    done
    if test $count -eq 0; then
        echo "The file $file not read correctly." 1>&2
        exit 1
    fi
done

rm -f $img_file
rm -f $log_file


# Create a safe temporary file.
test -n "$mklog" && log_file=`$mklog`

# Now perform the installation.
$grub_shell --batch --device-map=$device_map <<EOF >$log_file
root $root_drive
setup $force_lba --stage2=$grubdir/stage2 --prefix=$grub_prefix $install_drive
quit
EOF

if grep "Error [0-9]*: " $log_file >/dev/null || test $debug = yes; then
    cat $log_file 1>&2
    exit 1
fi

rm -f $log_file

# Prompt the user to check if the device map is correct.
echo "Installation finished. No error reported."
echo "This is the contents of the device map $device_map."
echo "Check if this is correct or not. If any of the lines is incorrect,"
echo "fix it and re-run the script \`grub-install'."
echo

cat $device_map

# Bye.
exit 0
my device.map file still reads the same as it did before too (ie correctly)

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main »

I guess you must be running "devfs". Is /dev/hda5 a symbolic link? If it is I assume it points to "/dev/ide/host0/bus0/target0/lun0/part5". I also assume that you would have a "/dev/ide/host0/bus0/target0/lun0/disc" device. If so I assume you can also do an:

# fdisk -l /dev/ide/host0/bus0/target0/lun0/disc

This would do nothing more than verify that you are using devfs. I just started playing with devfs in the 2.5 kernel and to tell you the truth I didn't realize it was available for 2.4 (I'm a little slow). I guess Mandrake must have implemented it. I have never tried to install GRUB on a devfs system and I don't know if there are any special issues.

The only thing I can think of is to first try the "--force-lba" and/or "--recheck" options to grub-install. If that doesn't do it make a backup copy of your menu.lst and then clean out all of the entries (make a very basic one boot menu.lst) and try and do the grub-install. If that works add your menu items back. If that doesn't work you might try using your Red Hat partition as your boot partition. Otherwise I think you've got me stumped. I haven't found anything close to the problem you are having on Google.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main »

Forget all that drivel I just said, try this:

# grub-install --recheck /dev/hda

and if that doesn't work try this:

# grub-install --recheck /dev/ide/host0/bus0/target0/lun0/disc

I am pretty sure one of those two commands will work. I believe the problem is that your /boot/grub/device.map is wrong. You are running devfs and that file is for a non-devfs installation. The "--recheck" will recreate that file with the appropriate device names.

This is the closest thing I could come up with:
http://www.mail-archive.com/bug-grub@gn ... 05934.html
http://www.mail-archive.com/bug-grub@gn ... 05937.html

User avatar
Calum
guru
guru
Posts: 1349
Joined: Fri Jan 10, 2003 11:32 am
Location: Bonny Scotland
Contact:

Post by Calum »

thank you very very much for doing all this research on my behalf.
however i haven't taken that advice from your last post yet and i'll tell you why.

when i posted my last message i had just installed the mdk version of grub but was still getting the error message. i then shut down. when i came back just now i forgot to put the mandrake boot disk in my drive and i expected to see the winsux boot screen but no! i was greeted with my old familiar grub menu! shocked? yes i was.
for some reason grub has successfully written me a new MBR! but as you can see yourself from my last post above i still get all error messages!
i am baffled as to how this can be the case, but there it is. and it now seems to work again. i won't probably have this problem again in the future because now i have windows set up with no IE, no lookout excess, and vim, emacs, phoenix, staroffice et c, i can just make a tarball backup of it and untar it to a fat32 partition if i ever need it.
also:

Code: Select all

calum@localhost:~$ ls -al /dev/hda5
lr-xr-xr-x    1 root     root           33 Mar  7 22:56 /dev/hda5 -> ide/host0/bus0/target0/lun0/part5
calum@localhost:~$ ls -al /dev/ide/host0/bus0/target0/lun0/part5
brw-------    1 root     root       3,   5 Jan  1  1970 /dev/ide/host0/bus0/target0/lun0/part5
so you were right there, even though i still don't really know what devfs is and why it would only affect hda5 (which is the root partition for the system containing grub i suppose, that would make a difference?)
anyway, confused am i, but at least it works!
thanks again.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main »

The error message pops up because your device.map file is wrong. If you run the grub-install with the "--recheck" param it should create a new device.map with the proper entries and you should no longer get that error. I should have figured that out when I accidentally typed the wrong device name and got the same error message but I'm getting old and slow...

Post Reply