MBR and bootsector
MBR and bootsector
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?
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).
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).
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.