12

When I turn on my computer, what is the software that selects which operating system to boot, and how does it decide when given multiple options?

More specifically, what if I have a computer with multiple operating systems living on the same disk? And what if I have external drives - does it search every partition across all storage devices for formats that it recognizes?

From my understanding every disk has its own boot sector that contains information on which partition the computer should boot. But what if I have multiple disks attached, where each disk has a different boot sector - which one does it load?

When trying to research this topic, I've run into some confusion since not all technologies behave the same (e.g. some say that the bootable flag is important while others say it is ignored). Some clarity in how different systems work would be much appreciated.

1
  • 1
    More details on the old BIOS boot. If UEFI set for CSM - CSM - UEFI Compatibility Support Module (CSM), which emulates a BIOS mode, only available with secure boot off, it also applies. multibooters.com/guides/visual-guide-to-the-boot-sequence.html Windows requires boot flag for its boot code in MBR to find the boot partition. Grub does not use boot flag. With UEFI most partition tools use boot flag to assign the ESP - efi system partition, so you cannot have BIOS boot with Windows on same drive as UEFI boot.
    – oldfred
    Commented Mar 22, 2020 at 13:47

7 Answers 7

16

Unfortunately this has become more complex as computers have evolved.

Initially (ie the first PC's) there was a fixed order (which depended on cabling).

Almost all computers still have a default boot order which can be controlled/influenced by the BIOS. Newer computers supplement this functionality with UEFI, which in some ways supercedes the BIOS.

For BIOS booting there is a preferred order. The BIOS looks at each drive for bootable boot sectors, and will attempt to load these, going down its list of options until one boots.

For UEFI there is a filesystem on the disk, (a small fat partition labeled as UEFI which contains a first stage boot loader and instructions. In some cases this is supplemented by instructions programmed into the UEFI (ie settings stored in nvram similar to the BIOS)

Once a boot loader/UEFI partition has been found, a program takes over the boot process, and this may offer the ability to boot into different modes or OSs.

6
  • Do you have links that explain the UEFI process in very simple terms, and a comparison to the older BIOS boot procedure? I understand the BIOS and MBR method for the most part, but everything I could find about UEFI was too complicated. Are EFI/UEFI the same thing? Most articles that talk about UEFI bring up something called "information in the NVRAM". Does the NVRAM mean the BIOS? Or is there a permanent memory besides the BIOS on a motherboard that supports UEFI booting?
    – user13267
    Commented Mar 23, 2020 at 1:24
  • @user13267 These questions are slightly past the edge of my knowledge - I believe UEFI is the newer version of EFI, so effectively the same thing. As I understand it, BIOS is different from UEFI booting, so no, NVRAM does not mean BIOS. I get the distinct impression that this is stored in the same type of memory (probably on the same chips) as the BIOS. I think the UEFI process itself supports the booting, and is analogous to the BIOS, but hands off to a disk or external memory earlier, and in a more flexible way.
    – davidgo
    Commented Mar 23, 2020 at 2:14
  • @user13267 UEFI is an updated version of EFI after the inventors of EFI donated EFI to the UEFI (Unified EFI) forum and stopped updating EFI themselves. So, yes, UEFI is the modern EFI. NVRAM means "Non-volatile RAM" which, unlike most bytes of RAM, does not lose data when power is turned off. This stuff is more expensive, so instead of having all your RAM be NVRAM, such NVRAM is typically used to store smaller amounts of data, like configuration details storing information about how you want your system started.
    – TOOGAM
    Commented Mar 23, 2020 at 12:49
  • BIOS is "Basic Input/Output System". For years, "IBM Compatible" systems used compatible BIOS code which some operating systems relied upon. When EFI was released, the statement was "this is not BIOS" because EFI was largely incompatible with other existing popular BIOS implementations. So the term "BIOS" started to clearly refer to the standard ways that older BIOS worked. But some motherboard referred to EFI as a BIOS (e.g., "dual BIOS" options) . As is, the waters are really muddy. Whether EFI is a BIOS or not depends on what a BIOS is, so there is not universal agreement to this question
    – TOOGAM
    Commented Mar 23, 2020 at 12:53
  • 2
    @TOOGAM do you have a link that explains all of this in simple, possibly layman terms with diagrams?
    – user13267
    Commented Mar 24, 2020 at 0:44
6

As others said, it's become a bit complicated, but the way I understand it:

When the computer is first powered on, it's not your hard drives at all that matter. There's a special piece of software in a chip on the motherboard which gets loaded first and the CPU starts to execute that. This is known as BIOS or UEFI (UEFI is actually the successor of BIOS).

This code does a bit of work initializing various parts of hardware and then starts to look for the next thing to pass control to. Now, what exactly that will be depends on a lot of things. There are many possible options - your internal hard drives, your external drives, network adapters, RAID controllers, add-on cards, etc.

BIOS/UEFI also has settings that determine the order in which to check these options. It will go through each one of them in the configured order and ask - "can you continue to boot?" And the device will either say "yay" or "nay". The first one that says "yay" gets to continue. That device then gives BIOS a piece of code which is loaded in memory and the CPU continues the execution with that.

In the particular case of a hard drive, the disk itself doesn't really know if it can boot or not. So what the BIOS does is that it reads the very first sector (512 bytes classically) of the drive and checks for a special few bytes in a certain location of the sector. If they contain the value 55 AA (in hexadecimal), then this sector is executed as code. Otherwise it moves on to check the next disk.

Now, 512 bytes isn't a lot of space, but it's enough to do a few simple things. For example, classical DOS put a bit of code in there which found a partition marked as "bootable", then loaded the first sector of that partition and then executed that. And that next sector contained enough code to load a few more sectors, and then start parsing the file system, and load files from that, and so on and so forth.

But really, there is nothing that says what this code must do. It could also not load the active partition, but some other sectors on the disk where more code resides. And that code then could give you a menu which allows selecting among multiple bootable partitions or OSes or whatever.

Anyways, the code in the first sector of the drive is known as "bootloader". There are different bootloaders out there. The Linux world these days leans heavily on grub, Windows has its own thing, etc. The bootloader really comes before the operating system, but it does need to know how to load the operating system into memory and give control to it.

Does this make it clearer?

4

On startup, your motherboard will power all (or most) electronic components attached to it. One of them is your hard drive or SSD, called the system drive, because the primary operating system is on it. Unless you've set your BIOS or (U)EFI to boot from a different, external drive, be it USB, FireWire or network, that's the drive that'll be used first.

On this drive, there is a master boot record partition (to simplify) that's usually read-only (can be edited via the bcdedit.exe set of commands, though), and it will review all available OSes on the drive. One has been set as default, either by you, or by itself when installed, either in factory or when you reinstalled/upgraded your main OS.

Windows doesn't allow your booting from a USB hard drive or SSD. You can boot on a USB key, that hosts a specific USB controller, but booting from a USB drive connecting via cable is not allowed by Windows. The necessary drivers are not loaded until well after the first Windows services and processes (smss.exe and crss.exe) are already loaded, which means that Windows itself has started.

4
  • "motherboard will power" might be a little off. On most desktop systems I'm aware of, hard drives get their power direct from the power supply directly. But in general principle, yes. Commented Mar 23, 2020 at 17:14
  • The power switch is connected to the motherboard, which in turn powers all components. Hard drives may have their own supply, but without you pressing the button, they won't do much good. What I meant in my reply is that the sequence of events starts with the user pressing the power button, electrical power being distributed to all (or most) electronic components, including RAM, without which nothing happens, then the hard drives starts revving (or hashing, if it's an SSD...), and THEN the software part of the boot sequence begins (if you except the firmware, of course).
    – user1019780
    Commented Mar 23, 2020 at 18:16
  • You're saying it logically powers all components in sense of command flow. Coz it sounds like misdescribing how PCs are physically wired (which I'm guessing you have never seen the inside of a PC). I would just rephrase it. Commented Mar 23, 2020 at 19:26
  • I've been inside a PC more times than I care to remember, but laptops and desktop differ in many ways. You got my drift, I'm sure, that's what matters. The OP's question was more rhetorical than practical, I think, so potatoes, potahtoes...
    – user1019780
    Commented Mar 23, 2020 at 19:40
2

The motherboard contains firmware that runs bootloaders that boot OSes, and the two main types of such firmware are UEFI (new) and BIOS (old). In both cases, there’s a small amount of non-volatile storage on the motherboard which records the user’s preference as to which bootloader to use. It’s also often possible to press a certain button during boot to override this preference for this particular boot.

BIOS simply records an order of physical drives (plus generic entries such as “USB drives” which may be tried, if present, before other things, or after, or never), and booting involves loading the MBR of the first drive (the first 512 bytes) into memory and running the code it contains. If that fails, BIOS tries the next drive. 512 bytes isn’t much, so the typical BIOS bootloader installation process stores the bootloader somewhere else, notes its location on the drive and puts a small piece of code into the MBR that merely runs the actual bootloader.

UEFI, unlike BIOS, has the capability of reading files from FAT32 partitions. There has to be a partition marked with a certain GPT code, and UEFI settings include a list of paths to files found therein. UEFI will find that partition, load the file that’s the first in the list into memory and execute the code it contains. Later, having booted an OS, it’s possible to modify UEFI settings from within the OS, something that typically isn’t possible with BIOS.

In either case, a bootloader such as GRUB is started, and it can be quite a sophisticated program, containing its own hardware and filesystem drivers so it can read files from partitions, even encrypted ones. Typically, it reads its own configuration from a file in a predefined place on a predefined partition, which contains a list of OSes and parameters to be passed to those, and displays a menu to the user. Once the choice is made, it reads the file containing the OS kernel, puts it into memory according to the requirements of that OS and launches it. From that point on, the kernel is in control.

Some OSes, such as Linux, have their kernel file laid out in a certain way compatible with UEFI requirements, so they can be booted from UEFI directly without the use of a bootloader, but this approach is uncommon.

The bootable flag comes from the times when bootloaders were typically put in volume boot records at the start of a partition (as opposed to the start of the entire drive), and the MBR code would enumerate the partitions and chainload the bootloader from the one marked bootable. The flag is irrelevant with modern bootloaders.

So the user can choose which OS to boot both by means of UEFI or BIOS and by means of the bootloader, in practice it’s almost always the latter (UEFI/BIOS load the same bootloader each time which then displays a pretty menu and boots the chosen OS).

0

There is software built into the computer, which you can configure to indicate what disk should come first, second (if the first is not available), third, etc.

This used to be the "bios", stored in an eeprom (fed by a battery). But currently it has become much more complex, even linux based OS built into the hardware (which can make your computer prone to external attacks).

Each disk has a partition table, not necessarily a boot sector.

0

As described by @davidgo and @vilx, the firmware (UEFI or BIOS) will find the first available boot device and load/execute the boot loader from that device.

It is possible to configure a boot loader to load more than one operating system, possibly even from a second (or third) disk or other device.

  • It used to be fairly common to configure grub (on Linux) to boot either Linux or Windows.
  • More recently, with Intel-based Macs, people would install Windows and MacOS side by side and choose which to boot when they (re)started their machine.
  • Windows NT would allow you to install onto a FAT partition side-by-side with MS-DOS and (16-bit) Windows and the NT boot loader would allow you to choose which to boot. It was also possible to use the NT boot loader to boot Linux off of a separate partition. There may have been a similar option for Windows 2000 and Windows 95/98.

But (at least with people who I know) these multi-boot scenarios have become much less common with the availability of virtualization software (VMware, VirtualBox, etc.)

As an aside, for many years it was common for the BIOS (or UEFI) to scan floppy drives first, then CD-ROM/DVD-ROM drives, then "hard disks". Or at least that was the default setting. Obviously floppy disks have been obsolete for a while now, but I still see quite a few machines configured with the optical drive as the first boot device.
This was and is useful when installing an operating system. But it was problematic if you had a floppy disk mounted that happened to be infected with a boot sector virus. (We're seeing a similar issue today with USB media.) And personally, I don't want my machine checking the optical drive when I'm only going to be booting off of that once per year or less.

0

Please stop explaining that bios is nolonger around and that we understood it. Please explain if you have 2 harddrives plugged into motherboard through sata cables. computer is booting through wrong drive as C landing user at blue screen with "choose an option:Continue,Use a devivce,Troubleshoot, Turn off PC". QUESTION in UEFI devices when getting wrongboot to start pc and getting stuck without boot working once recieving [blue screen with "choose an option:Continue,Use a devivce,Troubleshoot, Turn off PC"] what are steps to change boot order and essentially swap computer from the secondary drive to main drive and boot correctly UEFI . Or explain switching back to legacy bios from [blue screen with "choose an option:Continue,Use a devivce,Troubleshoot, Turn off PC"]

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .