Skip to contentSkip to conversation

Command extension suggestions

DISCUSSION Bean 3 participants 10 messages Jun 14, 2007

lore
Share & tools
lore

Bean

author
#0 lore raw

These ideas are mostly from grub4dos, I think they can be useful in GRUB2.

1. cat

In addition to the current function, cat can also generate hexadecimal dump, and it can optionally choose the range of bytes to display. For example:

cat [--hex] [--skip=S] [--length=L] FILE

Sometimes it's useful to dump the content of physical memory, it can be implemented with a special option --mem. For example,

cat [--mem] [--skip=S] [--length=L] base_address

It can also be implemented with virtual device (md). For example,

cat --hex (md)+2

dump the first 1K of memory.

But It seems a waste to add a new device just for cat.

The cat module can export function dump:

dump(unsigned long base, char* buf, int len);

other module can use it to generate hexadecimal dump.

2. find

Find command is missing in GRUB2. It's used to find the device which contains a certain file.

find [--set=var_name] FILENAME

If the device is found, it's name will be copied to var_name. For example,

find --set=root /io.sys
chainloader +1

Boot from the partition that has io.sys in the root directory.

3. chainloader

It can be useful if chainloader can load multiple sector file.

chainloader [--force] [--load-addr=SEG:OFS] [--boot-addr=CS:IP] FILE

The default load address and boot address is 0:0x7C00.

With this extension, chainloader can load grldr, ntldr, io.sys, kernel.sys, etc.

Signature · 1 line
Bean <[email protected]>
#1 lore raw
Quoted 8 lines · Bean

These ideas are mostly from grub4dos, I think they can be useful in GRUB2.

1. cat

In addition to the current function, cat can also generate hexadecimal dump, and it can optionally choose the range of bytes to display. For example:

cat [--hex] [--skip=S] [--length=L] FILE

Wouldn't it be more consistent to call it:

od [-j|--skip-bytes=S] [-N|--read-bytes=L] FILE

Quoted 8 lines

Sometimes it's useful to dump the content of physical memory, it can be implemented with a special option --mem. For example,

cat [--mem] [--skip=S] [--length=L] base_address

It can also be implemented with virtual device (md). For example,

cat --hex (md)+2

That sounds much cleaner IMHO. But IIRC (md) is already in use by the RAID/LVM stuff ?

Quoted 6 lines

2. find

Find command is missing in GRUB2. It's used to find the device which contains a certain file.

find [--set=var_name] FILENAME

We have this already, only with different name:

  search --set /file

(root is implicit, but it can be overriden)

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.
author
#2 lore raw
Quoted 5 lines · Robert Millan
Quoted 4 lines · Bean

These ideas are mostly from grub4dos, I think they can be useful in GRUB2.

1. cat

Quoted 9 lines
Quoted 4 lines

In addition to the current function, cat can also generate hexadecimal dump, and it can optionally choose the range of bytes to display. For example:

cat [--hex] [--skip=S] [--length=L] FILE

Wouldn't it be more consistent to call it:

od [-j|--skip-bytes=S] [-N|--read-bytes=L] FILE

Good idea.

Quoted 12 lines
Quoted 8 lines

Sometimes it's useful to dump the content of physical memory, it can be implemented with a special option --mem. For example,

cat [--mem] [--skip=S] [--length=L] base_address

It can also be implemented with virtual device (md). For example,

cat --hex (md)+2

That sounds much cleaner IMHO. But IIRC (md) is already in use by the RAID/LVM stuff ?

Maybe (mem) ?

Also, I don't know if GRUB2 kernel support initrd. You can start grub4dos like this:

kernel /grub.exe
initrd /aa.img

Inside grub4dos, the initrd can be access using (rd). It would be nice if grub2 support this kind of usage.

Quoted 5 lines
Quoted 5 lines

2. find

Find command is missing in GRUB2. It's used to find the device which contains a certain file.

Quoted 7 lines
Quoted 1 line

find [--set=var_name] FILENAME

We have this already, only with different name:

  search --set /file

(root is implicit, but it can be overriden)

Thanks for pointing out.

Signature · 1 line
Bean <[email protected]>
#3 lore raw

Bean <[email protected]> writes:

[...]

Quoted 5 lines
Quoted 3 lines

That sounds much cleaner IMHO. But IIRC (md) is already in use by the RAID/LVM stuff ?

Maybe (mem) ?

When would this be useful?

Quoted 8 lines

Also, I don't know if GRUB2 kernel support initrd. You can start grub4dos like this:

kernel /grub.exe
initrd /aa.img

Inside grub4dos, the initrd can be access using (rd). It would be nice if grub2 support this kind of usage.

You can use the loopback command to do this, if you want to access a filesystem image.

loopback (loop) /foo/bar.img
ls -l (loop)/

--
Marco

author
#4 lore raw
Quoted 11 lines · Marco Gerards

Bean <[email protected]> writes:

[...]

Quoted 5 lines
Quoted 3 lines

That sounds much cleaner IMHO. But IIRC (md) is already in use by the RAID/LVM stuff ?

Maybe (mem) ?

When would this be useful?

You can use it to dump physical memory, for example,

od (mem)+2

dump first 1K of memory

od --skip-bytes=0x413 --read-bytes=2 (mem)

dump the word at 0x413.

I can't think of other use at the moment.

Quoted 7 lines
Quoted 7 lines

Also, I don't know if GRUB2 kernel support initrd. You can start grub4dos like this:

kernel /grub.exe
initrd /aa.img

Quoted 9 lines
Quoted 2 lines

Inside grub4dos, the initrd can be access using (rd). It would be nice if grub2 support this kind of usage.

You can use the loopback command to do this, if you want to access a filesystem image.

loopback (loop) /foo/bar.img
ls -l (loop)/

Initrd can still be useful. In some case, it's not easy to access the boot media, such as, cdrom or pxe. To boot from such media, you can either put everything in core.img, or you can create a minimum core.img, and put other files, like *.mod, grub.cfg, font, etc, in an initrd. The initrd can be loaded along with core.img, using loader such as isolinux or pxelinux.

Signature · 1 line
Bean <[email protected]>
#5 lore raw
Quoted 17 lines · Bean
Quoted 11 lines · Marco Gerards

Bean <[email protected]> writes:

[...]

Quoted 5 lines
Quoted 3 lines

That sounds much cleaner IMHO. But IIRC (md) is already in use by the RAID/LVM stuff ?

Maybe (mem) ?

When would this be useful?

You can use it to dump physical memory, for example,

od (mem)+2

Quoted 7 lines

dump first 1K of memory

od --skip-bytes=0x413 --read-bytes=2 (mem)

dump the word at 0x413.

I can't think of other use at the moment.

Right, so mainly debugging :)

Quoted 12 lines
Quoted 12 lines
Quoted 8 lines

Also, I don't know if GRUB2 kernel support initrd. You can start grub4dos like this:

kernel /grub.exe
initrd /aa.img

Inside grub4dos, the initrd can be access using (rd). It would be nice if grub2 support this kind of usage.

You can use the loopback command to do this, if you want to access a filesystem image.

Quoted 8 lines
Quoted 2 lines

loopback (loop) /foo/bar.img
ls -l (loop)/

Initrd can still be useful. In some case, it's not easy to access the boot media, such as, cdrom or pxe. To boot from such media, you can either put everything in core.img, or you can create a minimum core.img, and put other files, like *.mod, grub.cfg, font, etc, in an initrd. The initrd can be loaded along with core.img, using loader such as isolinux or pxelinux.

Well, I see the problem but I do not agree with the solution.

The problem for GRUB 2 is that initrd is very linux specific. It's part of a loader. Perhaps we either have to extend loopback to load a file into memory on beforehand. Or add a memdisk disk or so.

One problem with initrd is that it is very architecture specific. Another problem is that the initrd is unloaded when you load another kernel or OS. Besides that, reusing initrd appears hackish to me :-).

--
Marco

author
#6 lore raw
Quoted 9 lines · Marco Gerards

Well, I see the problem but I do not agree with the solution.

The problem for GRUB 2 is that initrd is very linux specific. It's part of a loader. Perhaps we either have to extend loopback to load a file into memory on beforehand. Or add a memdisk disk or so.

One problem with initrd is that it is very architecture specific. Another problem is that the initrd is unloaded when you load another kernel or OS. Besides that, reusing initrd appears hackish to me :-).

I have another idea on this subject. First, We can extend the function of grub-mkimage so that it can handle data files. The data files embed in core.img can be accessed using a special device such as (ed). Then, we can put all necessary files, such as modules, grub.cfg and other data files in a single core.img. This kernel is self-sustaining, no extra file is needed for it to function properly.

Even if we don't create mono kernel, embeded data files can be usefully. For example, moddep.lst, fs.lst and command.lst, these files are best placed in core.img. Also, we can check the presence of embeded grub.cfg before loading external one, this is similar to the preset menu concept in GRUB Legacy.

Signature · 1 line
Bean <[email protected]>
#7 lore raw
Quoted 11 lines · Bean
Quoted 9 lines · Marco Gerards

Well, I see the problem but I do not agree with the solution.

The problem for GRUB 2 is that initrd is very linux specific. It's part of a loader. Perhaps we either have to extend loopback to load a file into memory on beforehand. Or add a memdisk disk or so.

One problem with initrd is that it is very architecture specific. Another problem is that the initrd is unloaded when you load another kernel or OS. Besides that, reusing initrd appears hackish to me :-).

Quoted 6 lines

I have another idea on this subject. First, We can extend the function of grub-mkimage so that it can handle data files. The data files embed in core.img can be accessed using a special device such as (ed). Then, we can put all necessary files, such as modules, grub.cfg and other data files in a single core.img. This kernel is self-sustaining, no extra file is needed for it to function properly.

This sounds good. In what way do you want to embed them? A filesystem image (for example minixfs)? Some simple archive?

You don't have to put modules in there, they can be made part of core.img.

Quoted 4 lines

Even if we don't create mono kernel, embeded data files can be usefully. For example, moddep.lst, fs.lst and command.lst, these files are best placed in core.img. Also, we can check the presence of embeded grub.cfg before loading external one, this is similar to the preset menu concept in GRUB Legacy.

The problem with a too big core.img is that it won't fit in the first cylinder. So we need to think carefully about what should go in there and what shouldn't.

But making it possible to pack everything so it can be booted using PXE or so sounds good. There was a feature for GRUB Legacy to add a menu.lst at compile-time. But having something more generic and not requiring a recompile is way better.

--
Marco

author
#8 lore raw
Quoted 20 lines · Marco Gerards
Quoted 11 lines · Bean
Quoted 9 lines · Marco Gerards

Well, I see the problem but I do not agree with the solution.

The problem for GRUB 2 is that initrd is very linux specific. It's part of a loader. Perhaps we either have to extend loopback to load a file into memory on beforehand. Or add a memdisk disk or so.

One problem with initrd is that it is very architecture specific. Another problem is that the initrd is unloaded when you load another kernel or OS. Besides that, reusing initrd appears hackish to me :-).

Quoted 6 lines

I have another idea on this subject. First, We can extend the function of grub-mkimage so that it can handle data files. The data files embed in core.img can be accessed using a special device such as (ed). Then, we can put all necessary files, such as modules, grub.cfg and other data files in a single core.img. This kernel is self-sustaining, no extra file is needed for it to function properly.

Quoted 2 lines

This sounds good. In what way do you want to embed them? A filesystem image (for example minixfs)? Some simple archive?

We can embed them the same way we embed modules. Just add a header:

SIGNATURE
FILENAME
DATA

SIGNATURE is used to distinguish data file from normal module, FILENAME is used by the virtual device to identify the data.

Signature · 1 line
Bean <[email protected]>
#9 lore raw
Quoted 24 lines · Bean
Quoted 20 lines · Marco Gerards
Quoted 11 lines · Bean
Quoted 9 lines · Marco Gerards

Well, I see the problem but I do not agree with the solution.

The problem for GRUB 2 is that initrd is very linux specific. It's part of a loader. Perhaps we either have to extend loopback to load a file into memory on beforehand. Or add a memdisk disk or so.

One problem with initrd is that it is very architecture specific. Another problem is that the initrd is unloaded when you load another kernel or OS. Besides that, reusing initrd appears hackish to me :-).

Quoted 6 lines

I have another idea on this subject. First, We can extend the function of grub-mkimage so that it can handle data files. The data files embed in core.img can be accessed using a special device such as (ed). Then, we can put all necessary files, such as modules, grub.cfg and other data files in a single core.img. This kernel is self-sustaining, no extra file is needed for it to function properly.

Quoted 2 lines

This sounds good. In what way do you want to embed them? A filesystem image (for example minixfs)? Some simple archive?

Quoted 8 lines

We can embed them the same way we embed modules. Just add a header:

SIGNATURE
FILENAME
DATA

SIGNATURE is used to distinguish data file from normal module, FILENAME is used by the virtual device to identify the data.

I will commit a patch soon that adds support for a dummy disk driver. In that case we just have to add a filesystem which offers access to this embedded data. I think this can even be done without changing the kernel a lot and adding this support in a module :-).

I would welcome such patch :-)

--
Marco