Page 1 of 1

GRUB2 - Multiboot "module" command documentation

Posted: Mon Oct 06, 2014 8:02 am
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

Re: GRUB2 - Multiboot "module" command documentation

Posted: Mon Oct 06, 2014 8:23 am
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).

Re: GRUB2 - Multiboot "module" command documentation

Posted: Mon Oct 06, 2014 8:59 am
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 :)

Re: GRUB2 - Multiboot "module" command documentation

Posted: Mon Oct 06, 2014 3:23 pm
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.

Re: GRUB2 - Multiboot "module" command documentation

Posted: Mon Oct 06, 2014 3:45 pm
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.

Re: GRUB2 - Multiboot "module" command documentation

Posted: Mon Oct 06, 2014 3:55 pm
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;
};

Re: GRUB2 - Multiboot "module" command documentation

Posted: Tue Oct 07, 2014 3:28 am
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 :)

Re: GRUB2 - Multiboot "module" command documentation

Posted: Thu Oct 09, 2014 6:16 am
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 :)