In a dual boot system, how does the BIOS choose which bootloader to run?

26,293

Solution 1

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.

Solution 2

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.

enter image description here
          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

  1. Start Boot-Repair, and select Advanced options -> GRUB location tab.
  2. If you do not see a Separate /boot/efi partition option, this means that your PC does not have any UEFI partition.
  3. If you see a Separate /boot/efi partition option, put a checkmark in the checkbox to the left of it.
  4. Click the Apply button in the lower right corner.

Converting Ubuntu into UEFI mode

  1. 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

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:

Solution 3

In legacy mode (BIOS boot and not UEFI) BIOS controls the drive order. Once upon a time this used to be controlled by the cables; but changing a BIOS setting beats opening the box & changing cables.

BIOS loads (into memory) the first sector (512 bytes of disk called MBR or master boot record) of the first disk (or drive order controlled by BIOS) and then passes (CPU) control to this 'bootloader'. BIOS has thus completed its job and the code in the first sector runs.

Share:
26,293

Related videos on Youtube

Prashant Singh
Author by

Prashant Singh

Updated on September 18, 2022

Comments

  • Prashant Singh
    Prashant Singh over 1 year

    I have a dual boot of Windows and Ubuntu. When I switch on the machine, the BIOS does POST and after that the bootloader starts.

    I want to understand how the BIOS chooses which bootloader to run. I want to know the process going on between the BIOS and the bootloader in a dual boot computer.

  • Prashant Singh
    Prashant Singh over 6 years
    SORRY sir but i am bit confuse as bios give control to the boot loader and window and linux have different boot loader so to which boot loader it give control .what process bios go through to choose the boot loader
  • guiverc
    guiverc over 6 years
    Your system can only have a single boot loader per disk (and only one is ever active). Generally, if you have two operating systems on your system, the second one installed owns the boot-loader as it wrote its own code into the MBR. This is why GNU/Linux (Ubuntu) uses GRUB; its a multi-step system (step 1 is the MBR, steps 1.5 & 2 are found in /boot) that puts up menu asking which OS you want to load/run (the ones grub knows about anyway, plus whatever ISO's you've added to it). If you have two disk drives; you can have a boot loader on each drive, but BIOS will determine which will run.
  • Prashant Singh
    Prashant Singh over 6 years
    So if i have 2 operating system in my computer then is it necessary that GRUB will put up the menu asking which os i want to load why not window's boot loader put that menu as i have both os in my computer.
  • guiverc
    guiverc over 6 years
    windows has a boot loader too (up to vista anyway); but its not as smart as grub is. the windoze version doesn't search for non-msft products (and can't read ext/reiserfs/xfs/zfs/btrfs/...) thus has you have to add the *nix yourself; and next update ..... the windoze version isn't worth using as grub is so much better. If windoze was on one drive, Ubuntu on the other you could alter the boot by BIOS; but grub is faster/easier. (if happy with my answer; accept it to close the question)
  • Prashant Singh
    Prashant Singh over 6 years
    thank you , now i get the picture what is happening during booting process .
  • rcgldr
    rcgldr over 6 years
    @PrashantSingh - on a multi-boot system where all of the operating systems are some version of Windows, then the native Windows multi-boot option will work. On my system, I had 4 Windows systems, Win XP Pro (32 bit), Win XP X64 (64 bit), Win 7 Pro (64 bit), and Win 10 Pro (64 bit) (this only works because my hardware components are old enough to have drivers fro Win XP and new enough to have drivers for Win 10).
  • jamesqf
    jamesqf over 6 years
    @Prashant Singh: The most fundamental reason why the Windows bootloader doesn't do this (or didn't, back when I knew a bit about Windows) is that MicroSoft doesn't make money by letting you run other operating systems.
  • wizzwizz4
    wizzwizz4 over 6 years
    This is one of the reasons that, on Ubuntu, you need sudo or root to write anything to an unmounted disk; if a program or malicious user writes malware to the boot partition...
  • Prashant Singh
    Prashant Singh over 6 years
    Thanks LawrenceC your explanation make my understanding more clear .thanks once again
  • Prashant Singh
    Prashant Singh over 6 years
    @guiverc : tell me if i have 2 OS then i have 2 MBR recordand if it is possible then Bios go where first in MBR 1OS or MBR 2OS.
  • Prashant Singh
    Prashant Singh over 6 years
    @guiverc :sir you stated that GRUB stage 1 is the MBR but BIOS go to the MBR First then choose Boot loader so how GRUB stage 1 is the MBR.
  • guiverc
    guiverc over 6 years
    a drive can only have a single MBR (the first 512byte sector of the disk, or first sector of LBA 0) which is the reason if you have two drives you can have two, three drives you can have three with the bios controlling the order of the drives (the first active drive has its mbr used). so MBR is stuck at one per drive. grub stage 1 is limited to 512 bytes as it has to fit in that first sector (the MBR). later stages of grub are in files on the fs.
  • guiverc
    guiverc over 6 years
    bios can only control which MBR is used by controlling which drive is drive=0 (or active). EUFI has replaced MBR for recent x86_64 anyway. But MBR was a easy boot rule: load registers with 0 (sec=0,trk=0,head=0,drive=0); load that sector; then run the loaded code.... with no [security] validation...