How to backup and restore your MBR


How to:  Backup and restore your master boot record

 

NOTE:  Follow these instructions at your own risk.

 

 

Conditions that may indicate that your master boot record (MBR) needs to be restored:

 

 

You should (always) have a complete and separate backup of all the data and things that are important to you on your computer hard disk drive before you ever consider starting to tinker with something like this.  Copying your files to another partition on the same hard disk drive is not a backup!

 

These procedures have been used countless times on Linux and Windows systems with 100% success. Your mileage may vary.

 

Sometimes the things that we think are the problems are only symptoms of something else, so be certain.  

 

 

These procedures are predicated upon the following basic assumptions:

 

 

 

 

 

Requirements:

 

 

 

 

Background information:

 

The master boot record (MBR) is the first physical 512 bytes of your active hard disk drive (your boot drive).

 

The first 446 bytes of the MBR are the boot code (sometimes called the boot sector).

 

The remaining 66 bytes (beyond the first 446 bytes) contain your hard disk drive's partition

table. Any unintentional writing to the partition table will destroy your data. It

really, really will totally annihilate your data.

 

The number 446 is important beyond any words that I can type here. If you overwrite your partition table, your data is gone unless you have some very specialized tools and expertise at your disposal.  The point here is to learn how to create a backup of your MBR and then restore only the parts that need restoring.  Most typically that is the boot code/boot sector, or the first 446 bytes of your MBR.

 

 

We use the /dev/shm folder because it is readable AND writable.  The fact that it is writable allows us to create a mount-point for the root partition on our hard disk drive.  We could also mount and use a floppy disk for the purpose of saving an MBR backup.

 

 

 

Backup your MBR...

 

Under normal conditions you can run dd as root from within a console window in a normal Xandros session.  When things aren't running so well, boot from your Xandros install disk, press the Spacebar for troubleshooting options. Select Rescue Console.

 

When you see the root@localhost:/ prompt

 

Code:  cd /dev/shm

Comment:  Changes the working directory to the /dev/shm folder

Code:  mkdir hdmnt

Comment:  Creates a mount-point called hdmnt

 

Code:  mount -t auto /dev/hda2 /dev/shm/hdmnt

Comment:  Mounts the partition /dev/hda2 to the /dev/shm/hdmnt mount-point

Code:  cd /dev/shm/hdmnt/home

Comment:  Changes the working directory to /home on your mounted hard disk partition

Code:  mkdir backups

Comment:  Creates a folder named "backups" in which you can save a copy of your MBR 

Code:  dd if=/dev/hda of=/dev/shm/hdmnt/home/backups/mbr_backup bs=512 count=1

Comment:  Copies the entire 512-byte MBR of /dev/hda to a file called mbr_backup, and does it only one time (count=1)

 

 

You should see:

 

1+0 records in

1+0 records out

512 bytes transferred in...

 

Now perform a directory listing to see if the file mbr_backup is present and 512 bytes in size.

 

Code:  ls

 

 

Remove/zero-out the boot code in your MBR (getting rid of Lilo or Grub)...

 

Before performing this you should already have an MBR backup. 

Boot from your Xandros install disk, press the Spacebar for troubleshooting options. Select Rescue Console.

 

When you see the root@localhost:/ prompt

 

Code:  cd /dev/shm

Comment:  Changes the working directory to the /dev/shm folder

Code:  mkdir hdmnt

Comment:  Creates a mount-point called hdmnt

 

Code:  mount -t auto /dev/hda2 /dev/shm/hdmnt

Comment:  Mounts the partition /dev/hda2 to the /dev/shm/hdmnt mount-point

Code:  ls /dev/shm/hdmnt/home/backups

Comment:  Lists the contents of the /dev/shm/hdmnt/home/backups folder...there should be only one file

 

 

You should see the file mbr_backup listed, and it should be 512 bytes

 

Now you can zero-out your MBR (triple-check everything you type)...

 

Code:  dd if=/dev/zero of=/dev/hda bs=446 count=1

Comment:  Overwrites the contents of the boot sector (the first 446 bytes) of the MBR with nothing (zero it out), but do only one time (count=1)

 

 

You should see:

 

1+0 records in

1+0 records out

446 bytes transferred in...

 

 

Restore your MBR from your backup...

 

Boot from your Xandros install disk, press the Spacebar for troubleshooting options. Select Rescue Console.

 

When you see the root@localhost:/ prompt

 

Code:  cd /dev/shm

Comment:  Change the working directory to the /dev/shm folder

Code:  mkdir hdmnt

Comment:  Creates a mount-point called hdmnt

 

Code:  mount -t auto /dev/hda2 /dev/shm/hdmnt

Comment:  Mounts the partition /dev/hda2 to the /dev/shm/hdmnt mount-point

 

Code:  dd if=/dev/shm/hdmnt/home/backups/mbr_backup of=/dev/hda bs=446 count=1

Comment:  Copies the first 446 bytes (the boot code) of your MBR backup file to the boot sector of your MBR, and does it only one time (count=1)...this restores your boot sector to its original state at the time you made your MBR backup.

 

 

You should see:

 

1+0 records in

1+0 records out

446 bytes transferred in...