Home

Awesome

MBiRa Boot Manager

What it is

This is a boot manager that can be installed in the first sector of an HDD (the sector is known as the Master Boot Record or MBR) that can automatically boot an OS (like MS-DOS, FreeDOS, Windows 9x/Me/2000/XP) from one of the four disk partitions or let the user intervene and manually choose which partition to boot from.

MBiRa implements most of what's known as "modern standard MBR" in Master boot record.

Why this? Why now, some 25 years too late? Well, it turns out, some are still using old technology and even my BootProg boot loader, which is also single-sector. In order to fix some bugs and limitations in BootProg and be able to test the changes quickly I needed something like MBiRa and so I wrote it (the one existing similar boot manager I'd tried before, mbrbm, hadn't quite cut it (no LBA support, no update of the active partition in the MBR, somewhat confusing UI)). It's also a fun coding exercise.

Features

Sample screen

When MBiRa starts, you can see something like this on the screen:

MBiRa
Hit #:
#  Type Size,MB
0   011 0007000
1   014 0002000
2 a 012 0010000
3   015 1888695
_

This shows a partition table for a 2TB disk that has four valid partitions, the third of them being active (that is, automatically bootable by default). The Type column lists the file system/partition IDs/types of these partitions and those correspond to a FAT32 with CHS addressing (11=0Bh), a FAT16 with LBA (14=0Eh), a FAT32 with LBA (12=0Ch) and an extended partition with LBA (15=0Fh) respectively.

With mbrtst.bin installed on the active partition shown above and booted on a test PC I get this additional output under the above partition table:

Geo CHS=01023,00255,00063=0016434495 sect

drv  dx   si   bp   cs   ds   es   ss   sp
0080 0080 11DE 11DE 0000 0000 0000 0000 7BEC

FS=00012 CHS=01023,00254,00063 LBA=0018434048 Sz,MB=0000010000
_

This shows that the BIOS boot drive is 80h (in the partition entry (under "drv") and the DL register), confirms the file system ID/type of 12 and the size of 10000MB.

The partition entry lists its start LBA (0018434048) and start CHS (01023,00254,00063). The start CHS is invalid because it's outside of the number of Cylinders, Heads and Sectors listed as the BIOS disk geometry shown at the top. Specifically, with 1023 cylinders reported by the BIOS, the valid cylinder numbers are 0 through 1022 while we got 1023. This situation is because the partition starts more than 8GB away from the HDD's start as can be seen from both the cumulative size of the preceding partitions (7000MB + 2000MB > approx. 8000MB) and the start LBA (18434048 > 16777215, the maximum 24-bit LBA value that the BIOS can accept in CHS-based reads). This partition will only boot when LBA is supported.

Requirements

There aren't that many requirements, probably.

You need an IBM PC-compatible computer with 64KB of RAM or better with an HDD (it can be a VM just as well), but "better" is limited. It can't be a modern PC that can only boot using (U)EFI. It'll have to have the Compatibility Support Module (CSM) in order to boot MBiRa.

The HDD where you intend to install MBiRa should have installed only OSes that can be booted by the MBR loading the first sector from the OS's HDD partition and transferring control there, that is, by very simple and standard MBRs. The following is a very incomplete list of such OSes: MS-DOS, FreeDOS, Windows 9x/Me/2000/XP. If there's a newer version of Windows (e.g. Vista, 7 through 11) or a Linux system that boots using GRUB, installing MBiRa there will break booting of those systems.

The HDD (specifically, its 1st sector, MBR) must not be write-protected or MBiRa won't boot any OS.

Compilation

You'll need NASM 2.10 or newer.

Then just

$ nasm mbira.asm -f bin -o mbira.bin

Installation and uninstallation

First, make sure you have mbira.bin compiled (see above).

FreeDOS

Here's how to install mbira.bin on the first HDD using FreeDOS 1.3...

First, save the existing MBR to the hdd1_old.mbr file:

> fdisk /SMBR 1
> copy boot.mbr hdd1_old.mbr

BACKUP THE hdd1_old.mbr FILE TO BE ABLE TO RESTORE THE ORIGINAL MBR!

Now install MBiRa as the new MBR on the first HDD:

> copy mbira.bin boot.mbr
> fdisk /AMBR 1

To uninstall MBiRa from the first HDD using the previously saved file hdd1_old.mbr:

> copy hdd1_old.mbr boot.mbr
> fdisk /AMBR 1

Linux

Here's how to install mbira.bin on /dev/sda using Linux...
(If needed, substitute /dev/hda and such)

First, save the existing MBR to the sda_old.mbr file:

$ sudo dd if=/dev/sda of=sda_old.mbr bs=1b count=1

BACKUP THE sda_old.mbr FILE TO BE ABLE TO RESTORE THE ORIGINAL MBR!

Now install MBiRa as the new MBR on /dev/sda:

$ sudo cp sda_old.mbr sda.mbr
$ sudo dd if=mbira.bin of=sda.mbr bs=1 count=440 conv=notrunc
$ sudo dd if=sda.mbr of=/dev/sda bs=1b count=1

Essentially, this overwrites the first 440 bytes of the MBR with the first 440 bytes of mbira.bin while keeping the last 72 bytes containing the partition table among a few other things.

To uninstall MBiRa from /dev/sda using the previously saved file sda_old.mbr:

$ sudo dd if=sda_old.mbr of=/dev/sda bs=1b count=1

Troubleshooting

Resources, links