[clue-tech] Help Recovering from grub-install error

David Anselmi anselmi at anselmi.us
Sun Mar 27 12:22:20 MST 2005


gthrelk at comcast.net wrote:
[...]
> Can't really tell you where grub was originally.  I would have thought that 
> /dev/hda and /dev/hda1 both pointed to the same area i.e. the beginning of the 
> first disk.  Looking at the results of your requested commands, I guess 
> I've already learned something new since they show different results.  

If it were that easy it wouldn't be any fun, would it? ;-)

> I've attached the output of the fdisk -l and sudo command output.

The dd output shows us that hda1 is a GRUB boot sector while hda (the 
MBR) is a Win95 MBR.  Probably you wanted GRUB on hda and had something 
good on hda1 (until you overwrote it with GRUB).

You didn't say what happens when you try to boot Windows, but GRUB 
probably expects hda1 to be Win95, not GRUB.  If you select Windows on 
the menu do you just get the menu again?

My first thought was to swap the first sectors of hda and hda1 since hda 
has "put there by Windows" stuff.  But that won't work--hda has the MBR 
on it and hda1 needs a "boot sector".  So, can we find a Win98se boot 
sector?  You might be able to get one from a Win98 boot floppy, but 
maybe a floppy is different from a hard drive.  Off to google...

The page http://home.att.net/~rayknights/pc_boot/w98bboot.htm indicates 
that a Win98se partition starts with 6 sectors of boot code followed by 
a copy of that boot code.  We only care about the first sector (since 
that should be the only one GRUB touched).  So let's copy sector 7 into 
sector 1.  (I don't have Win98 to verify this.  We'll check it below.)

In Linux, as root, first we want to put GRUB back where it belongs:

grub-install /dev/hda

(You don't need the MBR in hda so no harm in installing GRUB there. 
BTW, the reason putting GRUB in hda1 works is that the Win98 MBR loads 
the hda1 boot sector and runs it--expecting Win98, but GRUB works as well.)

Now let's get the boot sector we need:

dd if=/dev/hda1 of=hda1.boot bs=512 count=1 skip=6

Run hda1.boot through xxd and check that it's close to the hex dump on 
the web page above.  (There should be a MSWIN4.1 at the beginning and 
the IO SYS, MSDOS SYS, and WINBOOT SYS stuff should be at the end, as 
well as the last 2 bytes being 55aa--in the hda1.txt you sent GRUB 
didn't seem to overwrite those parts of the sector.)

If the hda1.boot you get isn't close, try skip=5 or skip=7.  Then put it 
on the disk:

dd if=hda1.boot of=/dev/hda1 bs=512 count=1

Now reboot and away you go--Windows should come up fine.

Here's a safety suggestion.  Before you start mucking with hda, run 
"grub-install /dev/fd0".  Then worst case you'll be able to get your 
grub menu by booting off the floppy.  As long as you don't do anything 
to hdb, your Linux system won't be affected.  But be careful when 
writing things to hda anyway.

FWIW, I wonder whether LILO might serve you better than GRUB.  LILO 
keeps its boot sector in lilo.conf so you don't accidentally write it to 
the wrong place.  It also doesn't have the odd GRUB notation for drives 
and partitions.  Of course this is just one incident so I can't say for 
sure.

With LILO, you have to run lilo (to update the boot sector) whenever you 
change your kernel (or your boot menu, or LILO itself).  With GRUB, you 
only have to run grub when you upgrade GRUB--the menu and kernel are 
found dynamically.

HTH, and that you were patient enough to wait for it.

Dave



More information about the clue-tech mailing list