Skip to contentSkip to conversation

grub-install

DISCUSSION Yoshinori K. Okuji 5 participants 17 messages Jul 24, 2005 – Jul 26, 2005

lore
Share & tools
lore
#0 lore raw

I have mostly implemented grub-install as a shell script. I just copied it from GRUB Legacy then adapted it to GRUB 2. This script is much simpler in GRUB 2, because grub-setup handles most things.

It has one remaining issue, and I'm not sure what is appropriate for this. Since the core image in GRUB 2 is generated dynamically, it is necessary to specify what modules should be included in it. When the user uses grub-install, I believe that they should be automatically determined.

For now, pc.mod and _chain.mod are hardcoded. I think these are good enough for PC. It might be better to add _linux.mod on GNU/Linux, though. I'm not sure.

The issue is how to determine a filesystem module which is needed to load more modules. I think there are three ways:

1. Shell scripting. Probably it is possible to write a shell function which detects a filesystem by using df, mount, etc. I do not like this approach very much, because the installation environment can be very minimalistic (suppose when you install an OS using a floppy), and the behaviors of commands are sometimes not clever enough.

2. Adding an option into grub-mkimage to add a filesystem module automatically, depending on the filesystem of a grub directory. This is not bad, but this makes grub-mkimage a bit complex.

3. Adding a new utility which detects an appropriate filesystem module for a given directory. This is not bad, but this sounds a bit overkill.

What do you think?

Okuji

#1 lore raw
Quoted 3 lines · Yoshinori K. Okuji

I have mostly implemented grub-install as a shell script. I just copied it from GRUB Legacy then adapted it to GRUB 2. This script is much simpler in GRUB 2, because grub-setup handles most things.

Great! This is something we still need to do on PowerPC before grub2 is generally usable...

Quoted 4 lines

It has one remaining issue, and I'm not sure what is appropriate for this. Since the core image in GRUB 2 is generated dynamically, it is necessary to specify what modules should be included in it. When the user uses grub-install, I believe that they should be automatically determined.

Is there a reason not to add all modules all the time?

-Hollis

#2 lore raw
Quoted 1 line · Hollis Blanchard

Is there a reason not to add all modules all the time?

I should have written more info in English. This is documented well, but only in Japanese.

There are several reasons. In the context of i386-pc:

- The size problem. We must keep the core image at least 31KB, so that we can embed it into the space right after the MBR. This is the most important reason. Very specific to i386-pc. I have no idea if other architectures have similar restrictions, but probably they do.

- The loading time. Potentially, the number of modules is infinite in GRUB 2.

- Conflicts. For now, we do not have multiple modules which provide the same functionality, but it is one of the goals of modules to make this possible.

- Runtime slowness. For example, if I load amiga partition map support, this makes apparently it slower to access partitions in QEMU.

- Hardware probing. In particular, probing ISA ethernet devices which are not present in a system frequently causes a system crash or a too long timeout.

Actually, many reasons are the same as "why we don't make initrd with all modules of linux" or "why we don't build all features into linux".

Okuji

#3 lore raw
Quoted 11 lines · Yoshinori K. Okuji
Quoted 1 line · Hollis Blanchard

Is there a reason not to add all modules all the time?

I should have written more info in English. This is documented well, but only in Japanese.

There are several reasons. In the context of i386-pc:

- The size problem. We must keep the core image at least 31KB, so that we can
embed it into the space right after the MBR. This is the most important reason. Very specific to i386-pc. I have no idea if other architectures have similar restrictions, but probably they do.

In case others don't know the reason for "31KB":

As can be seen in the attached common linux disk layout diagram, the optional DOS compatability region used by stage 1.5 is added by default by most partition managers, and is there so that partitions start on a cylinder boundry. Therefore its size is determined by the number of sectors (512 bytes) per cylinder. The maximum sectors per cylinder is 64, and so the largest size available for grub's stage 1.5 is 63 * 512, or 32256 bytes.

Pádraig.

#13 lore raw
In reply to Yoshinori K. Okuji
Quoted 2 lines · Yoshinori K. Okuji

3. Adding a new utility which detects an appropriate filesystem module for a given directory. This is not bad, but this sounds a bit overkill.

It's not *that* hard to write. Just probe the filesystem using modules until one works. For that module loading is required which can be done in GNU/Linux. The main problem is that you need to use mmap to get executable memory (which is OS specific) and the other problem are the relocations, the allocated memory needs to be close to the executable on the PPC.

How is the correct stage1.5 selected in GRUB Legacy?

--
Marco

#15 lore raw
In reply to Yoshinori K. Okuji

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 2 lines · Yoshinori K. Okuji

When the user uses
grub-install, I believe that they should be automatically determined.

...while the choice could be completely overridden, and maybe making possible to choose manualy some modules.

Quoted 3 lines

For now, pc.mod and _chain.mod are hardcoded. I think these are good enough for PC. It might be better to add _linux.mod on GNU/Linux, though. I'm not sure.

Good idea to add _linux.mod, if it (adding) can be disabled.

Quoted 2 lines

3. Adding a new utility which detects an appropriate filesystem module for a given directory. This is not bad, but this sounds a bit overkill.

I prefer that solution. I think grub-mkimage should only 'know' how to make an image from modules, another tool telling it which ones to add. And I think that "other tool" should be grub-install.

Vincent Pelletier
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFC5OPwFEQoKRQyjtURAo+1AJ9OLTTDRAvJRJ2rNiu0rg3sXkmOMwCZAXhT +eVXyfuvUtsGsxSZJSHdeg0=
=GNoV
-----END PGP SIGNATURE-----

___________________________________________________________________________
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger Téléchargez cette version sur http://fr.messenger.yahoo.com

#7 lore raw
In reply to [email protected]
Quoted 10 lines · On Jul 25, 2005, at 6:26 AM, [email protected] wrote:
Quoted 6 lines · Yoshinori K. Okuji
Quoted 1 line · Hollis Blanchard

Is there a reason not to add all modules all the time?

I should have written more info in English. This is documented well, but only in Japanese.
There are several reasons. In the context of i386-pc:
- The size problem. We must keep the core image at least 31KB, so
that we can embed it into the space right after the MBR. This is the most important reason. Very specific to i386-pc. I have no idea if other architectures have similar restrictions, but probably they do.

In case others don't know the reason for "31KB":

Quoted 7 lines

As can be seen in the attached common linux disk layout diagram, the optional DOS compatability region used by stage 1.5 is added by default by most partition managers, and is there so that partitions start on a cylinder boundry. Therefore its size is determined by the number of sectors (512 bytes) per cylinder. The maximum sectors per cylinder is 64, and so the largest size available for grub's stage 1.5 is 63 * 512, or 32256 bytes.

This is for GRUB Legacy, right? There is no "stage 1.5" In GRUB2? What is the new layout?

-Hollis

#8 lore raw
Quoted 10 lines · Hollis Blanchard
Quoted 9 lines

In case others don't know the reason for "31KB":

As can be seen in the attached common linux disk layout diagram, the optional DOS compatability region used by stage 1.5 is added by default by most partition managers, and is there so that partitions start on a cylinder boundry. Therefore its size is determined by the number of sectors (512 bytes) per cylinder. The maximum sectors per cylinder is 64, and so the largest size available for grub's stage 1.5 is 63 * 512, or 32256 bytes.

Quoted 2 lines

This is for GRUB Legacy, right? There is no "stage 1.5" In GRUB2? What is the new layout?

You are right. In GRUB 2 there is no stage 1.5 and stage2. In GRUB 2 there is a core image. It mainly consists of the stuff in kern/, some stuff from disk/i386/pc, term/i386/pc. Using that is can load modules.

The core image with some modules replace stage 1.5. So the main core of GRUB together with some important modules are stored in this 31KB. Because this space is limited not every module can fit in there. Most importantly is the filesystem module. It is used to load other modules from that filesystem.

So an example of a boot process is:

- The BIOS loads the GRUB2 (boot.img) as it is stored in the MBR

- GRUB2 in the MBR loads that 31KB into memory and jumps to it

- That 31KB consists of the kernel (kernel.img) and some raw modules

- The kernel (rescue mode) starts and loads every module

- Rescue mode tries to load normal.mod

- If normal.mod can be found on the prefix path it is loaded

- Normal mode looks for grub.cfg on the prefix path and loads it

- The menu is shown and the user can choose an OS to boot

It is possible to load additional modules so other filesystems can be accessed, other loaders can be used, etc. On the PC a nice set of modules is: pc.mod (for partition access), _chain.mod (rescue mode chainloader), ext2.mod. Of course ext2.mod is for the case that you want to load normal.mod and other modules from an ext2 filesystem.

I hope this e-mail made clear how GRUB 2 basically works on the PC. I am not a PC expert and my English is not that good. Hopefully someone can and will correct me if I was wrong so I will understand things better. Hopefully Hollis' question is answered.

Thanks,
Marco

#16 lore raw
In reply to Vincent Pelletier
Quoted 2 lines · Vincent Pelletier

...while the choice could be completely overridden, and maybe making possible to choose manualy some modules.

Good idea.

Quoted 1 line

Good idea to add _linux.mod, if it (adding) can be disabled.

OK.

Quoted 3 lines

I prefer that solution. I think grub-mkimage should only 'know' how to make an image from modules, another tool telling it which ones to add. And I think that "other tool" should be grub-install.

OK. That sounds reasonable. I follow this.

Okuji

#9 lore raw
In reply to Marco Gerards
Quoted 7 lines · Marco Gerards

So an example of a boot process is:

- The BIOS loads the GRUB2 (boot.img) as it is stored in the MBR

- GRUB2 in the MBR loads that 31KB into memory and jumps to it

- That 31KB consists of the kernel (kernel.img) and some raw modules

In details, the core image consists of diskboot.img, kernel.img then zero or more modules. boot.img loads only the first sector (diskboot.img) from a disk, and diskboot.img loads the rest of the core image.

In the case of PXE, pxeboot.img is prepended to the core image, and simply jumps to the start address in kernel.img, because PXE ROM loads the whole core image from a network.

Quoted 1 line

- The kernel (rescue mode) starts and loads every module

The kernel initializes the system briefly, and decompresses the compressed part of the core image. After this, the kernel loads all pre-loaded modules from the memory.

Quoted 4 lines

I hope this e-mail made clear how GRUB 2 basically works on the PC. I am not a PC expert and my English is not that good. Hopefully someone can and will correct me if I was wrong so I will understand things better. Hopefully Hollis' question is answered.

Your description is really good.

Well, the bootstrap on i386-pc is complicated, because PC BIOS sucks. On other architectures, this can be simplified very much.

Okuji

#14 lore raw
In reply to Marco Gerards
Quoted 1 line · Marco Gerards

It's not *that* hard to write.

Not hard at all. It is a design problem but not an implementation problem.

Quoted 1 line

How is the correct stage1.5 selected in GRUB Legacy?

Very ugly. The function install_func includes a list of pairs, where each pair consists of a filesystem name and a Stage 1.5 name.

Okuji

#5 lore raw
In reply to [email protected]
Quoted 7 lines · [email protected] wrote:
Quoted 1 line · [email protected] wrote:

As can be seen in the attached common linux disk layout diagram,

sigh, that 16KiB in the diagram should be 32KiB.
Anyway you get the idea...

Actually do we have 32,256 bytes to use?
I was wondering about sectors 62 & 63 (counting from 0). On my laptop (that had windows wiped the minute I got it), I notice that there is a MSWIN4.1 boot record in sector 63 (I think it actually flows over the next 2 sectors also). So can we generally use that? I.E. does grub provide all the functionality of that sector?
Also sector 62 has the following? Is that BIOS suspend to disk info or something, or maybe something left over from the windos install?

# dd count=1 skip=62 if=/dev/hda 2>/dev/null | od -Ax -tx1z
000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
*
0000c0 67 68 46 50 b6 96 ca 3e bb 35 eb 3d 32 54 4f 53  >ghFP...>.5.=2TOS<
0000d0 48 49 42 41 00 33 00 00 00 00 00 00 00 00 00 00  >HIBA.3..........<
0000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
*
000100 00 00 00 00 00 00 00 00 00 34 33 4d 35 33 36 38  >.........43M5368<
000110 39 54 00 00 00 00 00 00 00 00 00 00 00 54 4f 53  >9T...........TOS<
000120 48 49 42 41 20 4d 4b 32 30 31 38 47 41 53 00 00  >HIBA MK2018GAS..<
000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
*
000200
Signature · 2 lines
Pádraig Brady - http://www.pixelbeat.org
--
#10 lore raw
In reply to Yoshinori K. Okuji

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 2 lines · Yoshinori K. Okuji

Well, the bootstrap on i386-pc is complicated, because PC BIOS sucks. On other architectures, this can be simplified very much.

I'm afraid a stage 1 -like thing will be needed on usparc. I have found few docs about the actual implementation of the disk boot process on usparc, but it sounds like "load the second sector of disk, and run it" (the first sectors is filled with the partition table). I still have no success in making a bot floppy "by hand" (parted/fdisk + dd). I get a magic number error, while the crc in the partition table should be correct. I'll check that when I have more time, in 3~4 weeks.

Vincent Pelletier
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFC5oPlFEQoKRQyjtURAmpjAJ98vU2sF3Gb+P/sLbrxu8lLCkktuACgkGKr H5u+iuo/4eX1Ui91mJJxjXw=
=6LrZ
-----END PGP SIGNATURE-----

___________________________________________________________________________
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger Téléchargez cette version sur http://fr.messenger.yahoo.com

#6 lore raw
In reply to [email protected]
Quoted 4 lines · On Tuesday 26 July 2005 15:13, [email protected] wrote:

I was wondering about sectors 62 & 63 (counting from 0). On my laptop (that had windows wiped the minute I got it), I notice that there is a MSWIN4.1 boot record in sector 63 (I think it actually flows over the next 2 sectors also).

It is just a trace of the Windows boot sector. Once you remove Windows, it is a garbage.

Quoted 3 lines

Also sector 62 has the following? Is that BIOS suspend to disk info or something, or maybe something left over from the windos install?

I don't know. If you are afraid, you can try to fill that with zero (after making a backup) and see what happens.

Okuji

#11 lore raw
In reply to Vincent Pelletier
Quoted 1 line · Vincent Pelletier

I'm afraid a stage 1 -like thing will be needed on usparc.

You are right. On SparcStation, the firmware loads only 512 bytes like PC as a boot sector. So you need to make boot.img separately. The difference is that there is no "safe place" in SparcStation, and you can choose a sector to be loaded in the firmware. You can get some information from the web site of SILO:

http://www.sparc-boot.org/how.html

Quoted 7 lines

I have found
few docs about the actual implementation of the disk boot process on usparc, but it sounds like "load the second sector of disk, and run it" (the first sectors is filled with the partition table). I still have no success in making a bot floppy "by hand" (parted/fdisk + dd). I get a magic number error, while the crc in the partition table should be correct. I'll check that when I have more time, in 3~4 weeks.

Which model do you have? I hear that most UltraSparc models cannot boot from a floppy due to a bug in OpenBoot. Therefore, when I installed GNU/Linux into a UltraSparc machine, I used netboot.

Okuji

#12 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 3 lines · Yoshinori K. Okuji

Which model do you have? I hear that most UltraSparc models cannot boot from a floppy due to a bug in OpenBoot. Therefore, when I installed GNU/Linux into a UltraSparc machine, I used netboot.

I have an Ultra 10 (looking for an U80, with 4*450Mhz USparc II... quite expensive, but I can't get it out of my head :) ). I've heard of this bug, I'll have to test it with a reference floppy. I did some tests with a spare HD I used to hack grub 2, and I had the same error, but it might be another problem.
I used netboot to start the port, it works great with ELF64 unstripped binaries.

Vincent Pelletier
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFC5pWCFEQoKRQyjtURAmV6AJ9ncgVwA8ezoZ1BD3snBzl06+9Z5ACgouLF IvakTTvdLqFUGLfkWTZ5zUU=
=tFDa
-----END PGP SIGNATURE-----

___________________________________________________________________________
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger Téléchargez cette version sur http://fr.messenger.yahoo.com