In a dual boot system, how does the BIOS choose which bootloader to run?
BIOS firmware doesn't really choose the bootloader. It loads code from sector 0 of a drive and executes it. Whatever is there, it will execute. Hopefully it is a bootloader (or something that loads a bootloader) but it doesn't have to be. In the early PC days you had games on floppy disks that would simply boot and run without an OS - these are now called "booters."
UEFI firmware actually understands partitions and filesystems, and scans drives for a UEFI System partition type. Since this is a filesystem, multiple bootloaders can be placed here. UEFI firmware is supposed to provide a menu or other way for you to select which bootloader is used.
Many UEFI systems are booting in "Legacy mode" - where the UEFI loads a "Compatibility Service Module" - something that makes it look like a BIOS - and actually work like the BIOS.
GRUB is a common open-source bootloader that can either boot Linux or "chainload" (give control to) a Windows bootloader (typically winload.exe in the Boot folder of a Windows partition). GRUB is what's giving you the ability to make a decision. GRUB can read configuration files and take its default choice from them.
Read this if you want copious, gory details.
This diagram shows how control passes from the firmware (BIOS or UEFI) to the bootloader and from the bootloader to the operating system in Ubuntu.
BIOS vs. UEFI
If the OSs were installed in different modes (BIOS and UEFI), dual booting Windows and Ubuntu with grub can't work. In some computers that have Windows pre-installed there is an option to boot Windows in the UEFI setup utility.
Converting Ubuntu into UEFI mode
- Start Boot-Repair, and select Advanced options -> GRUB location tab.
- If you do not see a Separate /boot/efi partition option, this means that your PC does not have any UEFI partition.
- If you see a Separate /boot/efi partition option, put a checkmark in the checkbox to the left of it.
- Click the Apply button in the lower right corner.
- Set up your BIOS so that it boots the hard drive in UEFI mode. The way to adjust this setting depends on the specific model of the computer, but generally this setting is located in the boot priority settings under the Boot tab of the BIOS/UEFI setup utility.
Alternatively you can convert an existing Ubuntu installation from BIOS mode to UEFI mode from the terminal in a live Ubuntu USB session which was booted in UEFI mode by following the instructions in this answer.
Converting Ubuntu into BIOS mode
Note: Use this procedure only to convert an UEFI mode Ubuntu installation to boot in BIOS/CSM/legacy mode. Such a conversion may be necessary if some hardware doesn't work correctly under UEFI mode. (Graphics cards are a common source of problems.) Converting to boot in BIOS/CSM/legacy mode while Windows boots in UEFI mode can make the boot process more awkward -- you'll need to use the computer's built-in boot manager to switch between OSs, and some computer's have such poor boot managers that this may be impossible.
- If Ubuntu is installed on a GPT disk (you can check it via the
sudo parted -l
command), use GParted partition editor to create a BIOS-Boot partition (1MB, unformatted filesystem, bios_grub flag) at the start of its disk. - Start Boot-Repair, and select Advanced options -> GRUB location tab.
- Uncheck the Separate /boot/efi partition option
- Click the Apply button in the lower right corner.
- Set up your BIOS so that it boots the HDD in Legacy mode. Generally this setting is located in the Boot tab → Boot order section of the BIOS.
Converting Windows into GPT mode
MBR2GPT.exe is a command line tool which is located in the System32 folder in Windows 10. With it you can effectively and non-destructively convert a Windows 10 OS disk from MBR (for Legacy BIOS) to GPT partition style (for UEFI) without modifying/deleting any data on the disk or making a clean installation of Windows 10.
Links:
- UEFI - Community Help Wiki, Converting Ubuntu into UEFI or Legacy mode
- Convert from EFI to BIOS boot mode