MBR (Master Boot Record)
The task of the MBR (Master Boot Record) is to load boot code from an active partition of a drive.
Syslinux is distributed with several variants 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 tables.
altmbr.bin is also for msdos-style partition tables, but it boots from a partition with a given fixed number, ignoring the "boot" flag -- see below.
gptmbr.bin is a boot code that can be used on a drive with a GPT partition scheme.
The different flavours differ in the way they determine boot drive. The regular code uses information about the boot drive from the BIOS (passed in the DL register).
In some cases, this information may be somehow broken or incorrect, and for such cases (among others) there are "flavours" available.
The _c flavour checks if the
Ctrl key is held
during boot, and, if it is,
then the code boots from BIOS drive 0x80,
otherwise it uses the regular way.
The _f flavour always boots from BIOS drive 0x80.
See also Isohybrid#MBR_selection.
In all cases, the mbr code is 440 bytes long and can be written into the start of a drive (with an appropriate partition table) to make it bootable. The msdos style partition table is located in the first sector of the drive as well, right _after_ the mbr code (starting with an offset of 446 bytes).
All 3 flavours of the altmbr.bin variant are only 439 bytes long; one extra byte should be set to the partition number 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 to "1" with altmbr.bin is:
printf '\1' | cat altmbr.bin - | dd bs=440 count=1 iflag=fullblock conv=notrunc of=/dev/sda
Setting it to 23 (17h, 27o) is as simple as these substitutions:
printf '\027' printf '\x17'
- The "hex" syntax format is preferred.
- Reminder: do _not_ use leading zeros:
printf '\x9' is OK printf '\x09' is NOT