BIOS, UEFI, and the boot process explained
(note: this only applies to x86 PCs)
When your computer starts up, what does it do?
Well, the processor first loads a special firmware called the BIOS.
The BIOS is stored on a ROM chip that looks like this:
There are two types of BIOSes: legacy and UEFI.
The legacy BIOS is a type of BIOS that is used on older PCs.
UEFI is a newer type of BIOS hat has many advantages over the legacy BIOS.
How the legacy BIOS boots
After the BIOS has been loaded by the processor, it sets up a few interrupt services and other things. Then, it checks the first sector (bootsector) of all devices, including USBs and hard drives. It also checks CD/DVD drives, but they use something called El Torito. The bootsector is usually a bootloader, which reads an OS from disk and executes it. The bootsector must have a magic number
0xaa55 for it to be bootable. Examples are GRUB, SYSLINUX, and Windows Boot Manager.
Once the bootloader has finished loading, it starts reading from disk, and jumps to the address where the OS has been loaded.
How UEFI boots
The UEFI boot process is a bit more complicated.
Instead of just booting from the bootsector, it looks for something called an EFI application, which is usually a bootloader. An EFI application is a program that uses the UEFI APIs to do things. They are PE executables (I suspect that UEFI was created by Microsoft).
First, UEFI looks for EFI variables that are in the format of Boot#### e.g. Boot0000, which describe the UEFI menu entries.
Those variables contain data about each entry, and UEFI tries to boot from each entry.
If those fail, it starts looking for
\EFI\BOOT\bootia32.efi, depending on the machine architecture, on every drive it can find. Bootable UEFI drives should be formatted with FAT32 (a type of filesystem).
There is a special partition on computer adhering to UEFI, which is called the EFI system partition. This partition stores data for UEFI on the hard drive. Many bootloaders store their executables here. Once the bootloader has loaded, it does what it needs to do, and at the end tells UEFI to destroy the firmware environment.
I've explained here how your x86 PC usually boots. If you're interested you can read the OSDev wiki. The below repl is a demonstration of legacy BIOS booting.