[SOLVED] Need help with GRUB

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
0xd3ba
Posts: 8
Joined: Mon Apr 29, 2019 1:52 am

[SOLVED] Need help with GRUB

Post by 0xd3ba »

So I've been trying to boot a sample "hello world" kernel with GRUB2 and I've been encountering some issues.
I created the disk image (inside virtualbox) following this: https://wiki.osdev.org/GRUB
I added the kernel image to /mnt/boot and added grub.cfg to /mnt/boot/grub

grub.cfg contains :

Code: Select all

menuentry "sample" {
    multiboot /boot/kernel
    boot
}
What happens is that it boots to a grub prompt, not to the kernel. This happens when I try to do it manually after:
Image

I've tried searching for the issue, but didn't find anything. I hope someone can help me out and point me in the right direction.
Thank you
Last edited by 0xd3ba on Fri Aug 23, 2019 2:24 pm, edited 1 time in total.
User avatar
iansjack
Member
Member
Posts: 4705
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Need help with GRUB

Post by iansjack »

The message is saying that there is something wrong with your kernel image file (it's too short). With no details of this file it's difficult to know what the problem is, or why.

It would help if you linked to a repository of your source code and the exact instructions that you used.
0xd3ba
Posts: 8
Joined: Mon Apr 29, 2019 1:52 am

Re: Need help with GRUB

Post by 0xd3ba »

iansjack wrote:The message is saying that there is something wrong with your kernel image file (it's too short). With no details of this file it's difficult to know what the problem is, or why.

It would help if you linked to a repository of your source code and the exact instructions that you used.
It doesn't contain much - just multiboot stuff and 2 instructions (movl $0xabcdabcd, %eax and hang: jmp hang ) to see if the code's executing or not.
However I don't feel that's what causing the issue though.
User avatar
iansjack
Member
Member
Posts: 4705
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Need help with GRUB

Post by iansjack »

Well, if you want to keep it secret that's fine.

I hope you manage to find the solution to your problem.
0xd3ba
Posts: 8
Joined: Mon Apr 29, 2019 1:52 am

Re: Need help with GRUB

Post by 0xd3ba »

iansjack wrote:Well, if you want to keep it secret that's fine.

I hope you manage to find the solution to your problem.
Huh, like I've mentioned there's nothing much except the multiboot header and the 2 instructions. Its just that I didn't feel like it's worth writing it down (as the code is trivial)
Anyways -

Code: Select all

.code32
.section .text
.globl _start

MB_MAGIC = 0xe85250d6
MB_ARCH = 0
MB_HLEN = mbend - mbstart
MB_CHKSUM = -(MB_MAGIC + MB_HLEN)

.p2align 3
mbstart:
    .long MB_MAGIC
    .long MB_ARCH
    .long MB_HLEN
    .long MB_CHKSUM

    .word 0
    .word 0
    .long 8
mbend:

_start:
    movl $0xabcdabcd, %eax
hang: jmp hang

EDIT
I managed to solve the problem. The issue was that the executable was a raw binary (--oformat=binary set during linking) instead of an elf executable
User avatar
iansjack
Member
Member
Posts: 4705
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: [SOLVED] Need help with GRUB

Post by iansjack »

I'm glad you solved your problem.

Perhaps you can understand now why asked to see what instructions you had used to produce your kernel. Just asking "what's wrong" without showing what you have done is a very difficult question to answer.
Post Reply