OS won't boot with MBR

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
User avatar
accelleon
Member
Member
Posts: 28
Joined: Wed Jul 22, 2009 6:49 pm

OS won't boot with MBR

Post by accelleon »

Hi everyone :D . I would like a little help with an issue I've been having. I was testing my OS on a virtual hdd. The MBR is Microsoft's default one(probably my first mistake :twisted: ) anyway I thought Microsoft's MBR could boot any OS include any hobby one but I tried replacing the one made when I formatted the partion (using XP on Virtual PC) but it went to the same screen Virtual PC goes to when there's no bootable device, yet with the default boot sector it worked. I have no idea how to test a .vhd file with bochs so please help me. Oh and the sector I have my VBR is 0x3F if it matters, why I don't know XP put the partion's VBR there so I just overwrote it with mine). Also if this comes up yes the first byte in the first partion entry in the partion table of the MBR has the 0x80 bit set.
Accel OS website.
Pimpanime-#1 source for English dubbed anime
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: OS won't boot with MBR

Post by neon »

accelleon wrote:anyway I thought Microsoft's MBR could boot any OS include any hobby one but I tried replacing the one made when I formatted the partion (using XP on Virtual PC) but it went to the same screen Virtual PC goes to when there's no bootable device, yet with the default boot sector it worked.
I suspect it is something else at fault. Microsoft's MBR is a generic MBR - it can boot any partition so long as it is marked as primary and active. (If there is more then 1 primary and active partition, it will fail and display an error.)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
kop99
Member
Member
Posts: 120
Joined: Fri May 15, 2009 2:58 am

Re: OS won't boot with MBR

Post by kop99 »

The MBR is Microsoft's default one(probably my first mistake :twisted: ) anyway I thought Microsoft's MBR could boot any OS include any hobby one but I tried replacing the one made when I formatted the partion (using XP on Virtual PC) but it went to the same screen Virtual PC goes to when there's no bootable device, yet with the default boot sector it worked.
If your own boot loader have more than 446byte, then you have to spilit it...
User avatar
accelleon
Member
Member
Posts: 28
Joined: Wed Jul 22, 2009 6:49 pm

Re: OS won't boot with MBR

Post by accelleon »

neon wrote:I suspect it is something else at fault. Microsoft's MBR is a generic MBR - it can boot any partition so long as it is marked as primary and active. (If there is more then 1 primary and active partition, it will fail and display an error.)
I don't know what would be the problem the VBR is the same one that I used for the floppy. I know that my boot loader would display an error but thats what I want to happen so that I know it would work. Also if there is an error it changes the screen to fast to catch it.
kop99 wrote:If your own boot loader have more than 446byte, then you have to spilit it...
I replaced the VBR not the MBR's code. The code in the MBR has to be 446 bytes at the most so that it can fit the partion table and the boot signature. The VBR is the same method used for floppy drives. It can be the size of a sector (in my case 512 bytes) but under the case that the VBR loads other sections of it self (eg. Windows uses 3 sectors) it can be as large as the amount of RAM real mode allows (forgot that amount #-o ).

Edit: I am now noticing that when I replace Microsoft's VBR with mine the size decreases from 4 GB to 1.86 MB.
Accel OS website.
Pimpanime-#1 source for English dubbed anime
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: OS won't boot with MBR

Post by egos »

Are you sure that you are using correct boot sector? What format of the volume is present, FAT32 or other? Maybe your boot sector (data and/or code) is not suitable for this volume.
If you have seen bad English in my words, tell me what's wrong, please.
User avatar
accelleon
Member
Member
Posts: 28
Joined: Wed Jul 22, 2009 6:49 pm

Re: OS won't boot with MBR

Post by accelleon »

The boot loader is the same one that worked for my floppy. I formatted the 4 GB partion to FAT16.
Accel OS website.
Pimpanime-#1 source for English dubbed anime
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: OS won't boot with MBR

Post by neon »

I don't know what would be the problem the VBR is the same one that I used for the floppy
Why are you using an MBR to boot a floppy VBR? :? MBRs are typically on hard disks, which is what Windows MBR expects to be booted from.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
accelleon
Member
Member
Posts: 28
Joined: Wed Jul 22, 2009 6:49 pm

Re: OS won't boot with MBR

Post by accelleon »

I wanted to test booting from the HDD. I overwrote the partion's boot sector with the floppy's VBR, so the floppy VBR is on the HDD. I should still boot because Microsoft's MBR is supposed to be able to boot any VBR. It is 512 bytes and has 0xAA55 as the last word... It loads a file called ldr.sys witch in turn loads the krnl.exe. I don't have ether of the files on the HDD so I expect it to show an error, 'FATAL ERROR: Missing file "ldr.sys"', and halt the system. It doesn't even load the boot loader. I don't think the sector size is more than 512. Maybe it's the OEM Parameter Block... I would easily be able to change it to the correct values but I don't know the number of sectors let alone the size on a virtual HDD. Is there a program or way to check the values that are used in the OEM Parameter Block in windows XP?
Accel OS website.
Pimpanime-#1 source for English dubbed anime
User avatar
Thor
Member
Member
Posts: 51
Joined: Mon Jul 06, 2009 12:55 am
Location: Kamloops, BC, Canada

Re: OS won't boot with MBR

Post by Thor »

Chances are that (unless you did this) the Microsoft MBR has no idea your OS is there because you didn't add the necessary info to the Partition Table.
Vancouver Canucks fan for life
User avatar
accelleon
Member
Member
Posts: 28
Joined: Wed Jul 22, 2009 6:49 pm

Re: OS won't boot with MBR

Post by accelleon »

I used windows XP to create the partion. It should set up everything but the active byte, but I set it to 0x80... I don't know what else I need to set up. :(
Accel OS website.
Pimpanime-#1 source for English dubbed anime
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: OS won't boot with MBR

Post by Love4Boobies »

Did you happen to also disassemble MS' MBR or are you just asking us to do that for you?

Floppy problem:
Unlike your MBR which probably uses the DL value BIOS passed to it for INT 13h, MS' MBR plays around with the value of DX and then loads it back from the field that defines wether the partition is active or not (0x80 or 0x00, respectively). Since your FDD BAID is 0x00 and you try to use 0x80 guess what happens?

Hard disk problem:
Well, unless you corrupted the partition in some way the right values should already be there. Note however that Windows doesn't really care about the MBR, it only does so for booting. If you start adding partitions after you've installed the OS it won't update the MBR IIRC. It would probably be easy to either take a look around or provide a dump of it. Guessing is always a bad idea and we don't have enough info.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
accelleon
Member
Member
Posts: 28
Joined: Wed Jul 22, 2009 6:49 pm

Re: OS won't boot with MBR

Post by accelleon »

My floppy doesn't have a problem. I am trying to boot using a floppy VBR that's on the HDD using Microsoft's MBR. I just don't understand what's wrong. I know that the problem lies within the VBR cause this only happens when I replace Microsoft's VBR with mine. As for the detected size issue the only section of the boot loader that even has anything to do with the size is the OEM Parameter Block, so from where I'm looking the OEM Parameter Block is the culprit due to the the fact that that's the only thing that deals with the size of the sectors and number of sectors. But for me to test that I need to be able to retrieve the correct information.
Accel OS website.
Pimpanime-#1 source for English dubbed anime
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: OS won't boot with MBR

Post by Love4Boobies »

What?! Did you read carefully? I said that Microsoft's MBR uses a hard-coded values: 0x80 (which is both the signature for an active partition an the index for the HDD BAID). In other words, it always passes 0x80 to INT 13h and that doesn't work for a floppy. Your own MBR probably uses DL instead of a hard-coded value.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: OS won't boot with MBR

Post by Troy Martin »

accelleon wrote:I am trying to boot using a floppy VBR that's on the HDD using Microsoft's MBR.
If you can't figure out what the problem is, you shouldn't be programming.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: OS won't boot with MBR

Post by neon »

You cannot, and should never use a floppy VBR for a HDD. It should not work with any MBR because MBRs were not meant to boot floppy VBRs (for the simple reason that floppies don't need them.)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Post Reply