MBR and bootsector

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
someprogr
Posts: 7
Joined: Mon Dec 24, 2007 12:44 pm

MBR and bootsector

Post 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?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

The MBR is the first sector on the disk.

The bootsector is the first sector of a disk or partition
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post 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).
Ready4Dis
Member
Member
Posts: 571
Joined: Sat Nov 18, 2006 9:11 am

Post 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.
Post Reply