| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.

View
 

How to backup and restore your MBR

Page history last edited by PBworks 13 years, 2 months ago

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:

 

    • Your computer no longer boots to the lilo boot manager
    • You recently installed an operating system and you can no longer boot to Xandros (or Windows, or whatever)
    • A partition has inexplicably disappeared
    • The installation of some other Linux distro has overwritten your lilo boot manager
    • You receive strange, repeating alpha-numeric codes at boot (e.g., L99 99 99 99 99)

      (This is when you can zero-out the MBR and restore it with a backup that you made when you first set up your system)

    • Lilo is just "hosed"

 

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:

 

  • hda is the primary hard disk drive
  • hda1 is the swap partition
  • hda2 is / (root)

 

  • The MBR is installed on hda

 

  • Installed operating system is Xandros 4

    (These instructions were tested and written on a Xandros 4 system)

 

 

Requirements:

 

  • Xandros 3 or 4 install CD-ROM  (or a Knoppix or SLAX Kill Bill liveCD)

 

  • You need to be familiar with your hard disk drives, the partition names/numbers, and the EXACT location of your MBR (/dev/hda, /dev/hdb, /dev/sda, etc.). 

 

 

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...

 

 

Comments (1)

Anonymous said

at 2:56 pm on May 15, 2007

Version 1 of this How-to is now complete.

You don't have permission to comment on this page.