Making a bootloader for UEFI and BIOS at the same time.
Posted: Sat Dec 23, 2023 7:40 am
Hi ,
So I already have written my BIOS boot-loader that basically read a FAT16 filesystem and loads a file called "KERNEL.IMG" into memory and jumps to it. Now, I'm also interested into making my boot-loader compatible for UEFI. So, I grabbed a copy of debian.iso and looked at how partition were made as when as how the MBR and EFI partition where laid-out. From my understanding, they are using a hybrid-mbr kind of thing. I tried to look that up, and surprisingly, few results appeared during my research. I also saw that they were using "Xorriso" to make it boot with a CD.
I'm trying to wrap my head around that and assembling the parts, but I don't really understand how they managed to get it working.
How does the concept of hybrid-mbr works. I know that when a EFI BIOS boots, it reads the EFI tab partition and loads the bootloader, whereas a BIOS computer loads the mbr, executes the code of the boot-loader and that's it. But I'm having a hard time to image of both of them would work with a hybrid-mbr. Obviously two boot loader should be written (one for the BIOS and one for the UEFI) The only way I see them being "sort of connected", would be that they both read a FS, load the file and VOILA ! I'm not sure about that either..
If someone could possibly explain the process under the hood for example for GRUB (or any other UEFI-BIOS bootloader ) works and for example how debian used it to boot in BIOS and UEFI that would help trying to understand what's going on.
PS: I'm writing a boot-loader just to gain experience and better understand the lowest-level of a computer and nothing more, so reinventing the wheel is actually beneficial for me.
Thank you !
So I already have written my BIOS boot-loader that basically read a FAT16 filesystem and loads a file called "KERNEL.IMG" into memory and jumps to it. Now, I'm also interested into making my boot-loader compatible for UEFI. So, I grabbed a copy of debian.iso and looked at how partition were made as when as how the MBR and EFI partition where laid-out. From my understanding, they are using a hybrid-mbr kind of thing. I tried to look that up, and surprisingly, few results appeared during my research. I also saw that they were using "Xorriso" to make it boot with a CD.
I'm trying to wrap my head around that and assembling the parts, but I don't really understand how they managed to get it working.
How does the concept of hybrid-mbr works. I know that when a EFI BIOS boots, it reads the EFI tab partition and loads the bootloader, whereas a BIOS computer loads the mbr, executes the code of the boot-loader and that's it. But I'm having a hard time to image of both of them would work with a hybrid-mbr. Obviously two boot loader should be written (one for the BIOS and one for the UEFI) The only way I see them being "sort of connected", would be that they both read a FS, load the file and VOILA ! I'm not sure about that either..
If someone could possibly explain the process under the hood for example for GRUB (or any other UEFI-BIOS bootloader ) works and for example how debian used it to boot in BIOS and UEFI that would help trying to understand what's going on.
PS: I'm writing a boot-loader just to gain experience and better understand the lowest-level of a computer and nothing more, so reinventing the wheel is actually beneficial for me.
Thank you !