Saving and Restoring an MBR

0 views
Skip to first unread message

Randy Cooper

unread,
Aug 12, 2000, 3:00:00 AM8/12/00
to
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
MBR
W 9000:00 <= Write the sector stored at address 9000 to
MBR.DAT
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
DEBUG.EXE

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
you
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
XOR BX,BX
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
Mark
Minasi, published by Sybex.

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

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.

DISCLAIMER:
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
know.

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.


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
MBR
W 9000:00 <= Write the sector stored at address 9000 to
MBR.DAT
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
DEBUG.EXE

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
you
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
XOR BX,BX
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 Mark
Minasi,
published by Sybex.

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

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.

DISCLAIMER:
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
know.

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.


--
Reply to: rwco...@mb.sympatico.ca (mail checked week nights and weekends)


Bob Side

unread,
Aug 13, 2000, 3:00:00 AM8/13/00
to
On Sat, 12 Aug 2000 13:39:47 -0500, Randy Cooper <rwco...@mb.sympatico.ca>
blurted:

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

Very useful. I could have done with this two weeks ago. Live & learn.
--
Bob Side
The future is the key to our past

Torstein Pettersen

unread,
Aug 13, 2000, 3:00:00 AM8/13/00
to
It's much simpler to just boot with a win9x startup disk
and type: fdisk /MBR.

The /MBR parameter for fdisk undocumented, but it works.
(/MBR stands for Master Boot Restore).

Torstein

"Randy Cooper" <rwco...@mb.sympatico.ca> wrote in message
news:399599F3...@mb.sympatico.ca...

Randy Cooper

unread,
Aug 13, 2000, 3:00:00 AM8/13/00
to
That will only work if you want a generic DOS MBR. What if you want to recover
the MBR after Linux has been installed and overwritten the MBR to use with
LILO?

John Hasler

unread,
Aug 13, 2000, 3:00:00 AM8/13/00
to
Randy Cooper writes:
> That will only work if you want a generic DOS MBR. What if you want to
> recover the MBR after Linux has been installed and overwritten the MBR to
> use with LILO?

'lilo -u' of course. man lilo.
--
John Hasler
jo...@dhh.gt.org (John Hasler)
Dancing Horse Hill
Elmwood, WI

Villy Kruse

unread,
Aug 14, 2000, 3:00:00 AM8/14/00
to
On Sun, 13 Aug 2000 18:46:58 GMT, John Hasler <jo...@dhh.gt.org> wrote:
>Randy Cooper writes:
>> That will only work if you want a generic DOS MBR. What if you want to
>> recover the MBR after Linux has been installed and overwritten the MBR to
>> use with LILO?
>
>'lilo -u' of course. man lilo.


The backup files are named /boot/boot.0300 where the 03 is the major
device number, ie. ide disk; and 00 is the minor disk, ie. /dev/hda

brw-rw---- 1 root disk 3, 0 May 5 1998 /dev/hda
^^^ ^^^
major minor

For /dev/hda1 the save file would be /boot/boot.0301 and
for /dev/hda2 the save file would be /boot/boot.0302
and so on.

This file will be created only if it does not already exists, which
means that you won't loose it if you re-run lilo.

Villy

Reply all
Reply to author
Forward
0 new messages