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
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
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:

0x3E
The version number (not GRUB's, but the installation mechanism's).
0x40
The boot drive. If it is 0xFF, use a drive passed by BIOS.
0x41
The flag for if forcing LBA.
0x42
The starting address of Stage 2.
0x44
The first sector of Stage 2.
0x48
The starting segment of Stage 2.
0x1FE
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:

0x6
The version number (likewise, the installation mechanism's).
0x8
The installed partition.
0xC
The saved entry number.
0x10
The identifier.
0x11
The flag for if forcing LBA.
0x12
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