Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Next: , Previous: Memory map, Up: Internals

D.2 Embedded variables in GRUB

Stage 1 and Stage 2 have embedded variables whose locations are well-defined, so that the installation can patch the binary file directly without recompilation of the stages.

In Stage 1, these are defined:

The version number (not GRUB's, but the installation mechanism's).
The boot drive. If it is 0xFF, use a drive passed by BIOS.
The flag for if forcing LBA.
The starting address of Stage 2.
The first sector of Stage 2.
The starting segment of Stage 2.
The signature (0xAA55).

See the file stage1/stage1.S, for more information.

In the first sector of Stage 1.5 and Stage 2, the block lists are recorded between firstlist and lastlist. The address of lastlist is determined when assembling the file stage2/start.S.

The trick here is that it is actually read backward, and the first 8-byte block list is not read here, but after the pointer is decremented 8 bytes, then after reading it, it decrements again, reads, and so on, until it is finished. The terminating condition is when the number of sectors to be read in the next block list is zero.

The format of a block list can be seen from the example in the code just before the firstlist label. Note that it is always from the beginning of the disk, but not relative to the partition boundaries.

In the second sector of Stage 1.5 and Stage 2, these are defined:

The version number (likewise, the installation mechanism's).
The installed partition.
The saved entry number.
The identifier.
The flag for if forcing LBA.
The version string (GRUB's).
0x12 + the length of the version string
The name of a configuration file.

See the file stage2/asm.S, for more information.

  Published under the terms of the GNU General Public License Design by Interspire