Page 1 of 1
Hard Disk Boot Sector
Posted: Sun Apr 25, 2004 5:30 pm
by Sean
When creating a bootsector for a harddisk partition, what is the best way to detect what partition you're running from? For example, when your bootsector is loaded and called from the mbr, you can tell what disk you're in by the value of the dl register. But what about what partition you're on?
I'm trying to create a first stage bootloader to fit into the first two sectors of my partition. The file system header contains information on the second stage bootloader's location. I just need to find out which partition I'm on, so I can proceed with the second stage.
Any help would be appreciated. Thanks.
Re:Hard Disk Boot Sector
Posted: Mon Apr 26, 2004 1:49 am
by Pype.Clicker
well, you're on the partition you've installed your bootsector on
It make sense to have a register telling "this is drive #1 or #2" as you could decide to change your wires at any reboot ... But you will never change what partition you're running on. If you do (e.g. you're moving a filesystem to another partition with something like
dd if=/dev/hda1 of=/dev/hda2), then you should also fix your boot setup by re-writing a new up-to-date bootsector for that partition.
Re:Hard Disk Boot Sector
Posted: Mon Apr 26, 2004 3:12 am
by Candy
Of course you can assume that you're loaded by a MBR or bootloader decent enough to leave the partition table at 0x7BE (such as the default boot loader), and you can simply assume you're the active partition in that table. If you do it that way you can very simply boot off of "extended" partitions by using a MBR that can traverse them (still writing...
).
If you use grub, may god help you
. Or more honestly, I have no clue how you'd determine the partition.
Re:Hard Disk Boot Sector
Posted: Mon Apr 26, 2004 4:16 am
by Sean
So I should hardcode the partition into the bootsector, and then patch it using a tool whenever the filesystem is written/moved?
Re:Hard Disk Boot Sector
Posted: Mon Apr 26, 2004 4:25 am
by Solar
Candy wrote:
If you use grub, may god help you
. Or more honestly, I have no clue how you'd determine the partition.
It's in the Multiboot data structure, down to the BSD slice if you're using that.
Re:Hard Disk Boot Sector
Posted: Mon Apr 26, 2004 4:44 am
by Cemre
I don't know if that would work but, try that one...
from IDE Primary ports and from master device, read the cylinder port, sector port and the head port ( take into account that the combination may be LBA ) . This is where the last "read" has been made. that is, it is the address of the bootsector of your partition, soon compare this value with the values in the partition table and determine which partition you have booted from...
Re:Hard Disk Boot Sector
Posted: Mon Apr 26, 2004 4:55 am
by Candy
Cemre wrote:
I don't know if that would work but, try that one...
from IDE Primary ports and from master device, read the cylinder port, sector port and the head port ( take into account that the combination may be LBA ) . This is where the last "read" has been made. that is, it is the address of the bootsector of your partition, soon compare this value with the values in the partition table and determine which partition you have booted from...
I can't see that as a reliable way. The "last" access may have been that boot sector, may have been your own, or may even have been some root sector of some other partition, possibly the MBR (for saving something?). In case of GRUB, don't make any assumption what it is.
Re:Hard Disk Boot Sector
Posted: Mon Apr 26, 2004 1:30 pm
by Sean
How do bootsectors like the one for BeOS work? BeOS can boot up zbeos and then boot from a number of different kernels.
Re:Hard Disk Boot Sector
Posted: Mon Apr 26, 2004 2:56 pm
by Pype.Clicker
that sounds much like a 'multi-boot' selector program. Read a configuration file that tells you were the different kernels are, wait for the user to pick up one and then load it ...
Re:Hard Disk Boot Sector
Posted: Mon Apr 26, 2004 7:58 pm
by Sean
the BeOS bootloader doesn't actually need a config file. It will recognize a bootable partition on its own. I guess I could use a uniform bootsector/bootprogram for all partitions of my type, and the bootsector can just load the bootprogram from any one of the partitions available.
Re:Hard Disk Boot Sector
Posted: Tue Apr 27, 2004 1:44 am
by Pype.Clicker
well, of course if the 'different kernels' are acutally 'different system partitions' ...