1
$\begingroup$

Again, I must apologize if this is "easily googlable". I have tried.

My understanding is that the BIOS typically looks for the magic number 0x55aa at the end of a 512 byte sector (so bytes #511 and #512). Once it finds that, it begins executing that code. That code can then load the operating system. It finds this by checking all bootable disks/drives until it finds that sector, right?

I wrote a simple boot sector, and verified this mechanism on qemu and bochs.

My question is in regard to GRUB. Does BIOS find GRUB in the same way that it finds the boot sector I wrote? I did a hexdump on the binary GRUB file and was unable to find the magic number 0x55aa at the end of a 512 byte sector

Another way to ask the question, which really highlights my lack of understanding, would be as follows:

What is the purpose of the magic number 0x55aa in relation to BIOS and the booting process? What is the purpose of the magic number 0x1BADB002 in relation to GRUB and the booting process? Additionally:

  • Does BIOS locate boot loaders via the magic number 0x55aa? If not, what does it locate with that magic number? My understanding was that the boot sector is the sector that contains the boot loader code, and that sector need have the magic number 0x55aa.

I really felt like I was understanding everything writing my own boot sector in 16-bit real mode, entering 32 bit protected mode, and bootstrapping to C. Then when I learned about GRUB I felt like I don't understand anything anymore. i tried to read and google, please help

Much love!

pls let me know if im thinking about this wrong

$\endgroup$

1 Answer 1

2
$\begingroup$

It depends on what grub binaries you look at for finding the 0x55aa signature. GRUB has several files and has to be installed in several steps before it can be used.

The boot sector is meant to be the first sector of an hard-disk. It just happens that, with QEMU, you can specify any file type to be the hard-disk. This is a really great functionality because it allows to create a raw virtual hard-disk with dd.

When you boot with GRUB legacy, the first sector is loaded at 0x7c00 in RAM. This sector's code then uses the legacy BIOS services to load the second stage of GRUB to RAM and jumps to it.

Today, GRUB is an EFI app that is compiled probably by gcc using the gnu-efi framework. The UEFI firmware interprets a FAT32 hard-disk partition and jumps to the main function of /boot/efi/bootx64.efi. This executable is in the PE (Portable Executable) format.

$\endgroup$
2
  • $\begingroup$ "It depends on what grub binaries you look at for finding the 0x55aa signature. GRUB has several files and has to be installed in several steps before it can be used." Thank you so much for this answer. The implication is that the signature DOES exist, right? It has to, right? Thanks so much!!! $\endgroup$
    – prss98408
    Mar 13 at 16:12
  • $\begingroup$ Yes it must have the signature. Otherwise, the BIOS flags it as non-bootable. $\endgroup$
    – user123
    Mar 13 at 16:42

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.