Skip to contentSkip to conversation

Alternative booting method for grub2

DISCUSSION Bean 8 participants 24 messages Jun 8, 2007 – Jul 22, 2011 1 message not in the archive

lore
Share & tools
lore

Bean

author
#0 lore raw

It's possible to boot grub2 using the grub4dos boot loader.

1. create a kernel:

grub-mkimage -d . -o core.img pc fat ntfs

make sure you include the necessary file system driver.

2. add a header to core.img.

cat g2hdr.bin core.img > g2ldr

g2hdr.bin can be found in the grubutil package.

3. copy g2ldr to the root directory of any FAT/NTFS/EXT2 partition, and extra modules to /boot/grub/ in the same partition.

4. install the grub4dos boot loader.

You need grubinst, which can be downloaded at:

http://download.gna.org/grubutil/

The latest build is grubutil-1.1-bin-w32-15.zip.

1) Boot using the Windows NT boot manager

Generate boot file with grubinst:

grubinst -2 -o C:\g2ldr.mbr

Then add a line to boot.ini:

C:\g2ldr.mbr="GRUB2"

This is the safest method, no modification to MBR or boot sector is required.

2) Install to MBR

  grubinst -2 --save=mbr.sav (hd0)

Be careful, backup important data before install to MBR.

3) Install to boot sector

  grubinst -2 --save=bs.sav (hd0,0)

or

  grubinst -2 --save=bs.sav -p=0 (hd0)

Be careful, backup important data before install to boot sector.

Currently, grub4dos boot loader support FAT, NTFS and EXT2.

The advantage of using grub4dos boot loader is that the location of g2ldr is calculated at boot time, this means you can move it without causing problem.

author
#1 lore raw

Variable assignment not working as expected

I try the following command:

set AA=1
set BB=$AA

then type set, it shows:

AA=1
BB=

should the value of BB be 1 ?

BTW, i notice that echo.c exists, but no echo.mod is generated.

#2 lore raw

Re: Variable assignment not working as expected

Quoted 4 lines · Bean

I try the following command:

set AA=1
set BB=$AA

Taking a quick look at command.c where the "set" command is defined, it doesn't look like that feature is implemented. Even in grub_env_set in env.c it isn't implemented.

I'm willing to implement this feature... Where do you, devs, think this would be better suited? In the set command, or in the grub_env_set function?

Quoted 9 lines

then type set, it shows:

AA=1
BB=

should the value of BB be 1 ?

BTW, i notice that echo.c exists, but no echo.mod is generated.

Because echo is such a "core" command it is built right into the kernel AFAIK...

Cheers!

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

Re: Variable assignment not working as expected

Quoted 3 lines

I'm willing to implement this feature... Where do you, devs, think this would be better suited? In the set command, or in the grub_env_set function?

Hmm, after some further thought, I think it would make more sense to put it in grub_env_set function because that allows the feature to be use throughout the grub2 source code... It could be useful in some places...

Signature · 1 line
Alex Roman <[email protected]>
#4 lore raw

Re: Variable assignment not working as expected

Quoted 4 lines · Alex Roman

Hmm, after some further thought, I think it would make more sense to put it in grub_env_set function because that allows the feature to be use throughout the grub2 source code... It could be useful in some places...

I'm trying to code this feature but I'm noticing something peculiar...

In command.c, function set_command I do the following just before "var = args[0];":

grub_printf( "args[0]: %s\n", args[0] );

If args[0] contains a '$', the string is displayed up until the $, not inclusive. Any other character is fine.

Does '$' get considered as a line-ending or command-ending character? If so, we can't implement this feature because we don't get access to anything after the '$'...

Thanks!

Signature · 1 line
Alex Roman <[email protected]>
#5 lore raw

Re: Variable assignment not working as expected

Quoted 5 lines · Alex Roman

I'm trying to code this feature but I'm noticing something peculiar...

In command.c, function set_command I do the following just before "var = args[0];":

Quoted 8 lines

grub_printf( "args[0]: %s\n", args[0] );

If args[0] contains a '$', the string is displayed up until the $, not inclusive. Any other character is fine.

Does '$' get considered as a line-ending or command-ending character? If so, we can't implement this feature because we don't get access to anything after the '$'...

Furthermore, if I enter, say:
set A=$

In grub-emu, I get a segmentation fault!

Signature · 1 line
Alex Roman <[email protected]>
author
#6 lore raw

Re: Variable assignment not working as expected

In reply to Alex Roman
Quoted 5 lines · Alex Roman
Quoted 1 line

BTW, i notice that echo.c exists, but no echo.mod is generated.

Because echo is such a "core" command it is built right into the kernel AFAIK...

But when i try to use it in the grub console, it says unknown command:

grub> echo Hello
error: unknown command `echo'

#7 lore raw

Re: Variable assignment not working as expected

In reply to Alex Roman
Quoted 6 lines · Alex Roman
Quoted 4 lines · Bean

I try the following command:

set AA=1
set BB=$AA

Quoted 7 lines

Taking a quick look at command.c where the "set" command is defined, it doesn't look like that feature is implemented. Even in grub_env_set in env.c it isn't implemented.

I'm willing to implement this feature... Where do you, devs, think this would be better suited? In the set command, or in the grub_env_set function?

The problem is different. The command line parser should insert this, but currently can't deal with the case where text and variables are concatenated, IIRC.

Quoted 10 lines
Quoted 8 lines

then type set, it shows:

AA=1
BB=

should the value of BB be 1 ?

BTW, i notice that echo.c exists, but no echo.mod is generated.

Because echo is such a "core" command it is built right into the kernel AFAIK...

No, it's even a normal mode command.

--
Marco

#8 lore raw

Re: Variable assignment not working as expected

Quoted 12 lines · Marco Gerards
Quoted 10 lines · Alex Roman
Quoted 4 lines · Bean

I try the following command:

set AA=1
set BB=$AA

Taking a quick look at command.c where the "set" command is defined, it doesn't look like that feature is implemented. Even in grub_env_set in env.c it isn't implemented.

Quoted 7 lines
Quoted 3 lines

I'm willing to implement this feature... Where do you, devs, think this would be better suited? In the set command, or in the grub_env_set function?

The problem is different. The command line parser should insert this, but currently can't deal with the case where text and variables are concatenated, IIRC.

Ahh... I see now how it's handled. My bad.

... I wish I knew flex/yacc :(

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

then type set, it shows:

AA=1
BB=

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

should the value of BB be 1 ?

BTW, i notice that echo.c exists, but no echo.mod is generated.

Because echo is such a "core" command it is built right into the kernel AFAIK...

No, it's even a normal mode command.

So, is it built as part of a module which needs to be loaded, or does it get built into GRUB2 like insmod/rmmod/etc?

Signature · 1 line
Alex Roman <[email protected]>
#9 lore raw

Re: Variable assignment not working as expected

"Alex Roman" <[email protected]> writes:

[...]

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

BTW, i notice that echo.c exists, but no echo.mod is generated.

Because echo is such a "core" command it is built right into the kernel AFAIK...

No, it's even a normal mode command.

So, is it built as part of a module which needs to be loaded, or does it get built into GRUB2 like insmod/rmmod/etc?

It's a module. I just have to enable it.

--
Marco

#10 lore raw

Re: Variable assignment not working as expected

In reply to Bean
Quoted 11 lines · Bean

I try the following command:

set AA=1
set BB=$AA

then type set, it shows:

AA=1
BB=

should the value of BB be 1 ?

This is a known bug :-/

Quoted 1 line

BTW, i notice that echo.c exists, but no echo.mod is generated.

I will have a look at this.

--
Marco

#11 lore raw
In reply to Bean

Works wonders. I'm using it with win32-loader [1] [2], and plans are that this will make it to official Debian CDs/DVDs for the next major release.

I wonder if it can create a "grub.com" executable like the one grub4dos had, so that it's possible to load GRUB directly on a Win9x without rebooting or messing with MBR.

[1] http://packages.debian.org/sid/win32-loader
[2] http://goodbye-microsoft.com/

Quoted 63 lines · Bean

It's possible to boot grub2 using the grub4dos boot loader.

1. create a kernel:

grub-mkimage -d . -o core.img pc fat ntfs

make sure you include the necessary file system driver.

2. add a header to core.img.

cat g2hdr.bin core.img > g2ldr

g2hdr.bin can be found in the grubutil package.

3. copy g2ldr to the root directory of any FAT/NTFS/EXT2 partition, and extra modules to /boot/grub/ in the same partition.

4. install the grub4dos boot loader.

You need grubinst, which can be downloaded at:

http://download.gna.org/grubutil/

The latest build is grubutil-1.1-bin-w32-15.zip.

1) Boot using the Windows NT boot manager

Generate boot file with grubinst:

grubinst -2 -o C:\g2ldr.mbr

Then add a line to boot.ini:

C:\g2ldr.mbr="GRUB2"

This is the safest method, no modification to MBR or boot sector is required.

2) Install to MBR

  grubinst -2 --save=mbr.sav (hd0)

Be careful, backup important data before install to MBR.

3) Install to boot sector

  grubinst -2 --save=bs.sav (hd0,0)

or

  grubinst -2 --save=bs.sav -p=0 (hd0)

Be careful, backup important data before install to boot sector.

Currently, grub4dos boot loader support FAT, NTFS and EXT2.

The advantage of using grub4dos boot loader is that the location of g2ldr is calculated at boot time, this means you can move it without causing problem.

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)
#12 lore raw

If I command

grub-mkimage -d . -o core.img pc fat ntfs

The result is
Target format not specified (use the -O option).
Try `grub-mkimage --help' for more information

How can I create a kernel?

Thanks.

#13 lore raw
In reply to Bean

If I command

grub-mkimage -d . -o core.img pc fat ntfs

The result is

Target format not specified (use the -O option).
Try `grub-mkimage --help' for more information

How can I create a kernel?

Thanks.

#14 lore raw
Quoted 3 lines · 김민준

If I command
grub-mkimage -d . -o core.img pc fat ntfs

Just use grub-install

Quoted 14 lines

The result is

Target format not specified (use the -O option).
Try `grub-mkimage --help' for more information

How can I create a kernel?

Thanks.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko

A message that is not in the archive (sent off-list or not yet received): 22991850.525.1311095881463.JavaMail.mobile-sync@vbbfs23

#16 lore raw

-O i386-pc as a target would work.

Envoyé de mon appareil mobile.

Jérôme Poulin
Solutions G.A.

On 2011-07-19, at 07:48, "김민준" <[email protected]> wrote:

If I command

grub-mkimage -d . -o core.img pc fat ntfs

The result is

Target format not specified (use the -O option).
Try `grub-mkimage --help' for more information

How can I create a kernel?

Thanks.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#17 lore raw

When I command with -O i386-pc
the result is

grub-mkimage: error: cannot open ./moddep.lst.

If I command as root, the result is same.

Please help me.

Thanks.

#19 lore raw

When I command
sudo grub-mkimage -d ./grub-core -o core.img pc fat ntfs -O i386-pc

the result is
grub-mkimage: error: cannot open ./grub-core/moddep.lst.

When I command at /boot/grub, the result is same.

I can't understand why creating kernel is very hard.

Please, help me.

thanks.

#20 lore raw

1. the "-d" means where the "moddep.lst" is , so ,you should find it first.
2. It looks like you want to install grub in you PC, doesn't it? If does, you can use grub-install.
3. http://www.gnu.org/software/grub/manual/grub.html can help you.

Quoted 14 lines

When I command
sudo grub-mkimage -d ./grub-core -o core.img pc fat ntfs -O i386-pc

the result is
grub-mkimage: error: cannot open ./grub-core/moddep.lst.

When I command at /boot/grub, the result is same.

I can't understand why creating kernel is very hard.

Please, help me.

thanks.

#21 lore raw

Thank you very much, Cui Lei.
I find moddep.lst is in /boot/grub and /usr/lib/grub/i386-pc/. If I command as root in that folder, the result

grub-mkimage: error: cannot stat ./pc.mod.

please help me.

#22 lore raw
Quoted 8 lines · 김민준

Thank you very much, Cui Lei.
I find moddep.lst is in /boot/grub and /usr/lib/grub/i386-pc/. If I command as root in that folder, the result

grub-mkimage: error: cannot stat ./pc.mod.

please help me.

There should be no reason to use grub-mkimage directly on i386-pc platform. Please use grub-install, grub-mknetdir or grub-mkrescue depending on your goal. If your case isn't covered by any of them please explain what you're trying to do.

Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#23 lore raw
In reply to 김민준

the *.mod file should be in the same folder with the *.lst file.

Quoted 8 lines

Thank you very much, Cui Lei.
I find moddep.lst is in /boot/grub and /usr/lib/grub/i386-pc/. If I command as root in that folder, the result

grub-mkimage: error: cannot stat ./pc.mod.

please help me.

#24 lore raw

Yes. *.mod and *.lst file is in /boot/grub folder. But when I find the pc.mod in /, there are no pc.mod file.

Please help me.
I don't want to install grub, I want to make g2ldr.