Summer_More_More_Tea Summer_More_More_Tea - 6 months ago 36
Linux Question

Where does code of GRUB stage 1.5 reside on disk and what is the address it is loaded?

I have

grub v1.98
installed and after disassembling the MBR I find the following code snippet that I don't understand:

xor ax,ax
mov [si+0x4],ax
inc ax
mov [si-0x1],al
mov [si+0x2],ax
mov word [si],0x10
mov ebx,[0x7c5c]
mov [si+0x8],ebx
mov ebx,[0x7c60]
mov [si+0xc],ebx
mov word [si+0x6],0x7000
mov ah,0x42
int 0x13

It seems this piece of code tries to set up disk address of stage 1.5 code, then load and run it. However, how could I figure out which physical block it tries to read? What's more, what is the destination of the stage 1.5 code?

I refer to MBR for Windows 7, where subsequent boot up code is loaded
. Given MBR is first loaded at address
, it contains a piece of code copying MBR from
and then branch to
in case the original code corrupted. Will loading stage 1.5 code to address
conflict the original code? What's more, I also find:

jmp short 0x65
sar byte [si+0x7c00],1
mov es,ax
mov ds,ax
mov si,0x7c00
mov di,0x600
mov cx,0x200
rep movsb
push ax
push word 0x61c

at the beginning of the MBR. It seems the code tries to do the same thing as in MBR of windows 7 to copy the original MBR from
, except for the first
instruction. Will these codes in fact executed? If yes, when will control jumps here.(I believe the answer is YES, but am confused by the leading

Answer Source

GRUB 1.98 is GRUB version 2. In version 2, there is no stage 1.5 anymore. The stage 1.5 had a fixed place between MBR and first partition. It was (most often) unused space on the hard drive. GPT partitioning and other (unusual) layouts do not provide this space.

In GRUB v2 stage 1 loads core.img, which can be stored at any LBA48 location, typically between MBR and first partition, but it can also be stored within a partition. In the non-EFI case of GPT, a custom partition should be created for it. The location is hardwired into stage 1.

See also:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download