Partition Boot Record bootstrap code

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Mulligun
Posts: 1
Joined: Tue May 09, 2017 2:51 am

Partition Boot Record bootstrap code

Post by Mulligun »

I've read in many sources that Partition Boot Record/Record is written upon formatting a disk partition and contains machine code for bootstrapping specific OS. My question is how a formatting tool like DOS format command can write specific OS bootstrap while it only formats not installs specific OS?
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Partition Boot Record bootstrap code

Post by dozniak »

MBR only contains code to locate a bootable partition and load a bootsector from it. Your specific OS bootloader is located in that partition and does the rest of the job.
Learn to read.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Partition Boot Record bootstrap code

Post by iansjack »

So what happens when grub is installed in the MBR? It has no problem loading an OS kernel located in one of the partitions.

To answer the OP - the DOS format command has the ability to copy the boot code and files for DOS as well as just formatting the disk. But it can't make another OS bootable.
mallard
Member
Member
Posts: 280
Joined: Tue May 13, 2014 3:02 am
Location: Private, UK

Re: Partition Boot Record bootstrap code

Post by mallard »

The "FORMAT /S" MS-DOS command you're talking about doesn't write to the MBR. It writes to the partition's boot record and installs the absolute minimal files that MS-DOS needs to run (IO.SYS, MSDOS.SYS and COMMAND.COM). It does install a minimal version of "the specific OS".

To write the MBR for booting DOS, you'd use "FDISK /MBR" (or just create the partition table in FDISK on a completely blank disk). You can also install the minimal files without formatting using the "SYS" command.

When MS-DOS boots (from a hard drive), the MBR code checks the partition table for a bootable partition. It then transfers control to that partition's boot record, which then loads the aforementioned files. Both of these are about as primitive as it's possible to be; it's even required that IO.SYS be the first file on the partition and not be fragmented. MS-DOS's MBR can (and fairly commonly was, back when DOS was still relevant) be used to boot OSs other than MS-DOS; it's too primitive to care what it's actually loading, as long as it comes from the boot record of a "bootable" partition.

GRUB is a much more advanced bootloader. It's able to read the partition table, understand the filesystem within, load configuration, display a menu and load multiple different kinds of kernel (all this depends on the modules it's been configured with). As a result, it's much larger than the DOS MBR, but thankfully on modern(ish) systems there's (usually) a nearly 1MB "gap" between the MBR/partition table and the first actual partition and this is where GRUB puts most of its code. GRUB's MBR just transfers control to the code in the "gap".
Image
Post Reply