4

In this question, I'm considering both Windows (BOOTMGR) and Linux (GRUB) bootloaders as well as BIOS and EFI modes. Once a bootloader has invoked a kernel, does the bootloader keep running in any sort of way or does it die being replaced by the OS running?

xendi
  • 171

2 Answers2

3

does the bootloader keep running in any sort of way

No, the boot program transfers full control of the system over to the program/kernel it loaded.
The CPU would only have a single core enabled if it was multi-core, and the boot process is single threaded.
So the boot program ceases to execute once it jumps to the program/kernel it loaded.
The boot code, stack, and data are then all vulnerable to be overwritten at any time, so resumption of the boot program cannot be assured in any way.

sawdust
  • 18,591
2

Most of the time, they don’t. After the kernel is loaded, the bootloader transfers full control to it, the bootloader’s code becomes inactive and its memory can be reclaimed by the kernel. This mechanism is known as chain loading.

However, there are some booting utilities that reserve memory for themselves even after the kernel is loaded. One example of such a tool is MEMDISK, which can present an in-memory disk image as a virtual disk drive available to the operating system. To perform its functions, MEMDISK has to reserve memory not only for the disk image itself, but also for the code that intercepts firmware calls that perform disk I/O. Most other such tools are of this nature: for example, there is a tool that enables booting from USB disks for BIOSes that don’t provide this functionality natively, which similarly works by intercepting disk I/O calls. But even in this case, the code of such tools is only executed when the operating system specifically invokes it (or to be precise, the firmware services emulated by the tool) and cannot activate on its own.

In principle, nothing stops bootloader code from playing a more active role after the operating system kernel is loaded, except for the fact that doing so would probably require complex arrangements between the boot loader and the kernel, at which point it kind of stops making sense to call such software a ‘boot loader’ instead of an integral part of the kernel.