May
21

How to back up and restore MBR?

By Alaa Qutaish  //  sysadmin  //  7 Comments

Backup and restore MBR (Master Boot Record).

What is MBR anyway ?
MBR is the first 512 byte boot sector of a partitioned data storage device “Hard Disk” and it is not located in a partition, it is located in the Main boot record in front of the first partition.
MBR contains the primary partition entries in its partition table.

What is it for?

  1. Holding storage primary partition table, with exact max four primary partition tables
  2. Bootstrapping the operating system after BIOS loads and executes the MBR
  3. Identifying uniquely disk media with 32-bit disk signature

MBR code expects and scans the list of primary partitions entries in its partition table to find one and only partition marked with “active” flag , and then it loads its VBR “Volume Boot Record”

It is possible to edit the code inside the MBR sector using “Disk Editors” like fdisk. So what fdisk does is manipulating MBR code.

what would happen if we deleted our MBR or messed up with its code?
Simply, we will not be able to locate our partitions anymore and it would be a blind hard disk that can not see its partitions.
That hurts isn`t it? So the solution for this is to back up the MBR so we will not be afraid if something wrong happened in it.

How to back up the MBR?
Back up command:
dd if=/dev/sda of=/home/alaa/Sonyvaio-MBR.bkp bs=512 count=1

How to restore the MBR?
If the MBR is damaged, then you will be not able to boot from your disk, right? , so you have to do the following steps:

1- Boot up from Live CD like “Ubuntu or Gentoo or whatever you like”
2- In the terminal window type:
mkdir tmp
3- You have to mount the partition where the MBR image is saved, for example we saved it in my home directory, so :
mount /dev/sda5 tmp
cd tmp/home/alaa
4- Finally we restore the MBR image with this command:
dd of=/dev/sda if=Sonyvaio-MBR.bkp  bs=512 count=1

7 Comments to “How to back up and restore MBR?”

  • It’s very important …useful
    Thanks Alaa

  • very pleased to hear that, and you are most welcome :-)
    i`ll be waiting for your blog posts too ;-)

  • 0pens0urce.com – da best. Keep it going!
    Have a nice day
    SonyaSunny

  • The best information i have found exactly here. Keep going Thank you

  • Hi, interest post. I’ll write you later about few questions!

  • Hi. I like the way you write. Will you post some more articles?

  • Sometimes it’s really that simple, isn’t it? I feel a little stupid for not thinking of this myself/earlier, though.

Leave a comment