LinuxQuestions.org
Help answer threads with 0 replies.
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 06-17-2005, 01:56 AM   #1
TomF
Member
 
Registered: Sep 2003
Location: California
Distribution: RH9, Fedora: FC1, FC3, Suse9.3
Posts: 54

Rep: Reputation: 15
MBR zeroed. Can I verify backup MBR?


I am running FC3 with Grub in the /dev/hda MBR and / in /dev/hda7 .

I accidently zeroed my mbr. I have not rebooted. I have a backup file MBR.bin that I made last year. I don't think I changed the partitions since making the backup, but am not sure. Could I dd the MBR file to /dev/hda, do an fdisk p command, and compare the results to the output of gpart to see if they agree?

Is there another way to check if the MBR.bin agrees with my current partition structure, or to determine the partition structure from /proc?

I also have a recent dar backup. Is there a way to restore the MBR from it?

What is the best way for me to go from here?

Last edited by TomF; 06-17-2005 at 02:03 AM.
 
Old 06-17-2005, 02:57 AM   #2
SiLiCoN
Member
 
Registered: Sep 2004
Location: India
Distribution: Solaris 9, FreeBSD 4.10, Slackware, RedHat, Knoppix,
Posts: 84

Rep: Reputation: 15
boot from the CD in rescue mode
then
#chroot /mnt/sysimage
#grub-install <device name> (like /dev/hda1)

that should fix the boot record...u dont need a backup though
 
Old 06-18-2005, 10:36 PM   #3
TomF
Member
 
Registered: Sep 2003
Location: California
Distribution: RH9, Fedora: FC1, FC3, Suse9.3
Posts: 54

Original Poster
Rep: Reputation: 15
I discovered the file /proc/partitions, which has the partition structure that I zeroed out in the MBR. I copied it to another file system, so I won't lose it when I reboot.

I plan to try using dd to copy my backup MBR to the first 500 bytes of /dev/hda. Then I'll execute fdisk to print the partition table. If it is the same, I think I'll be done, and won't have to reinstall grub. Right?

If not, I'll still need to find out how to change the partition table in the MBR without affecting the data on the drive. Could I do this by executing fdisk with the first 500 bytes of /dev/hda zero, creating partitions according to the partitions file, and doing the grub-install? Could I do it by passing the partition structure to gpart -W?
 
Old 06-18-2005, 11:13 PM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,356

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Erkk !!! - how do you accidently zero the MBR ???.

You seem to have a fixation with the number 500 - did you merely zero just 500 bytes, or the whole sector ???.
May not matter, but fdisk (and cfdsik) for example won't open a disk without the signature bytes. If you only blotted 500 bytes, this won't affect you. Haven't tested if the following tools suffer the same restriction.

gpart may do the job for you, and testdisk has had good reports from people I've recommended it to.
Rebuilding the part table will not (for some value of "not" ) mangle your data. Simply indicates the start and end (and sector count, and ... well, you get the idea) - not a problem.
UNLESS it's wrong - obviously that has the potential to hurt.

Once you're happy with the rebuilt part table, then you can re-install grub - that's a no-brainer. And yes, you should re-install - it also has sector offsets in it. Easy to install and be sure. Save the grub.conf/menu.lst first.
 
Old 06-19-2005, 12:23 AM   #5
WhatsHisName
Senior Member
 
Registered: Oct 2003
Location: /earth/usa/nj (UTC-5)
Distribution: RHL9;F1-10; CentOS4-5; DebianSarge-Squeeze
Posts: 1,151

Rep: Reputation: 46
Before you do any more damage, you really should clarify how you "zeroed the MBR". It might help us suggest possible fixes.
 
Old 06-19-2005, 10:42 AM   #6
TomF
Member
 
Registered: Sep 2003
Location: California
Distribution: RH9, Fedora: FC1, FC3, Suse9.3
Posts: 54

Original Poster
Rep: Reputation: 15
I forgot about the last 12 bytes. The bad command was dd if=/dev/zero of=/dev/hda bs=512 count=1. I was trying to wipe out another drive in preparation for reallocating the partitions, but I pasted the command and forgot to correct the "of=" parameter.

'Rebuilding the part table will not (for some value of "not" ) mangle your data." I understand that if only the partition table is touched then the partition data is unaffected, and if the resulting partition table is correct, then the filesystems will be correctly mounted when I reboot.

I don't understand what fdisk does: does it store anything in the partitions when creating or modifying the partition table? I would guess not, since creating the filesystems is a separate operation, but I would like to be sure. Since gpart and testdisk are designed to fix the partition table, I would not expect them to touch the filesystems, but fdisk worries me.

I decided to check testdisk, and liked what I saw, so I installed and executed it. The results looked right, but were not formatted the same as the /proc/partitions file. I decided to save the partition table and execute the fdisk print command. fdisk shows hda1-hda9 the same as a previous fdisk, before I zeroed the MBR, and hda10 looks right, so I think the partition table problem is solved.

Since the testdisk suggestion worked so well, I'll also take the suggestion to do a grub-install /dev/hda1.

Added: the GRUB manual says to execute grub-install /dev/hda, so I did that instead. Then I remembered that /dev/hda1 is mounted to /boot, so I am again doubtful. Are the two grub-install commands equivalent, or should I re-install to hda1?



Thanks for the advice.

Last edited by TomF; 06-19-2005 at 11:14 AM.
 
Old 06-19-2005, 07:16 PM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,356

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
fdisk is fine, it just defines the limits of the partition(s) as you would expect.
But it just won't talk to the disk if the entire first sector is zapped - see some of my mutterings here if interested.
So obviously testdisk did it's job if you could get fdisk to fire up.

As for grub, it *has* to be installed into the MBR - you currently have no loder code in there at all.
Remember ??? - some-one zeroed it out ....
 
Old 06-20-2005, 05:28 PM   #8
Not now, John!
Member
 
Registered: Jul 2004
Distribution: LFS 5.1
Posts: 161

Rep: Reputation: 30
If nothing helps you can use testdisk utility from www.cgsecurity.org .
This tool searches the disk for partitions and adds them to the partition table.
 
  


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 Backup MBR? LinuxGeek Linux - Software 7 06-16-2005 03:54 PM
by tring to fix the MBR i damage the MBR that was help... AKAKAK Fedora 4 03-21-2005 08:18 AM
How to backup & restore the MBR in linux? sgzlit Linux - Newbie 7 03-02-2005 09:07 PM
GRUB MBR overwritten by WIN98 MBR TOuseef Linux - General 7 11-14-2004 04:25 PM
backup MBR and FIXMBR leessusan Linux - Laptop and Netbook 2 09-23-2004 01:31 AM


All times are GMT -5. The time now is 10:00 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