APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Best of CUSM: linux save restore mbr master boot record lilo

With so many easily availible bootable rescue cd's today, I can't imagine this is of much value, but I leave it here just in case and perhaps as a reminder of the things we had to do way back when..

Message-ID: <399599F3.EE06B673@mb.sympatico.ca> 
From: Randy Cooper <rwcooper@mb.sympatico.ca>
Newsgroups: comp.os.linux.setup,comp.os.linux.misc
Subject: Saving and Restoring an MBR
Date: Sat, 12 Aug 2000 13:39:47 -0500

I have noticed a lot of questions regarding recovering lost / damaged
Master Boot Records (MBR) lately. So I thought it was about time to
repost this.

You should make a backup copy of your MBR on a bootable floppy disk
before installing Linux and then again after installing Linux.


I can suggest two ways that you can back up the Master Boot Record (MBR)

on an IDE drive under Windows and DOS.

1. Use the Norton Utilities.

2. Use Debug, as found in DOS, it is also available from the DOS prompt
   in Windows/95 so I assume it is also available in Windows/98.

   Enter the following commands to save the MBR on the C drive, ignore
   the text after the '<=' on each line as it is only a comment:

   DEBUG MBR.DAT       <= Ignore the FILE NOT FOUND message
   A                   <= Assemble a program
   MOV DX,9000         <= Use segment 9000
   MOV ES,DX           <= Setup the segment register
   XOR BX,BX           <= Clear BX to zero
   MOV CX,0001         <= Start at track 00 sector 01, the MBR
   MOV DX,0080         <= 80=C:, 81=D:, 00=A:, 01=B:
   MOV AX,0201         <= Read 1 sector, 02=read
   INT 13              <= BIOS disk i/o call
   INT 20              <= Return to o/s
                       <= Press the return key to end program entry
   G                   <= Execute the program
   R CX                <= Display the value of CX
   :200                <= Change the value of CX to decimal 512, size of
   W 9000:00           <= Write the sector stored at address 9000 to
   Q                   <= exit DEBUG

If you examine the contents of MBR.DAT using a disk file editor the last

2 bytes must be AA55.

At this point you should copy the MBR to a bootable floppy along with

This technique may be used to recover the MBR as well, assuming you can
boot from another device (say a floppy with DEBUG.EXE on it).

Enter the following commands to restore the MBR on the C drive, ignore
the text after the '<=' on each line as it is only a comment:

  DEBUG MBR.DAT        <= The file containing the desired MBR, if you
get a
                          FILE NOT FOUND message type Q immediately! If
                          continue you will write garbage over the MBR.
  L 9000:00            <= Load the MBR into memory at this address
  A                    <= Assemble a program
  MOV DX,9000        <= The segment address containing the MBR
  MOV ES,DX            <= Setup the segment address
  MOV CX,0001          <= Track 00, sector 01
  MOV DX,0080          <= 80=C:
  MOV AX,0301          <= Write one sector, 03=write
  INT 13
  INT 20
                       <= Press the enter key to stop program entry
  G                    <= Execute the program
  Q                    <= Exit DEBUG

The MBR should now be restored to the C drive, making it bootable.

For more information on this technique for saving and restoring an MBR I

refer you the book 'The Complete PC Upgrade and Maintenance Guide' by
Minasi, published by Sybex.

Once you have Linux running you can save the boot record with the

  dd if=/dev/hda of=/boot/boot.MBR bs=512 count=1

It can then be restored with:

  dd if=/boot/boot.MBR of=/dev/hda bs=512 count=1

or if you do not want/need to overwrite the partition table with:

  dd if=/boot/boot.MBR of=/dev/hda bs=446 count=1

as the partition table is kept in the last 66 bytes of the MBR.

  Although I have double checked the above, I cannot be held responsible 
  for any errors. I suggest you try it on a bootable floppy disk before
  using it on a hard drive. If it does not work on a floppy disk let me

BTW: I find it easier to boot Linux from a floppy disk or
CD-ROM than to recover an MBR from DOS. The Slackware 3.5
(or greater) CD-ROM makes a good rescue disk if you have
a bios that supports bootable CDs.

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> linux save restore mbr master boot record lilo ––>Saving and Restoring an MBR

Increase ad revenue 50-250% with Ezoic

Kerio Samepage

Have you tried Searching this site?

Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

Dump may work fine for you a thousand times. But it _will_ fail under the right circumstances. And there is nothing you can do about it. (Linus Torvalds)

This post tagged: