2

Things I've discovered so far (possibly inaccurate):

  • GRUB installs boot.img in the first sector (MBR) of a disk.

  • GRUB installs core.img in the post-MBR gap.

  • boot.img is loaded by BIOS and then loads core.img and transfers control to it.

But in the next step, how does core.img find the /boot partition? There may be multiple partitions on a disk so how does the core image correctly identify which is /boot? Is that hardcoded in the core image or does it do a search every time?

Additional research reveals there is a --boot-directory option in grub-install which lets you choose where to install GRUB. But the core image still has to find this partition at boot time. Again it needs some form of identifier. Is that a label, a UUID, or anything else?

5

The address is hard coded in core.img. core.img has all the kernel and Grub modules necessary to call the Stage 2 modules by file path. You specify this as (hd0,msdos1)/boot/grub. By default it'll try to load the normal module at (hd0,msdos1)/boot/grub/i386-pc/normal.mod (assuming i386-pc arch).

More details here.

  • @gilles thanks for the formatting edit! Though, I did mean 'kernel modules' not 'grub modules'. Stage 1.5 consists of: diskboot.img+kernel.img+pc.mod+ext2.mod (the core image), so it contains modules in the kernel that you need to initialize your disk controllers for example, this gets compiled in as well. Given that it contains both though, I'll propose an edit as 'kernel ad Grub modules' – psarossy Dec 28 '16 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.