Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does GRUB's stage 1 boot loader loads the stage 2 bootloader?

From the past week I am puzzled with the question that how the grub first stage boot loader which is only 446 bytes is able to search for the second stage, when the second stage is in a complex file system! How does it locate the second stage?

When a complex partitioning scheme of windows and linux is in place, and the linux system is entirely in the extended partition, then how does the stage 1 finds the stage 2? Even stage 1.5?

All of the grub tutorials skim through this important part. I have searched though the internet but couldn't find anything that explains this. Sadly, I am not an assembly programmer.

I want to understand the boot process intricately in terms of which sectors of the hard disk are tickled (and roughly how) during bootup. *Please point me to a good resource or answer here. It will greatly help me to play with grub wisely.*

Some Resources Searched:

  1. How Linux Works : What every superuser should know by Brian Ward
  2. http://www.dedoimedo.com/computers/grub.html
  3. some past stackoverflow questions.
like image 796
codeman48 Avatar asked May 10 '13 12:05

codeman48


1 Answers

Stage 1 "knows" where Stage 2 is by entries in a block-list loading table embedded in it. It loads the lists of blocks off of the booting drive, then jumps to a specified CS:IP in 16-bit real mode. These are described in the page on embedded data. It queries the BIOS for the disk geometry, and maps the linear block numbers there to C:H:S addresses used by the INT 13h BIOS interface.

http://www.uruk.org/orig-grub/technical.html

Also a lot of time with new disk alignment, there is just under 1-2 MB of unallocated space between the MBR and the first partitions and stage 2 is sometimes stuck there.

like image 102
WorBlux Avatar answered Sep 30 '22 17:09

WorBlux