GRUB2 - Multiboot "module" command documentation

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
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

GRUB2 - Multiboot "module" command documentation

Post by max »

Hey guys,

I'm using GRUB2 to boot my OS. There are three binary files: the loader, the kernel and the ramdisk. The loader is loaded as the multiboot kernel file, and the kernel and ramdisk are loaded as multiboot modules. So my configuration looks like this:

Code: Select all

set timeout=0
set default=0

menuentry "Ghost" {
    multiboot /boot/loader
    module /boot/kernel /boot/kernel
    module /boot/ramdisk /boot/ramdisk
    boot
}
This already works fine (even though I had to specify the path for each module twice, otherwise the path in the multiboot structures would be empty, whyever).

My problem is that I just can't find a documentation on what parameters the module command can take. The only thing I found in the GRUB 2.0 documentation is the way this command is used in GNU HURD or for Linux..

Could someone please help me to find the documentation for this command?

Thanks :)
Max
mallard
Member
Member
Posts: 280
Joined: Tue May 13, 2014 3:02 am
Location: Private, UK

Re: GRUB2 - Multiboot "module" command documentation

Post by mallard »

Looking at GRUB's source code, the implementation of the "module" command ("grub_cmd_module") is fairly simple.

The first parameter is the filename and the second parameter is optionally, "--nounzip", which disables GRUB's automatic decompression of .gz and .xz files. All other parameters are placed in the "cmdline" field (e.g. the filename in your example).
Image
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: GRUB2 - Multiboot "module" command documentation

Post by max »

mallard wrote:Looking at GRUB's source code, the implementation of the "module" command ("grub_cmd_module") is fairly simple.

The first parameter is the filename and the second parameter is optionally, "--nounzip", which disables GRUB's automatic decompression of .gz and .xz files. All other parameters are placed in the "cmdline" field (e.g. the filename in your example).
Oh right.. looking at the source is a good idea :P
Sadly, in the GRUB version 1.98 (had to take the one from Cygwin for the moment, but I guess its obsolete) I have to pass the second parameter, otherwise the "path" in the multiboot structures is empty. I'll investigate on that.
Thanks for pointing me to the right source files :)
User avatar
darkinsanity
Member
Member
Posts: 45
Joined: Wed Sep 17, 2008 3:59 am
Location: Germany

Re: GRUB2 - Multiboot "module" command documentation

Post by darkinsanity »

max wrote:Sadly, in the GRUB version 1.98 (had to take the one from Cygwin for the moment, but I guess its obsolete) I have to pass the second parameter, otherwise the "path" in the multiboot structures is empty. I'll investigate on that.
There is no path-field. There's only cmdline, and it only contains the parameters.
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: GRUB2 - Multiboot "module" command documentation

Post by max »

darkinsanity wrote:
max wrote:Sadly, in the GRUB version 1.98 (had to take the one from Cygwin for the moment, but I guess its obsolete) I have to pass the second parameter, otherwise the "path" in the multiboot structures is empty. I'll investigate on that.
There is no path-field. There's only cmdline, and it only contains the parameters.
Actually, the multiboot specification defines it not as "cmdline", but only as some null-terminated string:
Multiboot specification wrote:The ‘string’ field provides an arbitrary string to be associated with that particular boot module; [...]
GRUB Legacy used to put the path of the module there if you specify the module just like module /boot/ramdisk, but obviously GRUB2 doesn't.
User avatar
darkinsanity
Member
Member
Posts: 45
Joined: Wed Sep 17, 2008 3:59 am
Location: Germany

Re: GRUB2 - Multiboot "module" command documentation

Post by darkinsanity »

The multiboot specification is unprecise in several places. That's why I recommend to also have a look at the multiboot.h-header, which defines it like that:

Code: Select all

struct multiboot_mod_list
{
  /* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
  multiboot_uint32_t mod_start;
  multiboot_uint32_t mod_end;

  /* Module command line */
  multiboot_uint32_t cmdline;

  /* padding to take it to 16 bytes (must be zero) */
  multiboot_uint32_t pad;
};
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: GRUB2 - Multiboot "module" command documentation

Post by max »

Ah yes. That makes more sense. As it seems GRUB Legacy thought of it in a more argv-like way, as it included the module name itself.
Thank you :)
User avatar
darkinsanity
Member
Member
Posts: 45
Joined: Wed Sep 17, 2008 3:59 am
Location: Germany

Re: GRUB2 - Multiboot "module" command documentation

Post by darkinsanity »

No problem :)
Oh, and a little sidenote: I recently played around with iPXE, which also supports multiboot. When using the "kernel"-command to load a multiboot-compatible kernel, iPXE, in contrast to GRUB 2, does include the path. So instead of "-verbose" the cmdline-field of the multiboot-info-structure contained something like "http://192.168.1.50/frost.krn -verbose". Seems like you have to expect both behaviors. Or you force people to use GRUB 2 ;)
However, I had a lot of problems with iPXE's multiboot implementation, so I ended up chainloading a GRUB-ISO anyway.

/edit:
Is your project open source? I'm interested in taking a look at it :)
Post Reply