Hard Disk Boot Sector

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
Sean

Hard Disk Boot Sector

Post 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.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Hard Disk Boot Sector

Post 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.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Hard Disk Boot Sector

Post 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 :P. Or more honestly, I have no clue how you'd determine the partition.
Sean

Re:Hard Disk Boot Sector

Post by Sean »

So I should hardcode the partition into the bootsector, and then patch it using a tool whenever the filesystem is written/moved?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Hard Disk Boot Sector

Post by Solar »

Candy wrote: If you use grub, may god help you :P. 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. ;-)
Every good solution is obvious once you've found it.
Cemre

Re:Hard Disk Boot Sector

Post 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...
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Hard Disk Boot Sector

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

Re:Hard Disk Boot Sector

Post 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.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Hard Disk Boot Sector

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

Re:Hard Disk Boot Sector

Post 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.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Hard Disk Boot Sector

Post by Pype.Clicker »

well, of course if the 'different kernels' are acutally 'different system partitions' ...
Post Reply