Help - Search - Members - Calendar
Full Version: How to Fix a FUBAR'd MBR w/out Formatting
Neowin Forums > Help & Discussion Center > A Collection of Essential Guides
Computer Guru
Fixing the Master Boot Record without Formatting

This is the ONLY guide on the web to fixing a FUBAR'd MBR without formatting or deleting your partitions.

A FUBAR'd MBR is one that cannot be repaired by using fixmbr or fdisk/mbr.

A warning: all the steps are laid out very clearly, but it takes absouloutely forever to carry out. Its a long and harsh road, but the path is clearly marked, there are no dead ends, and all the pot-holes are filled.

For n00bs and advanced alike, this works, and it works well. It will test your patience and your resolve, but ITS WORTH IT.

YOU WILL NOT LOSE A SINGLE BYTE OF DATA!

This is the ONLY way. I searched the entire web for a safe and secure way of pulling it off, and THERE WAS NONE.

There are some steps that can and are in the process of being shortened.
You are required to install Linux, but we will not even step foot in it. Do not be afraid smile.gif

Please post feedback on the blog, its where people from all over the web will be reading the guide in the end.


EDIT
Forgot to post a link pinch.gif
johngalt
Left a moment there - not sure if all that was actually necessary at this point in time....

But at the very least, his steps are detailed *and* explained - so anyone carefully reading the blog and not thinking they know what to do and getting ahead of themselves should have a working MBR in a matter of an hour or less.
Computer Guru
Thanks John.
I left a reply to your post there....

Basically I am working on trying to find a copy of a Grub Installer that boots from a floppy or something, without Linux at all. I think that will make it a lot easier, no Linux download, and no Resuce Mode for people who already installed Linux.

Plus, most beginners tremble at the *nix word smile.gif
johngalt
Hmmm, I wonder if I can assist you in this venture. I don't know if there is a floppy - accessible GRUB, b/c I am not sure that it will fit - but a very tine ISO would work just as well, and not limit you to a 1.44 / 1.76 (in case you use the M$ Extended Floppy format) barrier.

A 3 MB ISO may seem like a waste of a CDR - but if that ISO saves their arse even *one* they'll place it in storage and refer to it every single time.

EDIT: Added the following
Read your replies, and replied again. Thanks again for a well documented and clarified guide. As I said before as long as n00bs / lusers don't get ahead of themselves, they'll be back up and running in under an hour.

Now to find out if there is a GRUB install for use for the fix to avoid having to get a 20-40 MB install CD download (I personally use Gentoo, and the minimal CDs for it at 65 MB, but there *has* to be a way of compressing only the *absolutely* essential files into a minute image.
Computer Guru
Thanks for the support John.
I will hit the Linux Forums seek my fortune there ^*^
If I find anything, I will be sure to let you (and everyone else) know.
johngalt
Kewl. I will keep an eye out for it as well. I *know* there was a distro that was floppy loadable, and thus I may be wrong about GRUB not fitting on a floppy, but I cannot remember for sure.

And no, not referring to QNX - that is a different flavor entirely - and I have used it before when I worked at IBM. This was something more recent that I saw.
Computer Guru
Well, Fedora Core 4 gives you an option to install Grub TO a floppy, but that is if you do not want to isntall to MBR. I am looking to install Grub FROM a Floppy TO the MBR.

I've posted, just waiting for a reply..
johngalt
If you can install Grub to a floppy, and can locate the grub files on the floppy, I got the entry that will allow you to automatically install it to a HD....

We can edit it so that it can take into account various types of HDs - such as (hd0,0) etc, or to see how it works (if differently) for SATA drives.

try this:

CODE

#For installing GRUB into the hard disk
title Install GRUB into the hard disk
root    (hd2,0)
setup   (hd0)


In this example, my 'root' files, IE where the grub.conf is located, is [hd2,0]. By altering that you should be able to install Grub to the HD from a floppy, no?

EDIT: Added the following
In fact, that should work correctly, except that from that point on it would look for the floppy diskette every time it booted, and then the 'optional' steps at the end to remove GRUB would become mandatory to help fix it.

Of course, as you also mentioned in the guide, if the user already has Linux then they can perform this themselves and save a lot of time.
Computer Guru
looks like this is shaping up nicely smile.gif Good work John ^*^

Anyway, just a couple of things that I think would need to be looked at first however:
1) If I were to make the Grub floppy image on my computer, then distribute the unpacker that users can run, the entries in Grub will correspond to teh entries on my pc.. i.e. Windows on hd0,0 and linux on hd0,3 and hd1,2

There needs to be a wizard that will correctly identify the existing partitions. especially since the command to boot to windows is drastically different from booting to Linux, and not all of our users will be on one system or the other, ther are some linux-only and windows-only people.

but its a start smile.gif I'm working on it too... just reinstalling FC4 tonight the real way (did the minimal install to get my MBR working he he) then I will see what i can get.

again, thanks a million!
johngalt
Hmmm.... this is getting tricky - but you could *theoretically* make multiple entries - like this:

CODE

#For installing GRUB onto device IDE 0 Disk 0
title Install GRUB into the hard disk
root    (fd0) [color=#FF0000]<--- changed that - that *should* be correct for locating the grub.conf on the floppy[/color]
setup   (hd0)

#For installing GRUB onto device IDE 0 Disk 1
title Install GRUB into the hard disk
root    (fd0) [color=#FF0000]<--- changed that - that *should* be correct for locating the grub.conf on the floppy[/color]
setup   (hd1)

#For installing GRUB onto device IDE 1 Disk 0
title Install GRUB into the hard disk
root    (fd0) [color=#FF0000]<--- changed that - that *should* be correct for locating the grub.conf on the floppy[/color]
setup   (hd2)

#For installing GRUB onto device IDE 1 Disk 1
title Install GRUB into the hard disk
root    (fd0) [color=#FF0000]<--- changed that - that *should* be correct for locating the grub.conf on the floppy[/color]
setup   (hd3)


Of course, then, if SATA drives are represented differently (I don't have access to am cine with SATA enabled, so I cannot say one way or another) then that will need editing as well to add entries for SATA drives.

An easier way might be to make sure there is no timeout setting (either set it extremely high, like 65535, or comment it out completely) so the user is *forced* to make a choice, then give him the commands to do so, with an explanation:

CODE

title Please read this carefully.  You have just booted your system
title with a *nix boot loader called GRUB.  In order to facilitate the
title MBR fix process, please select the very last entry in this list
title using the arrow keys and then hit the [E] key to edit the entry.
title Use the arrow keys to select the last line, which should have
title the syntax "setup (hd0)" - replace the 'hd0' part, leaving the
title parentheses, with your Windows system drive number - i.e.
title if the Windows disk is the master drive on the primary IDE
title channel, then use hd0 - if it is the slave drive on the primary
title IDE channel, use hd1.  Master on the 2nd IDE channel = hd2
title and slave on 2nd IDE is hd3.  Please note that IDE nomenclature
title starts at 0, so IDE 0 is the first* IDE channel and IDE 1 is the 2nd.
root (fd0)
setup (hd0)


Not exactly a wizard, but getting there- still not very n00b friendly, I admit, as you have to be savvy enough to know 8where you stuff is installed.

But a wizard on a floppy - umm, well...I don't see it.
Kudzu can probably run off the CD ISO image I mentioned earlier ;-0
Computer Guru
well, I *may* have found something easier:

QUOTE
Invoking grub-install
The program grub-install installs GRUB on your drive using the grub shell (see Invoking the grub shell). You must specify the device name on which you want to install GRUB, like this:

    grub-install install_device
   
The device name install_device is an OS device name or a GRUB device name.

grub-install accepts the following options:

--help
Print a summary of the command-line options and exit.

--version
Print the version number of GRUB and exit.

--force-lba
Force GRUB to use LBA mode even for a buggy BIOS. Use this option only if your BIOS doesn't work properly in LBA mode even though it supports LBA mode.

--root-directory=dir
Install GRUB images under the directory dir instead of the root directory. This option is useful when you want to install GRUB into a separate partition or a removable disk. Here is an example in which you have a separate boot partition which is mounted on /boot:
          grub-install --root-directory=/boot hd0
         


--grub-shell=file
Use file as the grub shell. You can append arbitrary options to file after the file name, like this:
          grub-install --grub-shell="grub --read-only" /dev/fd0
         


--recheck
Recheck the device map, even if /boot/grub/device.map already exists. You should use this option whenever you add/remove a disk into/from your computer.


THis is a helper program that comes with the grub package. It can theoretically be invoked to install to the MBR via a script. Now the only problem would be, that a simply MS Boot Disk would not suffice, we woudl have to have a complete linux kernel fit on a floppy! but nesides the kernel there would not be anything, since the only thing we need is the kernel to run the grub-install script.

We could add grub-install as runtime script, it would install and then exit.


However, now seems to be the right time to ask this quesion: Do we *need* a floppy image? In this day and age, most new PCs do not have floppies. Every PC needs a CD-Drive however.... I personally have a floppy cuz many morons from the past still give me files via 3.25, but its disabled from teh BIOS for virus protection and speeded booting
Computer Guru
http://www.toms.net/rb/

This is a linux kernel that claims to it on a floppy... looking good smile.gif
johngalt
That is the one I was trying to find lol.

I forgot about grub-install script, figures though since I always manually install grub by running grub from the CL....

I also still have a floppy in my system (both of them in fact) and can *easily* test the install scripts as well. The best part? Both machines (P4 2.0 GHz and Celeron 366 laptop) already have GRUB installed to hd0 to begin with, so as long as it is a current version of Grub, it will not affect anything (of course, I will have to manually specify the root folder to avoid losing my current configurations, but that is easy enough).

But, you still are no closer to a wizard / script that *auto* detects the HD and knows where to place it, no?
Computer Guru
actually, we are.

Grub-install itself I *believe* does that. its how you get standard grub.conf across all distros.

My FC4 install last night went awry, guess where: Grub! Yep, apparently if you give the ext3 partition a name (Like I did mine: Fedora Core 4), then assign it a label '/' in FC4 setup, grub wont boot it.. you get kernel panic....

Soon as its fixed I'll try to compile a script and get you a copy.
thnks!
johngalt
hmmm - if this is true then I should be able to boot to Gentoo and do the grub-install and see how it outputs to the floppy, right?

Unless the script is not a part of the Gentoo GRUB portage package....
Computer Guru
IMO it should be.. but you would not output to floppy, you would actually copy the script to the floppy, then run it from the floppy via tom's RB
johngalt
I can check now - great little tool called RSFgui - windows executable that allows you to read ReiserFS partitions (which is what I use for Gentoo).

Just as I thought - no grub-install script in /boot/grub.

I will try searching the usually /bin /sbin etc dirs later on. but I haven't gotten X working fully yet so I have no real Internet access. Yet. (and yes, by Internet access I mean the ability to enter forums and read stuff and reply. Not even via elinks / links2.

I went ahead and rated ya a 5 - with the work you're putting in to it it is definitely worth that much - even if it only saves .0001% of all computers out there - all those folks are gonna love you for life.
Computer Guru
better than RSFgui, there are programs that can mount reiserfs systems in my computer, from where you can read and write to the NATIVELY!

i am usng ext3 with IFS Drives, (its free), but hope to upgrade to resiserfs soon

thanks for the rate... anyone else biggrin.gif

best of luck with you net.. Linux needs net very much
johngalt
Yeah, I said *net8 and meant GUI. I can do things without a GUI, but browsing is still too much of a PITA without a GUI.

When you said tools to mount ReiserFS, were you referring to *windows*? because I have been looking for such a tool and cannot find it.

If you meant in Linux, *that* I can see - building support for it in your kernel helps tremendously.
Computer Guru
no, i meant Windows...
I just installed reiserFS.. an realized that the IFS driver does nt work on reiserFS
http://p-nand-q.com/download/rfstool.html is what you have?
johngalt
no, this one:

http://www.wolfsheep.com/map/#RFSGUI

QUOTE("Michael Adams")
Unlike most other tools, RFSTOOL is NOT required.
- IOW - it is completely standalone.
Computer Guru
Cool!
I just formatted my nix sad.gif

I downloaded Gentoo 2005.1 it reached 99% (with GetRight) then all of a sudden it resets to ZERO!

BUT before that I made much progress in Fedora Core with grub-install.

1) Grub2 is not yet included with anything, and hard to install. If we use GRUB2 = much more happy people!
2) grub-install is very picky on where it is installed to, gives much trouble if the first partition is NTFS sad.gif
3) Grub itself comes with a basic bash.... can be used to run Grub-Install from within Grub?!
4) Looking a tad harder, but much clearer.
johngalt
well, it depends upon which Gentoo 2005.1 you are downloading - and sometimes those managers get FUBAR'd from the several mirrors available - There are so many ways to get Gentoo working that it is impossible for me to know which one you are using.

I *can* say that there is now a Gentoo LiveCD (and a Live DVD as well, ISTR) that allow you to install from a GUI based installer script, but also allow you to simply have a working install environment when installing. The basic problem is that different boot CDs have support for different parameters - for example, if you want to use LVM, then you'll not be able to go through a stage 1 (I think). Other restrictions apply as well.

Regarding grub-install - I had a feeling that this would be the case seeing as it was an install script....

re: Grub itself - that is what the install entry I have in my grub.conf makes use of....

as long as it does not get hazy, you are all good.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.