LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 04-01-2006, 10:01 PM   #1
stevod333
Member
 
Registered: Mar 2006
Location: Australia
Distribution: SUSE 10.2
Posts: 47

Rep: Reputation: 15
How can I wipe the MBR clean and remove GRUB


I'm having a terrible lot of trouble getting GRUB to work successfully.

When things go terribly wrong, sometimes it seems the best thing to do is to completely remove GRUB from the MBR.

I have tried the DOS command: FDISK /MBR, and WinXP recovery console commands: FIXMBR, FIXBOOT and possibly some others, but nothing seems to be able to erase the MBR to the depth that GRUB installs itself at.

After using any of the above commands, all I get at boot time is a nasty message saying "disk error". Even re-installing WinXP won't fix it. The only method I have found so far is a Seagate disk utility that does a quick low level format, which also destroys all partitions, but atleast then at boot time I get a much more friendly message "Insert system disk".

Anyone know how to wipe the MBR clean without damaging the partitions?
 
Old 04-01-2006, 10:27 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,109

Rep: Reputation: 985Reputation: 985Reputation: 985Reputation: 985Reputation: 985Reputation: 985Reputation: 985Reputation: 985
Saw you other thread, decided to stay out of it as I don't use FC. I don't understand why you have this problem, but do this from a Linux console
Code:
dd if=/dev/zero of=/dev/hda bs=1 count=446
Will leave your partition table intact - XP "fixmbr" will re-install the ntldr code.
 
Old 04-01-2006, 11:08 PM   #3
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD
Posts: 1,979

Rep: Reputation: 290Reputation: 290Reputation: 290
Quote:
Originally Posted by stevod333
I have tried the DOS command: FDISK /MBR, and WinXP recovery console commands: FIXMBR, FIXBOOT and possibly some others, but nothing seems to be able to erase the MBR to the depth that GRUB installs itself at.
I am sorry that these Windows commands are not working for you, but you probably can't blame it on grub.

Your MBR makes up the first sector (512 bytes) of your harddisk. This first sector is numbered 0. The first 64 sectors of your harddisk are called "track 0". After track 0 is where "normal stuff" begins (your OS, typically).

Of your MBR, the first 442 bytes are called the "boot code". Then the next 4 bytes are the "volume bytes" (used only by newer versions of Windows, AFAIK). The next 64 bytes are called the "partition table". Then the remaining 2 bytes are "signature bytes" that mark the end of a valid MBR.

Installing grub to your MBR will overwrite the 442 bytes of boot code, and put some more data in the (normally unused) sectors 1 through 63. I don't think it goes all the way up to sector 63 - it probably ends significantly before that point.

Running the old msdos FDISK /MBR will overwrite those 442 bytes of boot code with code that should boot any version of Windows AFAIK. It may actually wipe out the first 446 bytes (including the volume bytes), but I can't remember for sure. I do not know why this is not working for you. Just the opposite usually happens. A very standard complaint on these forums is when someone has a working Linux installed, then installs Windows, and wonders where their Linux went. What happened is that Windows overwrote the boot code and thus wiped out grub (or lilo - another Linux bootloader that may be resident in the MBR).

When you run FDISK /MBR note that it does not clear out the part of grub that is in sectors 1 through 63. It doesn't need to. Windows does not use these sectors in track 0. Sectors 1 through 63 may contain nothing, or random data (an old grub install perhaps), and not make one bit of difference to Windows. I know of one sneaky program, Intuit's TurboTax, that installed some code in track 0 a few years back in an ill-conceived attempt at copy protection. This was Intuit's sneaky way to keep their code in place even if you reformatted your disk (format won't touch track 0). However, Intuit shoved it's code into track 0 without concern about what else might already be there. They were wiping out people's Linux grub and lilo installs!

Now back to your problem. I do not know why FDISK /MBR or the other tools you tried would not overwrite the bootcode as they were supposed to. You could use Linux to zero out the bootcode first, and then try your tools again. Assuming your harddisk is "hda", you can clear the bootcode like this:
Code:
# dd if=/dev/null of=/dev/hda bs=442 count=1
Be VERY careful to type this command correctly!!! A minor typo and you can really hose yourself. If you limit yourself to only zeroing the first 442 bytes of track 0, you will leave your partition table intact.
 
Old 04-03-2006, 05:18 AM   #4
stevod333
Member
 
Registered: Mar 2006
Location: Australia
Distribution: SUSE 10.2
Posts: 47

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by syg00
Saw you other thread, decided to stay out of it as I don't use FC. I don't understand why you have this problem, but do this from a Linux console
Code:
dd if=/dev/zero of=/dev/hda bs=1 count=446
Will leave your partition table intact - XP "fixmbr" will re-install the ntldr code.
Thank you both for your advice.

syg00's command worked perfectly, although it took "count=512". to completely erase the MBR and give me the old "disk boot failure - insert system disk" message that I was looking for.

Sorry haertig, but you syntax was slightly off - usage: bs=1 count=[bytes] seems to be the correct syntax, but only using "if=/dev/zero". Thank's very much though for your detailed explaination - it's given me me a much better understanding of what is going on within the MBR.

I owe you both a great debt.

Cheers, Steve.
 
Old 04-03-2006, 05:20 AM   #5
stevod333
Member
 
Registered: Mar 2006
Location: Australia
Distribution: SUSE 10.2
Posts: 47

Original Poster
Rep: Reputation: 15
Oops, 512 bytes did destroy the partitions! you did warn me to be careful!
 
Old 04-03-2006, 05:48 AM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,109

Rep: Reputation: 985Reputation: 985Reputation: 985Reputation: 985Reputation: 985Reputation: 985Reputation: 985Reputation: 985
It didn't actually.
You destroyed the partition table - mis-interpretation of the symptoms (by you). The actual partitions still exist, as does the data contained therein.
Like when a file is deleted - you don't actually delete the file, just the pointer to it.

Situation is recoverable, but I think you have enough to keep you occupied ...
 
Old 04-03-2006, 09:42 AM   #7
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD
Posts: 1,979

Rep: Reputation: 290Reputation: 290Reputation: 290
Quote:
Originally Posted by stevod333
Sorry haertig, but you syntax was slightly off - usage: bs=1 count=[bytes] seems to be the correct syntax, but only using "if=/dev/zero".
Youy're right, /dev/zero is what I meant. Now didn't I tell you that you must be "very careful"?! But /dev/null might actually have worked by some stroke of luck (never tried it). Also, you can flip those bs and count parameters. It's just math. 1 * 442 = 442 * 1.

Now that you've whacked your partition table with a wipe of the first 512 bytes, you can attempt to use the "gpart" program (short for "guess partitions") to see if you can recover. If nothing else, your foray over to the Dark Side of harddisk maintenance will leave you with loads of experience to become a Jedi Master for teaching others!
 
Old 04-03-2006, 09:51 AM   #8
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD
Posts: 1,979

Rep: Reputation: 290Reputation: 290Reputation: 290
Quote:
Originally Posted by stevod333
although it took "count=512". to completely erase the MBR and give me the old "disk boot failure - insert system disk" message that I was looking for.
"...that I was looking for" ???!!!

You must be some kind of masochist. If you liked what 512 did for you, try something like "count=999999" for even MORE fun!

[ Please - don't really do that. It was a joke. You never know who's going to miss the sarcasm in one of these posts and really attempt a disk-blaster command like that! ]
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to clean MBR since Windows XP Bob_Esponja Linux - Newbie 3 12-12-2006 05:26 AM
HD won't boot after clean OS installs. Unfixable MBR? Guivre Linux - Hardware 1 04-22-2005 08:24 PM
should i wipe my mbr? bandofmercy Linux - Newbie 6 09-26-2004 11:14 PM
how to wipe MBR on slave drive from windows? Ebenonce Linux - Newbie 9 08-16-2004 02:57 AM
How to clean super block and MBR under Linux preswang Linux - General 5 10-30-2003 05:31 AM


All times are GMT -5. The time now is 03:13 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration