From Syslinux Wiki
Revision as of 01:23, 17 May 2011 by GeneC (talk | contribs) (Write: altmbr method)

Jump to: navigation, search

MBR (Master Boot Record)

The task of MBR (Master Boot Record) is to load boot code from an active partition of a drive.

Syslinux distribution comes with several versions of mbr code. These are mbr.bin, altmbr.bin and gptmbr.bin, each in 3 different flavours, -- regular, and with suffixes _c and _f.

mbr.bin is a regular boot code for msdos-like partition table.

altmbr.bin is also for msdos-style partition table, but it boots from a partition with fixed number, see below.

gptmbr.bin is a boot code that can be used on a drive with GPT partition table.

The different flavours differs in the way how they determine boot drive. The regular code uses information about boot drive from the BIOS (passed in DL register). In some cases, this information may be somehow broken or incorrect, and for this case there's _c version, which checks if Ctrl key is held during boot and if it is, the code boots from BIOS drive 0x80, or else it uses regular way. And the _f version which always boots from BIOS drive 0x80.

In all cases the mbr code is 440 bytes long and can be written into start of a drive (with appropriate partition table) to make it bootable. MS-DOS style partition table is located in the first sector of the drive as well, right _after_ the mbr code (starting with 440 byte).

The altmbr.bin (all 3 variants) is only 439 bytes long, -- one extra byte should be set to the number of partition to boot from.


Some people may recommend redirecting cat's output directly to the disk however this method carries a lot of danger and potentially dire consequences (data loss). A safe approach is:

 dd bs=440 count=1 conv=notrunc if=mbr/mbr.bin of=/dev/sda

This sets the input and output transfer block to 440 bytes, 1 block, and prevents the output from truncating the file (if the output is not a block device, like an image file).

An easy way to set the desired boot partition with altmbr.bin is:

 printf '\1' | cat altmbr.bin - | dd bs=440 count=1 conv=notrunc of=/dev/sda