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

Re: grub problem



On Thu, 2004-07-08 at 16:27, Rodney Richison wrote:
> I attempted a repair floppy last night. It didn't work out real well.
> Ahhh, for a command like sys a:    :)  Novel idea...
> 
> Anyway here's what I did for future google searches. Maybe it'll help
> someone someday.
> 
> How to Repair Grub boot loader after debian ghost restore
> 
> I booted with mepis (Any live-cd would probably do)
> Open a terminal window
> Mounted the drive (don't use the mepis icon as it mounts read only)
> mount -rw /dev/hda1 /mnt/hda1
> chroot /dev/hda1
> grub-install /dev/hda
> 
> Worked like a charm..   Am a bit confused what the drive is hda1 till I
> get to the install part, but I'm guessing I'm mounting partition one on
> hda, but the grub wants the "drive" to install to. Not the partition.

Hi Rodney,

The standard procedure for booting on the PC architecture is that the
BIOS is configured with a list of boot devices and the order to scan
them. It checks the MBR (master boot record, aka "boot sector") of each
device in turn until it finds some executable code.

Note: the BIOS does not care at all about the partitions on the drive,
it only looks at the "boot sector" for the device.

What grub-install does is write a small amount of code (512 bytes) into
the MBR on a device, called the "stage1" code. This code is just smart
enough to be able to read a sequence of hard-wired disk blocks (the
"stage1.5" or "stage2" executable) into memory and jump to the loaded
code. This data resides as a standard file in some kind of filesystem.
Note that no filesystem knowledge is required - but the file being
loaded had better not move on disk (eg defragmentation is a really bad
idea) as the physical location of the blocks is wired into the MBR.

That is why grub-install takes a "device" (hence /dev/hda) as a target,
not a "partition"; it is installing the stage1 code into the MBR.

And it needs to figure out the physical disk blocks which contain the
executable which is the next "stage" of grub. So you can either mount
the filesystem that will contain these files as the root partition
(which you effectively did), or mount it elsewhere and pass the
"--root-directory" option to grub-install. Of course here you are
dealing with *filesystems* which reside on *partitions* (hence
/dev/hda1).

I hope this helps. I learnt much of this the hard way after having to
fix unbootable systems just like you are doing now :-)

The grub docs at http://www.gnu.org/software/grub/manual/grub.html are
of course the ultimate source of info.

NB: To confuse issues, each partition also has a "boot sector". The BIOS
never looks at these, but a bootloader stored in the MBR of the device
can be set up to delegate to the boot code in a partition's boot sector.


BTW, there may be errors in the above - anyone who knows better is
welcome to correct these.


Regards,

Simon




Reply to: