Symptoms of my problem:
When attempting to boot into Windows, GRUB prints to the screen 'GRUB
loading stage2...' and hangs. (This is happening because the small bit
of code that is the of GRUB
has been written to the boot sector of the Windows partition. The
system files that normally boot Windows have been corrupted.)
If you are lucky (and I am not), you might be able to use a . In my case, every time I typed 'sys a: c:' or
'sys c:' I got back
Invalid media type reading drive C,
Abort, Retry, Fail?
Read on about how I recovered.
How did I fix this?
(Note: if you have two hard drives, read this explanation by Don Hardaway (email@example.com).)
This is all relatively simple if you know what you're doing (which I
usually don't... worst linux user ever). What needs to be done is
(NOTE: Jason Thomas pointed out
that it might only be necessary to zero out the boot sector of the
Windows partition and recopy the system files (assuming that you have
GRUB installed correctly on the MBR)... this means only do numbers 2
and 4 from the following list. This avoids zeroing out the MBR (number
1) which is the most delicate part of this whole scheme.)
- Zero out MBR. (but not all of it!) You need to use 'dd' to
erase the MBR. For my machine the command was:
dd if=/dev/zero of=/dev/hda bs=446 count=1
Why the 'bs=446'? Because the rest of your MBR holds the partition
table for the drive... which you do not want to destroy. (note how
'hda' in this context refers to the MBR where, in general, 'hda' is
the first hard drive in your system)
- Zero out the boot sector of the Windows partition. Once
again, for my system, the commad was:
dd if=/dev/zero of=/dev/hda1 bs=512 count=1
This erases the boot sector of the first partition on hda.
- Re-write a Windows MBR. You'll need to boot into DOS with your
trusty Windows 98SE OEM and do:
(NOTE: I have received reports
that you need to use specifically a Windows 98SE OEM
("Original Equipment Manufacturer") boot disk (boot98se.exe) as neither of the two
commands sys a: c: or format C: /s seem to correctly copy the system
files to the boot sector of Windows ME (and, I assume, anything later
than ME) partitions. "Apparently the Windows Me disk requires Windows
to be installed and detectable before it will do squat, the 98 disk
ignores this and just does what we want (install the boot
sector)."--reader Erich Hoover for the tip)
- Copy Windows system files to boot sector of Windows
sys a: c:
Which tells DOS to copy the system files from a: to the boot sector of
- At this point your computer should be able to reboot into
Windows as if you just had Windows installed. Try it by
- If all has gone well, you can .
- Now is a good time to make copies of the boot sectors of all
your partitions and your MBR. Then you can use 'dd' to replace
them if anything should go wrong in the future.
- Pat yourself on the back... you deserve it.
I would like to thank George Fisher, James Lloyd, and Jason Thomas for
their help in resolving my problem and the eventual solution. Please
email me at firstname.lastname@example.org for any
corrections or additions to this document.
This work is licensed under a
Creative Commons License.
What's all this talk of 'stage1' and 'stage2'?
The MBR (master boot record) is a small piece of space on the
beginning of the hard drive that tells your computer what to boot from
(a floopy, cdrom, hard drive) and where on that media to boot from.
The amount of memory in the MBR is so small that it doesn't allow for
much in the way of fancy graphical environments that allow you to
choose what you want to boot (remember LILO? not much in the way of
graphics or features). GRUB gets around this by having a and stage2 part of the
bootloading process. is
written to your MBR when you install GRUB and stage2 is somewhere on
your hard drive where there is much more space to put a fancy
bootloader like GRUB.
simply runs stage2... what happens then depends on how you have GRUB
configured. If you did a default install while installing RedHat
Linux like myself, launches
a menu that you can choose which partition on your hard drive to boot
What if you have two drives?
This is an exact quote from Don Hardaway who was able to recover from
a similar grub problem with two drives:
"I am not sure I have all of the answers but here is what I
understand and what I did.
The first 512 bytes of any disk is the MBR [Master Boot Record].
My understanding is that you can write to the MBR of any disk. In my
case I have hda (my first drive) and hdc (my second drive).
[Here's what happened:]
That was it. I rebooted and now can select windows to launch on hda or
linux to launch on hdc." (Thanks to Don Hardaway (email@example.com).)
Copying system files...
- First you will need a Windows boot disk with the system files on
it. has all the flavors
of Windows and DOS.
- Boot into Windows with this disk and try 'sys a: c:' which tells
DOS to copy the system files that reside on the floppy in the a: drive
to the boot sector on drive c:.
NOTE: if this doesn't work and you get 'invalid media type while
reading drive c, abort, retry, fail?' then you can try one more thing
that may or may not work (it didn't for me). You can try to issue
'fdisk /mbr' and then a 'sys a: c:'. BE CAREFUL!!! 'fdisk /mbr' will
write over your MBR and anything (GRUB) on it so you better be
prepared to .
How do I reinstall GRUB?
Hopefully you know how to do this but if you don't:
- You need to install GRUB
on your MBR:
- Boot into linux.
- where the 'grub' and
'grub-install' executibles are. Change directories to where these
./grub-install /dev/hda which will install GRUB on
your MBR. (NOTE: if you type './grub-install /dev/hda1' you are back
where you started from... this is bad)
- Next, you need to tell GRUB where it's pieces reside:
- Use 'su' to become root.
- Go to where your 'grub' executible resides.
- you are now in the command-prompt version of GRUB's stage2. you
need to use 'install' to tell GRUB where to look for , stage2 and the menu.lst file ( is a
good article that covers menu.lst files). In my case, I have a boot
partition (which is the second partition on drive c:... or ), so I did the following install command:
grub> install (hd0,1)/grub/stage1 d (hd0) (hd0,1)/grub/stage2 p (hd0,1)/grub/menu.lst
If the GRUB executibles (and the and stage2 executibles) are in your Linux
root directory (as in '/boot/grub/') and your Linux partition is the
second partition (assuming you have something like Windows or NT as
the first partition) you would want to do:
grub> install (hd0,1)/boot/grub/stage1 d (hd0) (hd0,1)/boot/grub/stage2 p (hd0,1)/boot/grub/menu.lst
If your situation is different than the above (if the above install
fails) then you can use the 'find' or 'cat' commands available from
the GRUB prompt to look for the menu.lst file and then just change the
above to reflect where , stage2 and menu.lst files are (more than
likely all these files will be in the same directory).
Hopefully when you reboot, the GRUB menu will come up (although
Windows may not boot, hopefully again Linux will).
How do I find a file?
Use the find command... for example if you are looking for your GRUB
executibles you can type
find . -name "grub-install" -print
and that will return any matches.