GOTAM GORABH

Technology

From Electricity to Execution: Everything That Happens Before Linux Takes Control

#linux#boot#firmware#uefi#hardware

Press the power button, wait a few seconds, and Linux starts printing messages. It is easy to treat the time before those messages as a single step: the BIOS does something, then the kernel starts.

There is a much more interesting sequence hiding inside that pause. The board has to establish stable power, release processors from reset, execute code without ordinary RAM, configure memory, discover boot devices, and prepare an environment that a kernel can actually use.

This article follows a typical x86-64 PC through a cold boot, using UEFI as the main path and legacy BIOS as a comparison. Laptops have different power circuitry, and ARM boards, virtual machines, suspend/resume, and kexec have different starting conditions. Even among PCs, some operations overlap or happen in a different order.

The useful thread to follow is what each stage makes possible for the next one.

Checkpoint 01 / Power & reset

The power button starts a hardware conversation

On a conventional ATX desktop connected to mains power, part of the system can already be powered while the PC appears off. The standby supply, commonly +5VSB, supports circuitry that can respond to the power button or a configured wake event.

Pressing the button signals the motherboard’s power-control logic. The board asserts PS_ON#, an active-low signal asking the power supply to enable its main outputs. Once those outputs meet the required conditions, the supply asserts PWR_OK. These signals are described in Intel’s desktop power supply design guide.

The motherboard also has its own regulators and power sequencing. Components need appropriate voltages and clocks before they can operate reliably. Reset signals keep parts of the system in a defined state while those prerequisites settle; PWR_OK is one input to that process, rather than a wire that simply tells Linux to start.

A spinning fan tells us that some power is available. It does not establish that the CPU has executed firmware or that memory initialization has succeeded.

Checkpoint 02 / The first instruction

The CPU begins at a reset vector

Once the platform permits execution, the processor starts from an architecturally defined reset state. It does not search the SSD for an operating system.

For the conventional modern x86 reset path, the bootstrap processor’s first instruction fetch is at physical address 0xFFFFFFF0, near the top of the first 4 GiB of address space. Platform hardware maps firmware storage into that address range. A small entry sequence transfers execution to more substantial initialization code.

Firmware is commonly stored in SPI flash on the motherboard. The address used for an instruction fetch is a physical address decoded by platform hardware; it does not mean there must be a working DRAM chip at that location.

The initial execution state has legacy x86 real-mode characteristics and special reset-time segment state. A processor capable of running 64-bit Linux does not immediately begin in 64-bit long mode. Firmware establishes the execution modes it needs as startup progresses. Intel’s minimal architecture boot loader white paper describes this reset path and its early initialization requirements.

On multiprocessor systems, one logical processor leads the initial boot. Other processors are brought into the sequence under firmware and, later, operating-system control.

Checkpoint 03 / Temporary working memory

Firmware needs working space before RAM works

A C function normally assumes it can use a stack. Firmware has a problem: the DRAM controller and memory devices have not yet been configured, so ordinary main memory is not ready for that stack.

Early code starts with very limited resources. On supported x86 platforms, firmware can configure processor cache as temporary storage, a technique called cache-as-RAM. Other platforms may provide on-chip SRAM. That small working area makes it possible to run more substantial initialization code before DRAM becomes usable.

The coreboot project’s architecture documentation provides a concrete example: its early stages establish a C environment, can apply microcode updates, and initialize DRAM before moving into later stages.

Many UEFI implementations organize similar work using the UEFI Platform Initialization architecture:

  • SEC — Security: handles the earliest initialization and establishes temporary working memory.
  • PEI — Pre-EFI Initialization: brings up permanent memory and records information needed by the next phase.
  • DXE — Driver Execution Environment: runs the richer driver and service environment used later in boot.

The PI overview describes the transition from processor-local resources to permanent memory. These phase names describe a firmware architecture; UEFI itself defines the interface exposed to loaders and operating systems, so every UEFI implementation need not have identical internals.

Checkpoint 04 / Permanent memory

Installed RAM still has to be initialized

The memory controller needs to know what is connected and how to communicate with it. Firmware obtains memory characteristics, commonly from a module’s Serial Presence Detect (SPD) data, and configures the controller and DRAM devices.

Initialization includes selecting supported settings, programming timing parameters, and performing training. Training calibrates communication between the controller and memory: high-speed signals must be sampled within a reliable timing window, despite differences between channels, modules, and board traces.

Intel’s server platform specification illustrates the work involved, including DIMM discovery, SPD collection, controller initialization, and channel training. The exact steps depend on the processor and memory generation.

Some systems retain training results to speed up later boots. A first boot, changed memory configuration, or reset of firmware settings can therefore take noticeably longer. Intel also documents extended memory initialization and training as a possible reason for a black screen during startup on the platform described there.

After permanent memory becomes available, firmware can migrate its temporary state, use larger stacks and heaps, and load more code into RAM.

This also puts POST, the power-on self-test, in context. Hardware checks and initialization occur throughout early firmware execution. The diagnostics vary by platform; a successful startup does not imply that firmware performed an exhaustive test of every byte of RAM.

Checkpoint 05 / The preboot environment

Firmware builds a small preboot environment

With usable RAM, later firmware can discover devices and provide enough drivers to reach a boot target. Depending on the machine and its boot policy, that can involve PCI/PCIe discovery, resource assignment, storage controllers, USB devices, a display console, and network boot support.

The goal is to make the selected boot path usable. Firmware does not have to provide the full capabilities that Linux will later expose through its own drivers.

In a PI-based implementation, DXE drivers publish interfaces called protocols. These allow other firmware components and EFI applications to discover services without knowing each device’s implementation. The DXE overview also describes the UEFI System Table and its links to boot services, runtime services, and configuration tables.

Those configuration tables can point to ACPI and SMBIOS information. ACPI describes platform details such as interrupt topology and power-management interfaces; SMBIOS provides system inventory information. Linux receives pointers to these descriptions and uses them alongside its own hardware discovery.

The manufacturer’s logo can appear during this environment’s lifetime. Its appearance is evidence that display initialization has progressed, but it does not identify the exact stage responsible for a later delay.

Checkpoint 06 / Choosing a boot target

UEFI chooses an executable to boot

UEFI includes a firmware boot manager. Its persistent variables describe boot options:

  • Boot#### variables hold individual options, including a device path and optional load data.
  • BootOrder specifies the normal order in which options are attempted.
  • BootNext requests a particular option for the next boot.

For a typical local installation, an option identifies a loader on the EFI System Partition (ESP), normally a FAT32 partition on a PC. UEFI loads an EFI executable in PE/COFF format. It can use an explicitly registered path, while the x86-64 removable-media convention uses \EFI\BOOT\BOOTX64.EFI. The UEFI boot manager specification defines these mechanisms.

That executable might be GRUB, systemd-boot, a distribution’s shim, or a kernel image with EFI support. Network boot and recovery options provide other routes.

The firmware boot manager and a Linux bootloader menu are separate selection points. Firmware can select GRUB, and GRUB can then select among several installed kernels.

Checkpoint 07 / Verifying the next link

Secure Boot checks what may execute

When enabled and enforcing its policy, UEFI Secure Boot checks EFI images against authorized and forbidden signature databases. The authorized database, db, can contain trusted certificates or image hashes; dbx records forbidden entries. A match against the forbidden database prevents acceptance even when an authorization would otherwise apply.

The Secure Boot specification describes this image-validation policy. Later components must continue verification according to their own policies if the intended trust chain is to extend through the kernel and other boot resources.

This explains how a loader can exist on the ESP and still be rejected before Linux begins normal startup. Loading bytes from storage and authorizing those bytes to execute are separate operations.

Secure Boot also serves a different purpose from disk encryption. Secure Boot controls acceptance of executable boot images; encryption protects stored data. Systems can combine both.

Checkpoint 08 / Preparing Linux

The loader prepares the kernel and its inputs

The selected loader needs to put a suitable kernel image and its supporting data into memory. Depending on the boot arrangement, those inputs include a kernel command line and an initial RAM filesystem image.

A command line might look like this:

root=UUID=<root-filesystem-uuid> ro quiet

The UUID here is a placeholder. On a typical distribution with an initramfs, early userspace can resolve that filesystem UUID to the root device. Parameters such as ro and quiet influence root mounting and console output. The kernel documents its options in the command-line parameter reference.

The loader also has to respect a defined entry contract. For the native x86 Linux boot protocols, this includes preparing struct boot_params, placing the image and supporting buffers appropriately, and entering with the required processor and register state.

For example, the native 64-bit protocol requires 64-bit mode, paging with the specified identity mappings, disabled interrupts, and the address of boot_params in %rsi. These are requirements of that particular entry path. EFI entry has its own contract. The Linux/x86 boot protocol specifies the supported interfaces.

A separate bootloader is optional

With CONFIG_EFI_STUB, an x86 Linux kernel image includes an EFI boot stub that lets it be loaded as an EFI executable. The stub performs preparation that would otherwise require a separate loader. The kernel’s EFI stub documentation explains this direct boot path.

A Unified Kernel Image (UKI) can package a kernel, an EFI stub, an initramfs, and additional resources such as a command line into one EFI executable. That image can be signed as a unit and launched by firmware or another boot manager. The systemd-stub documentation describes this arrangement.

The preparation still has to happen. Its implementation can live in a separate program, a kernel stub, or a combination of components.

Checkpoint 09 / The ownership transition

ExitBootServices marks the ownership transition

While a UEFI loader or kernel stub is preparing the system, it can use firmware boot services to allocate memory and access devices. Before continuing independently, it must end that environment.

The loader or stub obtains the current memory map through GetMemoryMap(), then calls ExitBootServices() with the map’s key. If the map changes and the key becomes stale, it must obtain a fresh map and retry as required by the interface.

After a successful call, boot services are unavailable, and the operating-system loader is responsible for the system’s continued operation. Memory types still matter: regions reserved for runtime services or other platform purposes cannot simply be treated as free RAM. The UEFI boot services specification defines this boundary.

This gives “Linux takes control” two related meanings. Linux-provided EFI stub code may already be executing while firmware services remain available. Successful ExitBootServices() ends the firmware boot-services environment; Linux then continues into its native startup path.

Some firmware functionality persists after that transition. UEFI runtime services remain available under their specified calling rules, including services for variables and system reset. Firmware has not vanished from the machine; its boot-time service role has ended.

Alternative path

How the legacy BIOS path differs

Legacy BIOS performs early hardware initialization too, but the traditional disk handoff is different. For a conventional hard-disk boot, it loads the initial boot sector at physical address 0x7C00 and transfers execution to its small loader.

In the classic MBR layout, the first sector contains a limited boot-code area alongside a partition table and boot signature. That is far too small for a complete modern loader.

GRUB’s BIOS path therefore uses a small initial image to reach its larger core image, which can load filesystem support and further modules. On GPT disks, a BIOS Boot Partition can provide space for this core image. This partition serves a different purpose from the EFI System Partition used by UEFI. The GNU GRUB manual explains the embedding requirements.

The two paths can eventually start the same Linux kernel, but they reach it through different interfaces:

Legacy BIOS -> boot sector -> loader stages -> Linux entry
UEFI        -> EFI executable / stub       -> Linux entry

The familiar MBR boot-sector story should therefore be applied to the legacy path, rather than assumed to describe every modern PC.

Beyond the handoff

What happens just beyond the handoff

At the native kernel entry point, Linux still has considerable work ahead. Architecture-specific startup code establishes the execution environment needed by the main kernel; depending on the image and entry path, that includes decompression and relocation. Kernel initialization then develops its own memory management, interrupt handling, scheduling, and device support.

An initramfs helps bridge the gap between the kernel and the installed root filesystem. It can supply modules and programs needed to find storage, assemble volumes, or unlock an encrypted root device.

The firmware and bootloader generally load or convey the initramfs as data. Linux unpacks it, and when it contains /init, the kernel executes that program as PID 1. Early userspace can then locate the installed root filesystem and continue into its init system. The kernel’s initramfs documentation explains this transition. Systems with everything required built into the kernel can boot without an external initramfs.

A distribution’s service manager and login screen arrive after these stages. By the time either appears, Linux has already controlled the system for a substantial part of startup.

On your machine

Looking for evidence on a running system

Once Linux is running, a few commands help connect this sequence to the machine in front of you.

Check whether the running kernel exposes a UEFI firmware interface:

if [ -d /sys/firmware/efi ]; then
  echo "UEFI interface is available"
else
  echo "UEFI interface is not exposed"
fi

On a normal PC installation, its presence indicates a UEFI boot. Its absence alone is less decisive in a container or a system where EFI support is disabled.

If installed, efibootmgr can display the firmware’s boot entries and device paths:

efibootmgr -v

This read-only invocation may require elevated privileges, and EFI variable access must be available. Compare the selected loader path with files on the mounted ESP.

Inspect the command line that reached the running kernel:

cat /proc/cmdline

On a system using systemd and its journal, inspect kernel messages and boot timing:

journalctl -k -b
systemd-analyze time

Firmware and loader timing appears only when the relevant timing data is supplied. The systemd boot loader interface describes how loaders report it; systemd-analyze explains the timing output.

Kernel logs start after firmware has already done its early work. Investigating a failure before kernel entry may require platform diagnostics, POST indicators, serial firmware output, or firmware-specific logs.

That is what makes the pause after pressing the power button so interesting. Before Linux can manage processes or load a driver, earlier stages must turn electrical power into reliable instruction execution, usable memory, reachable storage, and a precise handoff. The first kernel message is the visible result of all that preparation.