OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 10:36 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: GRUB boots inconsistently...
PostPosted: Tue Dec 27, 2011 8:21 am 
Offline
Member
Member
User avatar

Joined: Tue Dec 27, 2011 7:57 am
Posts: 368
So, first post. Anyway, I have already followed this (excellent) tutorial: http://www.osdever.net/tutorials/view/brans-kernel-development-tutorial

I have made some modifications though, I can't grub to find the kernel following it exactly. I used the Bare_Bones tutorial on the wiki for my ASM loader.

Anyway, I have an automated bash script to assemble, compile, link, write to floppy image, print the kernel location then boot it with qemu.

I use this code to get the size:

Code:
FILENAME=kernel.bin
FILESIZE=$(stat -c%b "$FILENAME")

echo
echo
echo "Use [kernel 200 + $FILESIZE]"
echo "Then [boot]"
.


Usually it will display 200+32.
However, when I use grub via
Code:
kernel 200+32
boot


It will load the kernel, however the whole (virtual) system will hang on "boot". However, sometimes it will boot just fine and print the two lines. (I only followed the tutorial up to the GDT part).

Following some experimenting, I found that there is still some data before 200+32. Here's the VERY VERY odd part: when the first command I run in the grub> prompt is loading the kernel, booting will hang. However, when I run something else before loading, for example "help", it loads and boots just fine.

I used ftp://alpha.gnu.org/gnu/grub/grub-0.97-i386-pc.tar.gz as mentioned in the wiki, then used the stage1 and stage2 files. I would use my own,(ubuntu 10.4LTS) but it appears I have GRUB2, and that apparently doesn't have stage1 and 2. I use qemu.

Now, why this extremely odd behaviour? It is reproducible 99.9% of the time.



EDIT: Great, now I cannot accurately reproduce it. at all. It seems COMPLETELY random.

_________________
[nx] kernel: http://github.com/zhiayang/nx


Top
 Profile  
 
 Post subject: Re: GRUB boots inconsistently...
PostPosted: Wed Dec 28, 2011 2:37 am 
Offline
Member
Member
User avatar

Joined: Tue Dec 27, 2011 7:57 am
Posts: 368
bump? Sometimes it seems if I type slower, it will work. Seriously, what's going on?

_________________
[nx] kernel: http://github.com/zhiayang/nx


Top
 Profile  
 
 Post subject: Re: GRUB boots inconsistently...
PostPosted: Wed Dec 28, 2011 2:49 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

What does "booting will hang" mean?

Does it mean GRUB hangs before it passes control to your kernel, or does it mean your kernel hangs?

When whatever does hang, how do you know - does it stop printing something (and if so, what is the last thing it prints)?

Are IRQs working when it hangs (and should IRQs be working)?

Is there an IDT with exception handlers? Could it be doing an "infinite loop of crashing" by executing an exception handler that does nothing more than "IRET"?

Do you have the same problem in Bochs or VirtualBox or other emulators? What about real machines?


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.


Top
 Profile  
 
 Post subject: Re: GRUB boots inconsistently...
PostPosted: Wed Dec 28, 2011 3:04 am 
Offline
Member
Member
User avatar

Joined: Tue Dec 27, 2011 7:57 am
Posts: 368
Brendan wrote:
Hi,

What does "booting will hang" mean?

Does it mean GRUB hangs before it passes control to your kernel, or does it mean your kernel hangs?

When whatever does hang, how do you know - does it stop printing something (and if so, what is the last thing it prints)?

Are IRQs working when it hangs (and should IRQs be working)?

Is there an IDT with exception handlers? Could it be doing an "infinite loop of crashing" by executing an exception handler that does nothing more than "IRET"?

Do you have the same problem in Bochs or VirtualBox or other emulators? What about real machines?


Cheers,

Brendan


1. As mentioned, I write stage1, stage2, a pad and my kernel to a floppy img.

2. From what I see, I have no idea. I have tried using the 'debug' command in grub, but that doesn't tell me anything more. What happens is I do 'kernel 200+32' (usually), then 'boot'. upon typing 'boot', the system will hang on that screen, forever. EDIT: Sometimes, not always

3. I think either something happened while booting my kernel, or something went wrong with loading it. (It always loads though).

4. No, IDTs are working, but not IRQs. I haven't got to there yet.

5. I have no idea.

6. I'm on ubuntu on vmware on a mac, so I don't think I can boot from hardware. Virtualbox refuses to recognise my floppy image (simple "cat stage1 stage2 pad kernel.bin > floppy.img" ) and vmware doesn't want to perform "computer-ception". I can't get bochs to build, any kind of "./configure" on this system always complains about something missing, either python or some other obscure dependency.



Actually, the main problem is inconsistency. Sometimes it works, other times it doesn't. That is what intrigues me. I can run my build script twice in a row, and one will work, the other will fail.

_________________
[nx] kernel: http://github.com/zhiayang/nx


Top
 Profile  
 
 Post subject: Re: GRUB boots inconsistently...
PostPosted: Wed Dec 28, 2011 3:27 am 
Offline
Member
Member
User avatar

Joined: Wed Dec 01, 2010 3:41 am
Posts: 1761
Location: Hong Kong
requimrar wrote:
cat stage1 stage2 pad kernel.bin > floppy.img


give it enough padding at the end as well?

Some emulators does not like floppy images with non-standard size. Although there are hacks and workarounds like this
https://forums.virtualbox.org/viewtopic.php?f=9&t=41696

In any case, a smaller floppy usually induce troubles.


Top
 Profile  
 
 Post subject: Re: GRUB boots inconsistently...
PostPosted: Wed Dec 28, 2011 3:33 am 
Offline
Member
Member

Joined: Sat Oct 09, 2010 3:35 am
Posts: 274
Hi,

requimrar wrote:
Virtualbox refuses to recognise my floppy image (simple "cat stage1 stage2 pad kernel.bin > floppy.img" )


As mentioned above, try padding the image.

requimrar wrote:
any kind of "./configure" on this system always complains about something missing, either python or some other obscure dependency


And the evil villain in the backyard is preventing you from installing the obscure dependency and/or whatever is causing the errors?

(hint: just search for the error messages on google - and you'd get plenty of hits. if that doesn't help, try searching specifically for ubuntu. would surely help)

Regards,
Shikhin

_________________
http://shikhin.in/

Current status: Gandr.


Top
 Profile  
 
 Post subject: Re: GRUB boots inconsistently...
PostPosted: Wed Dec 28, 2011 4:14 am 
Offline
Member
Member
User avatar

Joined: Tue Dec 27, 2011 7:57 am
Posts: 368
Shikhin wrote:
Hi,

requimrar wrote:
Virtualbox refuses to recognise my floppy image (simple "cat stage1 stage2 pad kernel.bin > floppy.img" )


As mentioned above, try padding the image.

requimrar wrote:
any kind of "./configure" on this system always complains about something missing, either python or some other obscure dependency


And the evil villain in the backyard is preventing you from installing the obscure dependency and/or whatever is causing the errors?

(hint: just search for the error messages on google - and you'd get plenty of hits. if that doesn't help, try searching specifically for ubuntu. would surely help)

Regards,
Shikhin


Thanks, and the above as well. and Shikhin, I hate how this "Ubuntu Software Centre" doesn't install dependencies like synaptic used to. Yes I know I can use synaptic, however it says my python is already the newest version. So yes, it must be the evil villain in my backyard. Doof?



EDIT: Whoops, forgot to reply. Yes, adding more padding seems to make it more reliable, but I still can't say for sure. Also, at the risk of either a) sounding stupid due to lack of reading tutorials or b) going off topic (I don't feel good posting again less than 24 hours apart),

How would I configure grub to boot automatically, without having to type those kernel and boot commands?

PS: Also, I found it better to get size in bytes/512, rather than directly getting blocks allocated using "stat". Seems more reliable. I think that was the problem, but it wouldn't hurt to add another 30sec to my build time, for compatibility?

_________________
[nx] kernel: http://github.com/zhiayang/nx


Top
 Profile  
 
 Post subject: Re: GRUB boots inconsistently...
PostPosted: Wed Dec 28, 2011 5:02 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

requimrar wrote:
How would I configure grub to boot automatically, without having to type those kernel and boot commands?


The "kernel 200+32" thing is an ugly hack. The way you're meant to use GRUB is have a file system and tell GRUB the name of the file it should load from that file system. For example, you could have a FAT formatted GRUB floppy with your kernel stored as the file "boot/kernel.bin" on the floppy; and then have a "boot/menu.lst" (also on the floppy) that GRUB will use for configuration, which might look like this:

Code:
hiddenmenu
timeout 0

title SomeOS
root (fd0)
kernel /boot/kernel.bin


In this case GRUB will figure out the size of the file and which sector/s to load automatically, and boot your kernel (with no menu and no timeout, and no need for the user to type anything).

I'd also recommend doing anything you have to to get something like Bochs working. The problem with VMware is that there's no debugger at all, so you can't debug it yourself and you can't even find any information that might help other people (e.g. us). With something like Bochs you could wait for it to hang then enter the debugger and find out exactly what the CPU is actually doing; or set a breakpoint and single-step through the code and find out how far it gets, or take a look at RAM and see that the file was loaded correctly. You might even get useful information from the log when your OS crashes.

Note: Newer versions of python aren't compatible with old versions of python. Maybe you've got a newer version installed but Bochs need an older version of python.


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.


Top
 Profile  
 
 Post subject: Re: GRUB boots inconsistently...
PostPosted: Wed Dec 28, 2011 5:10 am 
Offline
Member
Member
User avatar

Joined: Tue Dec 27, 2011 7:57 am
Posts: 368
Right. So sometimes I still get that problem. When loading the kernel, grub says this:

[Multiboot-elf, <0x100000:0x1185:0x0>, <0x102000:0xa0:0x4868>, shtab=0x107168(bad), entry=0x10000c]

What I'm most concerned (and is the only thing apart from Multiboot-elf I can decipher) is (bad).

_________________
[nx] kernel: http://github.com/zhiayang/nx


Top
 Profile  
 
 Post subject: Re: GRUB boots inconsistently...
PostPosted: Thu Dec 29, 2011 12:22 am 
Offline
Member
Member
User avatar

Joined: Tue Dec 27, 2011 7:57 am
Posts: 368
Brendan wrote:
Hi,

requimrar wrote:
How would I configure grub to boot automatically, without having to type those kernel and boot commands?


The "kernel 200+32" thing is an ugly hack. The way you're meant to use GRUB is have a file system and tell GRUB the name of the file it should load from that file system. For example, you could have a FAT formatted GRUB floppy with your kernel stored as the file "boot/kernel.bin" on the floppy; and then have a "boot/menu.lst" (also on the floppy) that GRUB will use for configuration, which might look like this:

Code:
hiddenmenu
timeout 0

title SomeOS
root (fd0)
kernel /boot/kernel.bin


In this case GRUB will figure out the size of the file and which sector/s to load automatically, and boot your kernel (with no menu and no timeout, and no need for the user to type anything).

I'd also recommend doing anything you have to to get something like Bochs working. The problem with VMware is that there's no debugger at all, so you can't debug it yourself and you can't even find any information that might help other people (e.g. us). With something like Bochs you could wait for it to hang then enter the debugger and find out exactly what the CPU is actually doing; or set a breakpoint and single-step through the code and find out how far it gets, or take a look at RAM and see that the file was loaded correctly. You might even get useful information from the log when your OS crashes.

Note: Newer versions of python aren't compatible with old versions of python. Maybe you've got a newer version installed but Bochs need an older version of python.


Cheers,

Brendan


Thanks for that. Unfortunately, Even with this automated thing, sometimes it hangs, (when I press enter or right arrow), other times it won't. Seriously, what is going on? I followed the tutorial on the wiki for making a bootable CD image (eltorito style).

_________________
[nx] kernel: http://github.com/zhiayang/nx


Top
 Profile  
 
 Post subject: Re: GRUB boots inconsistently...
PostPosted: Thu Dec 29, 2011 2:27 am 
Offline
Member
Member

Joined: Sat Oct 09, 2010 3:35 am
Posts: 274
Hi,

requimrar wrote:
Thanks for that. Unfortunately, Even with this automated thing, sometimes it hangs, (when I press enter or right arrow), other times it won't. Seriously, what is going on? I followed the tutorial on the wiki for making a bootable CD image (eltorito style).


Um, are you sure it's not your kernel? Try installing bochs, then putting a magic breakpoint (xchg bx, bx) at the starting of your kernel. That'd help you know whether you even reach your kernel, or not. After that, you could single step through various points, finding out where exactly is it halting.

Regards,
Shikhin

_________________
http://shikhin.in/

Current status: Gandr.


Top
 Profile  
 
 Post subject: Re: GRUB boots inconsistently...
PostPosted: Thu Dec 29, 2011 6:22 am 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 3192
It could be some hardware related problem. I also have a machine that boots with GRUB that sometimes locks-up during boot. This happens within GRUB, not as the kernel loads. From your description it seems similar to your situation. It could be some hardware that is setup incorrectly by your main OS that BIOS doesn't reinitialize properly. In my case, it always happens after a CTRL-ALT-DEL reboot of RDOS, or a shutdown of Windows XP, never after a cold reboot. If it happens while you are at GRUBs command-line prompt (and not after you have typed the "boot" command), it is certainly related to GRUB, not your kernel.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], DotBot [Bot] and 111 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group