Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora Resources > Guides & Solutions (No Questions)
FedoraForum Search

Forgot Password? Join Us!

Guides & Solutions (No Questions) Post your guides here (No links to Blogs accepted). You can also append your comments/questions to a guide, but don't start a new thread to ask a question. Use another forum for that.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 16th October 2011, 05:45 PM
plasmonics Online
Registered User
 
Join Date: Feb 2009
Posts: 60
linuxfirefox
How to backup and reset the master boot record and partition table of a drive

Recently, while trying to make a USB stick bootable, I inadvertently trashed both the stick and the MBR of my internal hard drive. Luckily, I was able to boot back into Fedora using the DVD in rescue mode. There was a problem with the stick that was causing it not to automount correctly. The MBR needed to be reset to factory and the partition table rebuilt.

Normally, to reset an MBR to factory, you would run fdisk /mbr off a MSDOS boot floppy, or fixmbr off a Windows boot CD. However, many laptops don't have a floppy and are sold with only a Windows restore CD. Besides, if you create a problem within Linux, you should be able to fix it within Linux.

The following Howto contains some simple commands to backup and reset the MBR and partition table of a drive. It should work for internal drives, USB stick, micro SD, floppy, etc. It is assumed that the device file associated with the drive is /dev/sdc. Yours will vary. All commands are executed as root.

If the drive is mounted, unmount it using
Code:
$ umount /dev/sdc
Obviously, this is not possible if this is the drive from which you are booting Linux. Not a big problem, as you can boot a rescue CD.

Backup up an MBR using
Code:
$ dd if=/dev/sdc of=mbr.bin bs=512 count=1
Restore the MBR with
Code:
$ dd if=mbr.bin of=/dev/sdc bs=512 count=1
To back up just the partition table instead of the whole MBR, run
Code:
$ dd if=/dev/sdc of=part.bin bs=1 skip=446 count=64
Restore the partition table with
Code:
$ dd if=part.bin of=/dev/sdc bs=1 seek=446 count=64
If you had previously backed up the entire MBR and just wanted to replace the partition table, the syntax is
Code:
$ dd if=mbr.bin of=/dev/sdc bs=1 skip=446 seek=446 count=64
To clean out the MBR, for example, to remove GRUB, LILO, Syslinux, etc., and restore it to factory, erase the executable part of the MBR with
Code:
$ dd if=/dev/zero of=/dev/sdc bs=446 count=1
If for some reason, the partition table is corrupted, zero it with
Code:
$ dd if=/dev/zero of=/dev/sdc bs=1 seek=446 count=64
Of course, this will render any existing data on the drive unreadable. Use /sbin/fdisk to remake the partition table. To avoid losing data, remake the partition(s) the same size as the original with the same starting and ending cylinders.
Reply With Quote
  #2  
Old 16th October 2011, 06:08 PM
DBelton's Avatar
DBelton Offline
Administrator
 
Join Date: Aug 2009
Posts: 6,612
linuxfirefox
Re: How to backup and reset the master boot record and partition table of a drive

testdisk (if advanced is selected from the menu) can test and rebuild the bootsector in linux. It can also check and rebuild MBR or GUID partition tables and recover from a completely wiped out MBR/GUID by searching the drive for partitions and then recreating the partition table from what it finds on the drive.

It's in the Fedora repos..

Code:
yum install testdisk
But, the reasoning as to fixing the problem where you caused the problem isn't always correct.

If the drive is a windows drive, with windows partitions, you are much better off fixing it in windows, even if there are linux utilities to do it with. And vice versa.. If its a linux drive with linux partitions, you are better off fixing it in linux.

Last edited by DBelton; 16th October 2011 at 06:10 PM.
Reply With Quote
Reply

Tags
backup, boot, drive, master, partition, record, reset, table

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Master Boot Record damage Hagis Using Fedora 0 25th June 2011 02:54 AM
Rebuilding the Grub Boot Loader on Master Boot Record (MBR) w Fedora Linux Vector Guides & Solutions (No Questions) 6 1st August 2009 08:39 AM
can't get GRUB into Master Boot Record OSBORNE1934 Installation and Live Media 2 6th November 2006 08:55 PM
XP Dual boot trouble CHS Partition table:Rebuilding Partition table ILovetux Using Fedora 0 15th May 2006 08:47 PM
Help with Master Boot Record NCortes Using Fedora 6 27th June 2005 05:25 AM


Current GMT-time: 02:13 (Sunday, 26-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat