Page 1 of 1

Using GRUB2 modules in the kernel

Posted: Fri Sep 27, 2019 7:06 am
by DridriLaBastos
Hi! I read the multiboot documentation, and I saw that it was possible for the bootloader to load boot modules in RAM for the kernel. Because I want to create a microkernel I find this awesome, I searched in the documentation of GRUB how it was possible to do that and I finally find the "module" command to load GRUB module in RAM for the kernel.

What I would like to do is to use a GRUB module to load the disk driver and process management program of my kernel, and then use them to load the rest. I was able to find the GRUB modules in RAM, but now I struggle on how to use them. They are a relocatable elf, so they need to be linked with something. Does this mean that I should know where the executable code of the core image of GRUB has been load in memory and write a small linker in my kernel? I think there is another way.

Does somebody know how to use GRUB modules as executable for the kernel? I can't find any info. Or maybe I can just call functions from the elf file of the GRUB module?

Re: Using GRUB2 modules in the kernel

Posted: Fri Sep 27, 2019 7:26 am
by FusT
"GRUB modules" are simply files that are loaded into memory and are pointed to by the "module" struct in the multiboot struct.
After they are loaded into memory they have nothing to do with GRUB whatsoever. So yes, you'll need to link the ELF executable to your kernel at runtime and jump to the entrypoint.

Re: Using GRUB2 modules in the kernel

Posted: Fri Sep 27, 2019 8:05 am
by DridriLaBastos
Ok, so this means that if I want to use the GRUB module I have to embed the core image of GRUB into the kernel? I don't think it's a good solution (but I am curious to test it, it should be possible to have a small image with everything inside). The other option I see is to create something like ramfs.

Thanks for the reply

Re: Using GRUB2 modules in the kernel

Posted: Fri Sep 27, 2019 9:11 am
by Korona
There is a difference between kernel modules loaded by GRUB (you control the contents entirely, GRUB only loads them from disk and passes a pointer to the module via the Multiboot info struct) and modules for GRUB (i.e., extensions of GRUB that are loaded/compiled into GRUB.

Re: Using GRUB2 modules in the kernel

Posted: Fri Sep 27, 2019 12:46 pm
by DridriLaBastos
Korona wrote:There is a difference between kernel modules loaded by GRUB (you control the contents entirely, GRUB only loads them from disk and passes a pointer to the module via the Multiboot info struct) and modules for GRUB (i.e., extensions of GRUB that are loaded/compiled into GRUB.
Oooh thank you, I thought it was only possible to load GRUB module with the command module, but I can load whatever file I want. This is exactly what I wanted, I am so happy right now :D!