Page 1 of 1

MBR and bootsector

Posted: Tue Dec 25, 2007 3:28 pm
by someprogr
Can someone explain the difference between the MBR and the bootsector? Is it the same thing? If not, how would I go about accessing the MBR for reading and writing?

Posted: Tue Dec 25, 2007 5:07 pm
by Combuster
The MBR is the first sector on the disk.

The bootsector is the first sector of a disk or partition

Posted: Wed Dec 26, 2007 7:30 pm
by bewing
MBRs only apply to hard disks / disks with partitions. An MBR has 436 bytes of code that is used to boot a bootsector. It also contains the partition table, and a little extra stuff. It is LBA 0 on any hard disk. MBRs are not OS specific -- they are meant to boot whatever is marked as "bootable" in the partition table.

A bootsector, as Combuster says, is the first sector (or first few sectors) of a disk that does not have partitions (ie. NON-hard disks, like floppies) -- or the first few sectors of a particular partition on a hard disk. A bootsector is OS specific. Its purpose is to begin to load the kernel (perhaps by going through a second stage bootloader).

Posted: Thu Dec 27, 2007 4:17 am
by Ready4Dis
Yeah, I wrote my own MBR so I can boot multiple partitions easily, it's 512 bytes (including partition table and boot signature), and allows me to chose a partition to load (times out after a predetermined time period, and selects the default). How it works is, it copies itself to 7c00 + 512 (to make room for the boot sector), then it loads the boot sector to 7c00 (the first sector of whatever partition was chosen), re-writes itself using whichever partition was chosen (sets the correct active flag so windows doesn't cry), and jumps to the boot sector. I multi boot win xp, dos and my os witout issues.