Jump to content
pmpatrick

Backing up and Restoring the MBR

Recommended Posts

If you play around with paritioning tools, installing linux disros, or writing bootloaders to the mbr long enough, sooner or later you will corrupt your partition table in the MBR. Then you have real problems trying to restore a corrupted partition table. With a little forsight and linux you can avoid those problems by making a backup of your mbr which you can restore if everything goes bad.

 

It's relatively easy to do using the dd command. To backup the mbr to a floppy just run:

 

# dd if=/dev/hdx of=/dev/fd0 bs=512 count=1

 

where 'x' is your boot hard drive, i.e. the one where your mbr is located.

 

The mbr is on the first sector of your hard drive which is 512 bytes. The above command merely copies the first 512 bytes on sector 1 to a floppy.

 

To restore the mbr from the floppy backup, boot off a rescue cd like knoppix, open a console and get root privileges, then run:

 

# dd if=/dev/fd0 of=/dev/hdx bs=512 count=1

 

If you don't have a floppy drive, you can backup the mbr to a file on your hard drive and copy the file to a cd-r if you have a cd burner. To backup to your hard drive run:

 

# dd if=/dev/hdx of=mbr.bak bs=512 count=1

 

This will create a file mbr.bak in your current working directory. Obviously, if your partition table is trashed, you will never be able to access that file on your hard drive so you need to place it on some removable medium. Just create a data cd and copy mbr.bak to the cd-r with your favorite cd burning program.

 

Restoring from a cd-r backup is essentiall the same except you have to mount the cd-r and run:

 

# dd if=<cd drive mount point/mbr.bak> of=/dev/hdx bs =512 count=1

 

Note, if you have resized or altered any of the existing partitions since you backed up this problably won't work. If you just created some new partitions physically located on the hard drive after your existing partitions, the mbr backup should leave the partition table in the same state it was in before you created the new partitions, i.e. the new partitions will be deleted and the prior working partition table with the old partitions should be restrored.

Share this post


Link to post
Share on other sites

Just for those who don't have any experience and didn't realise that they should/could have done this, most harddrive manufacturers actually have tools for download that can restore a previous partition table.

 

I have had to use such a tool and got to choose any of the previous 10 (or was it 15) partition tables, indicated by date. If there ever was a good reason to make sure the bios has the date set correctly...

 

So, in case you didn't save your partition table, you can (sometimes/usually?) still restore the old one.

Share this post


Link to post
Share on other sites

My problem is I tried to set up a dual boot with Mandriva 2008 and XP and it turned out that Mandriva did not have the drivers to properly handle a SATA drive.(My Bad) :unsure:

I found a windows utility called "MbrFix.exe" but I have not used it before and am concerned about screwing his pc even more.

Has anyone tried this? How did you use it and what where the results? He does not have the restore cd, it's a Dell PC.

Linux Rulez!

Roly

Share this post


Link to post
Share on other sites
Guest PauLLiK

You can use Clonezilla, that way you can clone a whole partition and then restore it.

No losses.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...