Can we fake a Hard Drive master boot record

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
PatrickV
Member
Member
Posts: 151
Joined: Sun Jul 06, 2008 7:50 pm
Location: New Zealand
Contact:

Can we fake a Hard Drive master boot record

Post by PatrickV »

I was looking at examples of hard drive MBR (Master Boot Record) and just wondering if we can fake it. I want to make a hard drive MBR to just print 2 linex of value. I know that you can do this with a floppy disk but on hard drive you have to make a partition parameter table and make sure that the partition boot indicator = 0x80.Have you got any ideas how can i go about it
User avatar
Telgin
Member
Member
Posts: 72
Joined: Thu Dec 20, 2007 1:45 pm

Re: Can we fake a Hard Drive master boot record

Post by Telgin »

For what it's worth, Bochs boots from HDD images with just a typical boot sector at sector 0. I don't know if that's correct and if a real BIOS would like that, but it works for me in Bochs. No need for all of the partition table stuff or anything, just have the signature at the end and it doesn't seem to care.
madeofstaples
Member
Member
Posts: 204
Joined: Thu Apr 12, 2007 8:15 am
Location: Michigan

Re: Can we fake a Hard Drive master boot record

Post by madeofstaples »

You can use the first sector of the hard drive however you like.

You only need a valid partition table if you want your code to be compliant with other standards (i.e, if you were writing a multi bootloader or you want your OS to work alongside other OSs without much trouble, etc), but it sounds like you just want to experiment. In this case, you can use the hard drive as if it were a floppy (the difference wouldn't be important for simply printing to the screen).

You can also do the same thing with a partition, where the partition exists in the partition table with the bootable flag set, and the first 512 bytes of the partition contain your bootloader (not sure if it's really required, but you should be able to spare the last two bytes for a boot signature 0x55 0xAA). This is, assuming you have a properly configured bootloader program in the MBR as well (set to chainload your partition).
Some people are offended by the verifiable truth; such people tend to remain blissfully unencumbered by fact.
If you are one of these people, my posts may cause considerable discomfort. Read at your own risk.
PatrickV
Member
Member
Posts: 151
Joined: Sun Jul 06, 2008 7:50 pm
Location: New Zealand
Contact:

Re: Can we fake a Hard Drive master boot record

Post by PatrickV »

Thanks!
Telgin wrote: No need for all of the partition table stuff or anything, just have the signature at the end and it doesn't seem to care.
well that is a load of crap becasue i already try that.
Ok! I just want to know if i Can not use a valid partition table at all. Does it allow me to do that? Have a look at my patricknet source code. I want to copy exact and run correctly on my hard drive?

REMOVED LINK!
Last edited by PatrickV on Fri Jul 10, 2015 7:58 pm, edited 1 time in total.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Can we fake a Hard Drive master boot record

Post by Brendan »

Hi,
PatrickV wrote:
Telgin wrote: No need for all of the partition table stuff or anything, just have the signature at the end and it doesn't seem to care.
well that is a load of crap becasue i already try that.
That *is* correct - the BIOS and hardware doesn't know or care about the partition table, and just loads the first sector and runs it (if the BIOS determines the first sector is bootable, etc). The first sector is usually an MBR that scans it's partition table and chainloads the boot sector in the active partition, but it doesn't have to. In a similar way you can have a partition table and MBR in a floppy if you like (but that's much less standard - other OS's probably won't recognize it).

In any case, when you tried it what went wrong?
PatrickV wrote:I want to copy exact and run correctly on my hard drive?
http://www.patricknet.pvcomputers.co.nz
I took a quick look at your source code, and it's dodgy - the magic number is in the wrong place. To fix it, replace "padding times 348 db 0" with "padding times 349 db 0" (which should work, but is still silly) or "padding times ($$-$+0x1FE) db 0x00" (which lets you modify the code without needing to manually recalculate how much padding to use).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
PatrickV
Member
Member
Posts: 151
Joined: Sun Jul 06, 2008 7:50 pm
Location: New Zealand
Contact:

Re: Can we fake a Hard Drive master boot record

Post by PatrickV »

That is an old verson. I was using that for an example. I've already fixed it in Beta 0.0.2 which i am having problems completing it.
Post Reply