Page 1 of 1

[SOLVED] Need help with GRUB

Posted: Fri Aug 23, 2019 9:36 am
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

Re: Need help with GRUB

Posted: Fri Aug 23, 2019 9:40 am
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.

Re: Need help with GRUB

Posted: Fri Aug 23, 2019 11:34 am
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.

Re: Need help with GRUB

Posted: Fri Aug 23, 2019 11:52 am
by iansjack
Well, if you want to keep it secret that's fine.

I hope you manage to find the solution to your problem.

Re: Need help with GRUB

Posted: Fri Aug 23, 2019 1:34 pm
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

Re: [SOLVED] Need help with GRUB

Posted: Fri Aug 23, 2019 3:01 pm
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.