Difference between revisions of "Mbr"
m (Added a link to article Master_Boot_Record) |
(Wiki formatting. Minor re-wording. Add internal links. Minor correction.) |
||
Line 1: | Line 1: | ||
== MBR (Master Boot Record) == | == MBR (Master Boot Record) == | ||
− | The task of | + | The task of the MBR ([[Master Boot Record]]) is |
+ | to load boot code from an active partition of a drive. | ||
− | Syslinux | + | Syslinux is distributed with several variants of mbr code. |
− | each in 3 different flavours | + | These are <tt>mbr.bin</tt>, <tt>altmbr.bin</tt> and <tt>gptmbr.bin</tt>, |
+ | each in 3 different flavours: regular, | ||
+ | and with suffixes <tt>_c</tt> and <tt>_f</tt>. | ||
− | + | <tt>mbr.bin</tt> is a regular boot code for msdos-like partition tables. | |
− | + | <tt>altmbr.bin</tt> is also for msdos-style partition tables, | |
+ | but it boots from a partition with a given fixed number, | ||
+ | ignoring the "boot" flag -- see below. | ||
− | + | <tt>gptmbr.bin</tt> is a boot code that can be used on a drive with a GPT | |
+ | partition scheme. | ||
− | The different flavours | + | The different flavours differ in the way they determine boot drive. |
− | The regular code uses information about boot drive from the BIOS (passed in DL register) | + | The regular code uses information about the boot drive from the |
+ | BIOS (passed in the DL register). | ||
− | In | + | In some cases, this information may be somehow broken or incorrect, |
+ | and for such cases (among others) there are "flavours" available. | ||
− | The | + | The <tt>_c</tt> flavour checks if the <code>Ctrl</code> key is held |
+ | during boot, and, if it is, | ||
+ | then the code boots from BIOS drive {{nowrap|0x80}}, | ||
+ | otherwise it uses the regular way. | ||
+ | |||
+ | The <tt>_f</tt> 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 <tt>altmbr.bin</tt> variant are only 439 | ||
+ | bytes long; one extra byte should be set to | ||
+ | the partition number to boot from. | ||
== Write == | == Write == | ||
− | 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: | + | 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 | 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). | + | 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: | + | An easy way to set the desired boot partition to "1" with <tt>altmbr.bin</tt> is: |
printf '\1' | cat altmbr.bin - | dd bs=440 count=1 iflag=fullblock conv=notrunc of=/dev/sda | printf '\1' | cat altmbr.bin - | dd bs=440 count=1 iflag=fullblock conv=notrunc of=/dev/sda | ||
Line 33: | Line 62: | ||
printf '\027' | printf '\027' | ||
printf '\x17' | printf '\x17' | ||
+ | <!-- --> | ||
+ | <small>About printf: <!-- (in Linux shell)... --> | ||
+ | * The "hex" syntax format is preferred. | ||
+ | * Reminder: do _not_ use leading zeros: | ||
+ | printf '\x9' is <font color=green>OK</font> | ||
+ | printf '\x09' is <font color=red>NOT</font> | ||
+ | </small> | ||
+ | <!-- --> |
Revision as of 17:42, 27 October 2018
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.
Write
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'
About printf:
- The "hex" syntax format is preferred.
- Reminder: do _not_ use leading zeros:
printf '\x9' is OK printf '\x09' is NOT