MBR vs Boot Record

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
Dhaann
Posts: 19
Joined: Fri Dec 19, 2008 1:37 pm

MBR vs Boot Record

Post by Dhaann »

Hello everybody,
I've written a boot record that works. But I want to write a MBR (Master Boot Record).
What's the difference between them? And I wondered how to write a boot record (or mbr) to a hard drive.

Thanks!
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: MBR vs Boot Record

Post by Troy Martin »

The MBR is sector 0 of a hard drive, but it has 64 bytes somewhere in it to describe the partitions of the drive, see wikipedia: http://en.wikipedia.org/wiki/Master_boot_record
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: MBR vs Boot Record

Post by Love4Boobies »

Dhaann wrote:Hello everybody,
I've written a boot record that works. But I want to write a MBR (Master Boot Record).
What's the difference between them? And I wondered how to write a boot record (or mbr) to a hard drive.

Thanks!
In your case, they are probably one and the same thing. However, you might one to read on the GPT, which is (U)EFI's way of describing partitions.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
quok
Member
Member
Posts: 490
Joined: Wed Oct 18, 2006 10:43 pm
Location: Kansas City, KS, USA

Re: MBR vs Boot Record

Post by quok »

Love4Boobies wrote:
Dhaann wrote:Hello everybody,
I've written a boot record that works. But I want to write a MBR (Master Boot Record).
What's the difference between them? And I wondered how to write a boot record (or mbr) to a hard drive.

Thanks!
In your case, they are probably one and the same thing. However, you might one to read on the GPT, which is (U)EFI's way of describing partitions.
GPT partitioning schemes are, in my opinion, much nicer than the old MBR scheme. Booting from them on a BIOS based system however, isn't entirely supported by BIOS systems. It's certainly possible (GRUB 2 can do it), but many of the solutions out there that accomplish such a thing are gross hacks that hark back to the days of MBR and hiding data in the sectors between partitions. According to the GPT spec (inside the UEFI 2.1 spec, see section 5), such spaces between partitions aren't needed, but some vendors (Apple, for instance) create them anyway. According to Apple Tech Note TN2166, this space is 128MB on Apple systems!

Back to booting a BIOS system from a GPT partition, I believe the UEFI spec does contain a solution for this (which nobody happens to then follow). MBRs are still there, of course, and you can nest MBR partitions inside GPT partitions, but I don't remember that part of the spec very well.

The UEFI spec is freely available from the UEFI website, although IIRC you'll have to sign up for a free account.
Last edited by quok on Thu Jan 22, 2009 10:57 am, edited 1 time in total.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: MBR vs Boot Record

Post by Love4Boobies »

I forgot to mention this, but there's also the notion of EBR (Extended Boot Record). On legacy MBR systems, multiple EBR can coexist in the system to define your extended partitions. Normally, only 4 partitions fit in the MBR - these are called primary partitions. After that, the MBR has to point to an EBR (which pretty much has the same partition table format but the last two entries are not used) which defines an extended partition and a link to the next EBR, if any. Think of this as a chain of extended partitions.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
abachler
Member
Member
Posts: 33
Joined: Thu Jan 15, 2009 2:21 pm

Re: MBR vs Boot Record

Post by abachler »

The MBR's job is to load the boot record of the active partition and execute it. Additionally, for compatibility reasons, the MBR should move itself to 0x0600:0x0000 and load the partition boot code to 0x07c0:0x0000
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: MBR vs Boot Record

Post by Love4Boobies »

That's not due to compatibility reasons. It's called chainloading and it doesn't really matter where you do it. 0600H is where Microsoft does it. 0500H is where my first stage boot loader (MBR) does it - that's the first spot of free memory, right after the IVT and the BDA. The reason for doing this is so that you can load the boot sector (not boot record) at 0000:7C00H; you wouldn't like to read over already execution code, would you?

EDIT: Oh, and btw - Microsoft does it at 0000:0600H, not 0600:0000H.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
Post Reply