Tags:
create new tag
, view all tags
Commands to back up the MBR (Master Boot Record)

dd if=/dev/hda of=backup-hda.mbr count=1 bs=512

See AboutThesePages.

Contents

Backing Up Only the Boot Loader

As mentioned in Master Boot Record, the MBR includes both a boot loader and the partition table for the disk. There are times when you want to backup and restore the boot loader without destroying the partition table.

One way is by mounting the disk temporarily (as hda, IIUC), then running lilo in a chroot jail on that temporary mount. More notes on this are at DdCloningScript and Parted (and should eventually be moved here as those pages are refactored).

Another approach would be to use dd to copy just the portion of the MBR containing the boot loader. This has been tried recently assuming the boot loader was 446 or 496 bytes and did not work. Now collecting resources to try to pinpoint the size of the boot loader:

  • FDISK /MBR; Doug Muth; viewed 3 Mar 2003 -- this might be the answer, it describes the MBR as including:
    • Boot Loader (446 bytes)
    • Partition Table (64 Bytes)
    • Signature bytes (2 bytes)

Which means we'd need to dd 446 bytes. (This page also talks about how viruses infect the MBR). From further below, maybe we need to specify the bs as 445 to copy 446 bytes? (but that doesn't make sense -- we might have to set the count to 445 instead of 446 if the count starts at zero instead of one, but that doesn't make sense either. Oh, well, since 446 doesn't seem to work, I'll try 445 once.

  • The Partition Table, MBR and Drive Overlays; viewed 3 Mar 2003 -- "The very first sector of any HD (cylinder 0, head 0, sector 1 for CHS, sector 0 for LBA, see drive access methods) contains the Master Boot Record." -- Hmm, does that mean we have to know whether we're using CHS or LBA and change the dd accordingly? And, can dd get something from sector 1 and copy it to sector 0 or vice versa? maybe -- see the dd man page -- seek and skip may help accomplish this (haven't read carefully yet) This site has some other useful pages, more Windows oriented -- one of them point out that the LBA method of addressing is limited to about 9,000,000,000,000 GB (so, can I predict when it will be too small??)._ But, after further thought, I don't think this difference is a real physical difference but instead a difference in terminology -- i.e., in CHS the first physical sector is addressed as 0,0,1, in LBA it is addressed as 0,0,0, but they both refer to the same physical location, and dd doesn't care whether it is CHS or LBA addressing (I don't think) -- it just starts from the first physical sector.

_Aside: (Less far than the end of the previous entry wink -- DD and Computer Forensics: Examples of Using DD within UNIX to Create Physical Backups; Thomas Rude, CISSP; August 2000 -- gives a better (easier to understand) description of some of the dd options:

ibs = input block size
obs = output block size
count = number of blocks to copy
skip = number of blocks to skip at start of input
seek = number of blocks to skip at start of output
conv = conversion

  • Master Boot Record, with application to ETH Oberon -- clarifies that the signature is at the end (and gives addresses), also specifies that layout of the partition table (I didn't read carefully -- is that only for Oberon (what is Oberson) or is that for any PC?) (From the first reference above, I inferred that the signature was the first two bytes -- now changed it above.)

An MBR is located in the first sector (Cylinder 0, Head 0, Sector 1) of a hard disk and it has the structure:

Offset Bytes  Meaning 
in hex.
0000    446   Boot Loader code 
01BE     16   1. partition entry 
01CE     16   2. partition entry 
01DE     16   3. partition entry 
01EE     16   4. partition entry 
01FE      2   Signature (55H AAH)

  • Partition is deleted or Partition Table is damaged, ©2002 -- error messages due to various partition table faults (move this resource to another page) -- also mentions OS independence of the MBR (presumably within a given architecture, like "Intel" (or "8086 based")

  • Tools and References for the MBR and OS Boot Records; some possibly useful tools, at first glance they seem to all be written for dos / Windows, but some work for Linux partitions -- from the page I get a glimmer of an inference that the first 64 or 128 sectors of a disk may be expendable without destroying the "real" OS. (His "free ZAP63 utility (zeros-out the first 63 sectors of any hard drive)".)

Hmm, an alternate strategy could be to copy the good partition table (only -- 64 or 66 bytes) to a file, overwrite the entire MBR from the clone master image, then restore the partition table from the file -- although I don't see how that does anything different than just the originally envisioned 446 byte dd.

  • 4. Boot Loaders 4.1 Concepts -- looks like a pretty good page to explain LILO, its lilo.conf file, and primary (IPL) and secondary (LILO, GRUB, etc.) boot loaders -- not read yet -- also covers GRUB in a similar fashion

Contributors

  • () RandyKramer - 28 Jun 2002
  • <If you edit this page: add your name here; move this to the next line; and include your comment marker (initials), if you have created one, in parenthesis before your WikiName.>

[[Main.RandyKramer#28 Jun 2002][]]

Page Ratings

Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2003-03-03 - RandyKramer
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by PerlCopyright 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding WikiLearn? WebBottomBar">Send feedback
See TWiki's New Look