Skip to content

Instantly share code, notes, and snippets.

@coder36
Last active August 29, 2015 13:59
Show Gist options
  • Save coder36/10986249 to your computer and use it in GitHub Desktop.
Save coder36/10986249 to your computer and use it in GitHub Desktop.
Baking up an MBR

Baking up an MBR

guide

The MBR is stored in the the first 512 bytes of the disk. It consist of 3 parts:

|-----------------------446 bytes bootloader--------------------|------64 bytes partition table-------|-id-|

  1. The first 446 bytes contain the boot loader.

  2. The next 64 bytes contain the partition table (4 entries of 16 bytes each, one entry for each primary partition).

  3. The last 2 bytes contain an identifier

       # backup MBR
       dd if=/dev/sda of=/img/sda-mbr.img bs=512 count=1
       #restore
       dd if=/img/sda-mbr.img of=/dev/sda bs=512 count=1
    
       # backup partition table
       dd if=/dev/sda of=/img/sda-part.img seek=446 skip=446 bs=64 count=1
       dd if=/img/sda-part.img of=/dev/sda/ seek=446 skip=446 bs=64 count=1
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment