LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-09-2006, 11:57 AM   #1
Randux
Senior Member
 
Registered: Feb 2006
Location: Siberia
Distribution: Slackware & Slamd64. What else is there?
Posts: 1,705

Rep: Reputation: 54
Preemptive "How do I fix MBR?" question


Hi guys,

I am preparing to install a dual boot setup. I have XP installed and I resized my 40G drive to 24G NTFS partition. This is working fine. Now I am going to partition the rest of the drive for my linux installation.

I would like to know how I can fix the MBR if I fry it while installing a linux distro. I plan to install LILO in the MBR. I don't have a floppy drive, so I can't make a DOS boot diskette. I do have CD drive (which I can boot from) but I don't know how to make a DOS boot disc.

Is there any easy way to do this? Or is there an even simpler way to fix the MBR, for example, from a liveCD distro?

Thanks,
Randux
 
Old 02-09-2006, 12:22 PM   #2
satinet
Senior Member
 
Registered: Feb 2004
Location: England
Distribution: Slackware 14.2
Posts: 1,491

Rep: Reputation: 50
i believe there is an ms utility to restore the MBR.

google time on this one buddy:

http://www.linuxgazette.com/node/9944

etc etc

there's loads out there.
 
Old 02-09-2006, 12:50 PM   #3
Randux
Senior Member
 
Registered: Feb 2006
Location: Siberia
Distribution: Slackware & Slamd64. What else is there?
Posts: 1,705

Original Poster
Rep: Reputation: 54
I was hoping for as windowsless as solution as possible. Thanks for the link, but I don't trust those SOBs as far as I can kick their sorry butts down a mountainside.

I hope to never touch a windows disk again. So I was kinda hoping for the DOS boot-disc on CD approach.
 
Old 02-09-2006, 12:51 PM   #4
UK MAdMaN
Member
 
Registered: Jul 2004
Location: Manchester, England
Distribution: Gentoo
Posts: 211

Rep: Reputation: 30
Stick the XP disk in and reboot, select the recovery console when asked, follow the instructions through and type "fixmbr" when you get to the command prompt.
 
Old 02-09-2006, 01:11 PM   #5
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,280

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Boot with a Knoppix CD ... that's Linux, not Windows ... and from a console window run:
Code:
# dd if=/dev/hda of=/tmp/mbr.bin bs=512 count=1
This assumes /dev/hda is the harddrive you're working with. It might be something else like /dev/sda on your system.

This dd command will create a copy of your MBR in a file named /tmp/mbr.bin , but since you've booted into Knoppix, this "file" is only in memory, not stored on disk anywhere. Now get that file over to some place secure. Email it to yourself, copy it to a flashdrive, burn it to a CD (kindof a waste to burn only 512 bytes to a CD!), run "od -x /tmp/mbr.bin" and painstakingly write down all those numbers on a piece of paper (careful - no mistakes!) You can do all these things from within Knoppix.

Now if you manage to screw up your MBR, you can boot into Knoppix again and restore your MBR by reversing the dd command example above.
 
Old 02-09-2006, 02:19 PM   #6
Randux
Senior Member
 
Registered: Feb 2006
Location: Siberia
Distribution: Slackware & Slamd64. What else is there?
Posts: 1,705

Original Poster
Rep: Reputation: 54
I maimed my disk by typing O instead of P. O killed the partition table. Luckily, the system locked up and committed the changes.

I had written down everything before I downsized my NTFS partition, so I was able to reconstruct it- sortof.

I recreated the NTFS partition and I can see my windows data in it from Slax liveCD. The problem is that it won't boot in Windows (of course) but that may be because I hadn't set the bootable attribute (I just did that now.) But before I try to boot widows, I see that the number of blocks is not the same after I recreated the 1st partition as it was in my notes.

I had to change the number of heads and cylinders at the beginning, because the values were completely out of whack. Now everything is as I noted before I started a couple of days ago, except that I'm showing 7999 blocks more now than I was then.

The disk has 255 heads, 63 sectors/track, 4864 cylinders.

I don't even remember how I set the allocation initially, but it showed Start and End as 1 and 3134 and Blocks as 25165824.

Now it is showing Start and End as 1 and 3134 but Blocks as 25173823.

Any ideas how this happened/what it means?

(I tried the widows recovery disk but it said "If you select OK your hard drive will be formatted." It didn't give me an option to go to recovery console &*)*)&!)

Does anyone know if the MBR gets fried when the partition table is wiped out?

Last edited by Randux; 02-09-2006 at 02:21 PM.
 
Old 02-09-2006, 02:42 PM   #7
UK MAdMaN
Member
 
Registered: Jul 2004
Location: Manchester, England
Distribution: Gentoo
Posts: 211

Rep: Reputation: 30
Quote:
Originally Posted by Randux
(I tried the widows recovery disk but it said "If you select OK your hard drive will be formatted." It didn't give me an option to go to recovery console &*)*)&!)
Windows recovery disks are created for pre-built computers and hold an image of the hard drive. The true XP disk has the recovery console on it.

Quote:
Does anyone know if the MBR gets fried when the partition table is wiped out?
The MBR includes the partition table.
 
Old 02-09-2006, 02:54 PM   #8
Randux
Senior Member
 
Registered: Feb 2006
Location: Siberia
Distribution: Slackware & Slamd64. What else is there?
Posts: 1,705

Original Poster
Rep: Reputation: 54
Ok, I need to reestablish the MBR. I'm searching but if anybody has any quick fixes, please lemme know.

Somebody had the idea to go back to one partition for the whole drive and let Windows (once it boots) figure out the size. I think this is what I did originally after qtparted resized NTFS, so it sounds like a good idea. I just need to get XP to boot.

Last edited by Randux; 02-09-2006 at 02:56 PM.
 
Old 02-09-2006, 03:54 PM   #9
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,280

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Quote:
Originally Posted by Randux
O killed the partition table. Luckily, the system locked up and committed the changes.
Luckily???!!! I'm not following the thought process here.
Quote:
Now it is showing Start and End as 1 and 3134 but Blocks as 25173823.
Any ideas how this happened/what it means?
That sounds about right to me:

((3134*255*63)-63)/2 = 25173823.5 blocks

1 block = 2 sectors, thus the "divide by two" and the resulting "half of a block" in the result.

Where did you get your previous block count of 25165824? Did some program report this to you? Did you calculate it yourself? You can get close to that number if you try to manually calculate using an incorrect formula:

((3134-1)*255*63)/2 = 25165822.5 blocks
Quote:
Does anyone know if the MBR gets fried when the partition table is wiped out?
The partition table is part of the MBR, so technically, ... yes.
Quote:
I had to change the number of heads and cylinders at the beginning, because the values were completely out of whack.
This certainly sounds scary. C/H/S values are pretty bogus these days. LBA is used for larger disks since C/H/S limits cylinders to 1024 max (which equates to a max disk size of 8Gb). Large disks report 255 heads and 63 sectors per track. Cylinders are calculated to yield the true capacity of the disk. Your disk is a 40Gb unit: 255*63*4864*512 = 40007761920.
 
Old 02-09-2006, 04:06 PM   #10
Randux
Senior Member
 
Registered: Feb 2006
Location: Siberia
Distribution: Slackware & Slamd64. What else is there?
Posts: 1,705

Original Poster
Rep: Reputation: 54
> Luckily???!!! I'm not following the thought process here.

It was my way of trying not to cry.

> Where did you get your previous block count of 25165824? Did
> some program report this to you?

Yes. I got it from fdisk after qtparted was done resizing NTFS from 40G to 24G.

Now that I think of it, I'm going to run qtparted again and check something. I'll be back in a minute.

The main thing now is that I need to build an MBR. I don't have a floppy drive, and I have only a "recovery disk". I haven't been able to find anything but wild guesses.

Does anybody know how to rebuild an MBR from linux?
 
Old 02-09-2006, 04:18 PM   #11
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,280

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Do you have a Knoppix CD? If not, download the iso and burn yourself one. Obviously you have access to a computer that works, since you're posting to these forums!

Then you can try the gpart program. This is included with Knoppix. "gpart" means "guess partitions", which sounds like about what you need right now. Consider gpart as a last ditch effort. No guarrantees.

You can see the gpart manpage here:

http://www.stud.uni-hannover.de/user...gpart-man.html

[edit]
Wait, you said you have a Slax LiveCD. Maybe gpart is on that one ... this would save you a download of Knoppix. But you should probably have Knoppix anyway. It's quite useful.
[/edit]

Last edited by haertig; 02-09-2006 at 04:19 PM.
 
Old 02-09-2006, 04:34 PM   #12
Randux
Senior Member
 
Registered: Feb 2006
Location: Siberia
Distribution: Slackware & Slamd64. What else is there?
Posts: 1,705

Original Poster
Rep: Reputation: 54
Ok, you're not going to believe this but:

I am posting this to you from my xp machine.

Here is as best as I can reconstruct, the sequence of events:

01) Windows/XP: defragged hard drive and shut down
02) Kanotix Live: used qtparted to resize NTFS from 40G to 24G. qtparted reports that one 24G partition was created as requested and hidden partition was automatically created for the free space.
03) Windows/XP: rebooted
04) Windows/XP: got message that system was checking system (took about 20 minutes, went through three steps) End result was system was running better than ever, and now Windows/XP sees only one drive and thinks it is 24G
05) Slax Live: used fdisk to add some partitions for linux. In the process, blew the partition table all to hell by using option "O". Do not, I repeat, do NOT use option "O" unless you want to wipe out your partition table!
06) Slax Live: using notes I took before doing anything, I reconstructed, to the best of my ability, the exact partition scenario I had observed before starting. I had to change the number of cylinders and number of heads as when the system came up with no partition table it had lost all of the settings I noticed at the beginning. I had to specify starting and ending positions and change the partition type to HPFS/NTFS.
07) Slax Live: I was able to see all of my windows data from Konqueror.
08) Tried to boot from HD. BIOS would not boot.
09) Slax Live: reconfigured partition table to have only 1 partition for full size of disk in hopes that XP would figure it out as it sorta did after the NTFS resize in step 04.
10) Tried to boot from HD. BIOS would not boot.
11) Had brainstorm
12) Kanotix Live: used qtparted to go through original steps of resizing 40G NTFS filesystem to 24G. It created 24G NTFS partition and hidden partition with free space. NOTE: It reported that it started at .03M off the beginning. This must account for the difference in block counts from my manual reconstruction, and explains why I couldn't boot. Now when qtparted fixed the partition table according to the way I had resized it in step 02 the MBR was logically backed-out of the data partition and became visible to BIOS again. Also important note: people who said that MBR was changed as a result of partition table changes, I think this statement is not correct. Either qtparted built an MBR (unlikely but possible) or having it logically move the beginning of the data to .03M instead of 0 offset as I had mistakenly done, trying to fix it manually, indicates that NOTHING of the data was changed during various partitioning changes, even blasting the table using "O" to clear it.

The key here is that I was careful NOT TO MODIFY ANY OF THE DATA!!! I mean, it could have been modified by my stupid mistakes with fdisk, but I didn't touch it from a LiveCD except for read-only.

Apparently everything is back to normal.

Maybe this should be a sticky?
 
Old 02-09-2006, 04:35 PM   #13
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,280

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
You haven't yet told us what happens when you try to boot with your hosed up MBR. Do you get any kind of error message? Something like "Missing operating system" perhaps? Absolutely nothing? Either your partition table or your bootcode may be screwed up. Or both. The bootcode and the partition table are what make up the MBR. I would not expect a repartitioning program to mess with the bootcode, but at this point I don't really know what you've managed to get yourself into.

But with only one partition (apparently), I don't see this an an unrecoverable error. A pain in the butt - yes, but you can probably get through it with persistance. Just don't panic and make the situation worse. Letting some Windows recovery CD have its way with your system would probably make the situation worse.
 
Old 02-09-2006, 04:39 PM   #14
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,280

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
OK. Our posts crossed in transmission. Glad you got it to work.

Now, don't you REALLY want to run "dd if=/dev/hda of=/tmp/mbr.bin bs=512 count=1" and SAVE that precious little 512 byte file in a safe deposit box or something similar!
 
Old 02-09-2006, 04:52 PM   #15
Randux
Senior Member
 
Registered: Feb 2006
Location: Siberia
Distribution: Slackware & Slamd64. What else is there?
Posts: 1,705

Original Poster
Rep: Reputation: 54
Quote:
Originally Posted by haertig
OK. Our posts crossed in transmission. Glad you got it to work.

Now, don't you REALLY want to run "dd if=/dev/hda of=/tmp/mbr.bin bs=512 count=1" and SAVE that precious little 512 byte file in a safe deposit box or something similar!
LOL naw, I'll just use qtparted.

Thanks, it sounds like a good idea!

P.S.

When the BIOS came up with the MBR not visible, I just got my normal message (I'm sorry I remember exactly what it was) which I get when it goes through the search order I set (CD, HD, etc) and can't find any OS.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie question: whats the difference between "su root", "su" and "su -&quo mojarron Slackware 9 12-07-2009 05:08 PM
FIX: wine error "No Program Start Menu Found" JackSmith Linux - Games 3 07-02-2009 11:38 PM
"Disk boot failure..." after lilo writes to the MBR alexko Linux - Hardware 6 11-16-2004 10:43 AM
Will "grub-install /dev/hda" kill Windows XP MBR? Zullocrit Linux - Newbie 3 09-25-2004 10:50 AM
Simple GAIM "ssl support needed" fix Mainframe Slackware 9 05-20-2004 01:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:11 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration