[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: GRUB problem (long, description of BOOT)



Jeremy Merritt wrote:
I have been having a problem getting my GRUB
bootloader to return on boot. No matter what I do, it
keeps going to XP. I consulted with other people on
this list and got some good input. But have run into a
dead end again. Can someone analyze these steps and
tell me what I'm doing wrong, or what I need to do to
get the GRUB menu to return the way it was when I
first installed Debian:

Steps so far:

1. Boot up with live CD (Knoppix)
2. Activate shell and go root
3. Mount /dev/hda5 as /mnt/hda5
4. chroot /mnt/hda5 /bin/bash
5. grub-install /dev/hda5 -- Reports successful
install but no results on bootup

You installed GRUB as the boot record (BR) of one
of your partitions (/dev/hda5). This will work fine, but it is
not what the BIOS will load.

I think you need a little more information about how
boot is accomplished on IBM PC style computers. If
you get that, then I think things will be much more
clear. So, here is a brief tutorial on disc partitioning
and how boot proceeds.

Those who are familiar with this may either skip the
rest of this message, or use it as a review, or
criticize it for errors or omissions.

Discs, to be used, must be formatted. The formatting
takes place in levels. The lowest level (sometimes
called low-level format) places tracks and sectors on
each surface usable on the disc. Modern hard discs reserve
one surface to hold tracking information alone, no
data. Low-level formatting should not be done on modern
hard discs except at the factory. Those of us who used to
use MFM and RLL discs are glad for that.

(Floppy discs have all three levels done at once
by a single program, usually. This causes some
confusion. The levels of formatting are actually
done in passes even for floppies.)

At the second level of formatting, the surface is divided into
partitions (floppy discs have only one partition, so they
have no partitioning to be done). Traditionally, the first
record on the disc, the Master Boot Record (MBR) contains
two parts: a small bootstrap program and a Partition Table
(PT). Some consider the PT to be separate from the MBR.
Also, traditionally, there may only be four (4) partitions defined.
However, as time went by discs grew larger, and a percieved
need for more partitions grew as well. So the concept of
a Primary Partition and an Extended Partition was developed.
There could be only four (4) Primary Partitions, but
only one (1) Extended Partition. If an Extended Partition
existed, it used up one of the entries, so only up to three
(3) Primary Partitions could then be defined. The PT uses
physical addresses (head, track [or cylinder], and sector).

Within the Extended Partition, Logical Partitions (also
called Logical Discs or Volumes) could be created. Primary
Partitions also contain Volumes, but only one per partition.

Each Partition has a type (OS, more or less) and a status.
The status could be either Bootable (also called Active) or
non-bootable (Inactive). Only up to one (1) partition may be in
an Active state, and if so, it must be a Primary Partition.

A floppy disc is a single Volume, hard discs
may have up to one Volume per Primary Partition, and
any number of Volumes (logical partitions or logical
discs) in an extended partition. Each Volume has
a Boot Record (BR) also called BIOS Parameter Block (BPB).
Technically, the BPB is actually a part of the BR, in
somewhat the same way the PT is part of the MBR.

The BR contains a description of the logical layout of the Volume,
like how many reserved sectors there are before the data area,
how many logical sectors there are, etc. The BR uses logical disc
addressing (logical sector number).

The top level of format is the File System (FS). The
file system uses allocatable units for addressing. Exactly
what an allocatable unit is depends on what FS is being
used. Usually the FS presents an Application Programming
Interface (API) which uses File Addressing (directories,
files, and records within file).


fdisk -l information (hda5=Mandrake, hdb2=Debian,
system is booting from hda1=XP):

Disk /dev/hda: 40.0 GB, 40020664320 bytes

This is your first disc.

255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 2433 19543041 7 HPFS/NTFS

Here is your primary partition which is active.

/dev/hda2 2434 4865 19535040 5 Extended

This is your extended partition.

/dev/hda5 2434 3197 6136798+ 83 Linux
/dev/hda6 3198 3337 1124518+ 82 Linux swap
/dev/hda7 3338 4865 12273628+ 83 Linux

These are volumes inside your extended partition.
Each of them may be treated as a partition.


Disk /dev/hdb: 61.4 GB, 61492838400 bytes

This is your second disc.

255 heads, 63 sectors/track, 7476 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hdb1 1 3188 25607578+ c W95 FAT32 (LBA)

This is a primary partition, not bootable.
(LBA = Linear Block Addressing, which means
that your BIOS is translating logical disc
addresses [sector number only] into physical
addresses [head, cylinder, sector] for you.)

/dev/hdb2 * 3189 7298 33013575 83 Linux

This is a primary partition, which is active.

/dev/hdb3 7299 7476 1429785 5 Extended

This is an extended partition.

/dev/hdb5 7299 7476 1429753+ 82 Linux swap

This is a logical volume inside your extended partition.


Disk /dev/hdd: 30.0 GB, 30020272128 bytes

This is your fourth disc. (Where is 3? Possibly
your CD reader.)

255 heads, 63 sectors/track, 3649 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hdd1 * 1 3649 29310561 83 Linux

This disc has only one partition, which is primary
and active.

Now, how does BOOT take place?

After RESET your processor starts executing a program contained
in Read Only Memory (ROM), which contains the Basic Input/Output
System (BIOS), and other programs. Among these is the Power On
Self Test (POST) program. During execution of the POST, a
cursory check of basic functionality is done, like a memory test,
test for video display, etc. Errors during execution of POST
are normally signaled via "beeps codes". A successful POST is signaled
by a single beep. Also during POST some codes are output to (IIRC)
I/O port 0x80 to indicate the progress of the POST. One can purchase
or build cards which display these, in order to do extended
diagnosis of boot problems. Hardly anyone does this, because
motherboards have become too cheap.

After POST, the boot program starts looking for boot devices.
Using BIOS settings (technically, these are not BIOS settings,
they are boot program settings, but hardly anyone makes that
distinction) the devices are searched in order. I am not familiar
with the details of boot from USB, SCSI, or CDROM devices, so
I do not deal with them here. Look elsewhere if you want that
information.

For a network boot, normally the Address Resolution Protocol
(ARP) is used to acquire an IP address, and then start remote
boot. I won't consider this any further, since it is not part
of your problem.

Anyway, the Boot Program searches in order some discs to use
for boot. It does this by reading the absolute first sector
of the disc. For a hard disc, this is the MBR (which is
outside of any partition). It then looks for a Boot Marker
(0x55, 0xAA) as the last two bytes of the first sector.
(This is head 0, cylinder 0, sector 1 [sectors are numbered
from 1].) For a floppy, this is the BR.

If the marker is not found, then the next device in order
is checked.

If the marker is found, the sector is loaded to a fixed
location in memory (I forget the exact address, but I
believe it may be 07C0:0000). Then it is given control.

For a hard disc, there is a small program which searches
the PT for a Primary Active partition. If exactly one
Primary Active partition is located, then the first sector
in that partition is loaded. This is the BR for this partition.
If no Primary Active partition is found, then an error message
about no operating system being found is displayed. If more
than one is found, then some other error message is displayed.
In either of these cases, BOOT fails.

At this point, the sequence for floppies and hard discs
converges, for we now have a BR in memory. Or maybe we
do. If the magic marker (0x55, 0xAA) is found in the last
two bytes of the putative BR are found, then we are ok
so far, otherwise a "missing operating system" message
is displayed.

At this point, we load the BR into memory. This contains
the BPB and a boot program. This boot program (which
is different for each OS) knows how to load the OS.
If this program can't find the OS it's looking for in
the partition, a "missing OS" message is displayed.

Otherwise, the OS gets loaded, and hopefully completes
the bootstrap.

Now, you may install GRUB as the MBR boot program, or
as a BR boot program. If it is installed into the MBR,
then it manages the boot. If not, then it
can be installed as the first sector of the partition
you are using as /boot.

To do the first, one must install it to /dev/hda, as
an example. To do the latter, on installs it to
/dev/hda5 or whatever partition is being used. Either
will work. But if GRUB is installed in /dev/hda5, then
there must be another boot program installed into the MBR.

This is your current situation. You have a program in the
MBR which is not GRUB. The program in the MBR knows how
to load the Widows XP boot loader program (from the BR
in the XP bootable partition). The XP boot program
can be instructed to load GRUB if you like. This is the
way I have my system set up. The XP boot manager either
loads XP (not the default!) or it loads GRUB. GRUB then
loads one of the versions of Linux I have installed.

So you must either:

(1) Install GRUB into the MBR, or
(2) Inform the XP boot manager of GRUB's existence.

I'd do the latter. But either will work. One can argue
ad nauseum about which is better, but ultimately, either
will work. I find that it is usually better to let Windows
be loaded by a MicroSoft loader (*). YMMV.

To do (1), you need to install GRUB into /dev/hda, not into
/dev/hda5.

To do (2), you need to use dd to lift the first sector of
/dev/hda5 into a file, put that on the XP partition, and
edit the boot configuration of XP to offer that as an option.

(*) Some machines (like mine) will go into an "auto recovery"
mode if the MBR is not what it expects.

Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!



Reply to: