How does a computer boot
A computer that has just been switched off is dark. The screen is blank and memory is empty. Yet we learned that the kernel manages everything: it starts processes, puts up walls in memory, and answers system calls. So where is that kernel now? With the power off, there is nothing in memory at all. How, then, does an empty computer turn into a living, working one in the instant you press the power button?
Press the Power Button and an Empty Computer Wakes Up
Picture a computer with the power off. Its memory is wiped clean. The kernel we learned so much about, and the processes that branched out from it, are not in memory now, not a single line of them. With no electricity flowing, that is only natural.
When you press the power button, something has to take the first step. It is not the kernel but a very small program kept permanently in a chip on the motherboard. It is called the startup program, or firmware.
The firmware sits there from the start, ready to be the first thing awake when the power comes on.
Press the power button: in a computer whose memory was empty, the small startup program inside the chip (firmware, blue) is the first to wake. The kernel is nowhere yet.
Only the small firmware is awake, and memory is still almost empty. The firmware is not clever. Apart from a quick check that the parts are connected, it cannot decorate the screen or launch apps.
What it does know is how to bring in the real worker, and that worker is the kernel. But the kernel is not in memory right now: while the power was off, it lay asleep on the disk as a file.
So the firmware's job is clear. Go to the disk and bring the kernel back.
The Firmware Lifts the Kernel from the Disk into Memory
Recall what we said in the last lesson: the kernel stays in memory and manages everything. But even a kernel that always stays in memory has to arrive there for the first time at some point. That point is now.
The firmware finds the kernel file on the disk and moves it into memory one chunk at a time. On real computers the firmware usually loads a small program called a boot loader first, and the boot loader then loads the kernel. Either way, the kernel finally settles into memory that was empty a moment ago.
The kernel we have called the star of every scene in this area steps onto the stage for the first time right here, in this one scene of booting.
Each press of the button lifts one more chunk of the kernel (gold), asleep as a file on the disk, into memory. Once all four chunks are up, the kernel that always stays in memory takes its place there for the first time.
Once the whole kernel is in memory, the firmware quietly hands over the job. The little startup program's part ends here: it has woken the real worker and sat it down, and the stage now belongs to the kernel.
What does the kernel do first? By itself, the kernel cannot do anything we can see. The icons on the screen, the window that takes our typing, the apps we open: all of them exist only once some program is running.
From this moment on, the kernel is in charge of the whole computer. So the very first thing it does is give birth to the first process.
The Kernel Starts the First Process, and Branches Grow from It
Think back to the lesson on processes. A program is a file asleep on the disk, and a process is that program running and alive. During boot, the kernel does exactly this for the very first time.
It picks one program sleeping on the disk and runs it, making it the first living process on this computer. On Linux this first process is given the number 1. The kernel does not launch every app itself, though. The first process starts other processes, and those children start children of their own, branching out like a tree.
Every one of the many programs we use is a branch that split off from this first process.
Press the button once and the first process is born under the kernel (gold); press it again and child processes (green) branch out from it.
One press created the first process, and the next sent children spreading out beneath it. This is where the screen we see every day begins. The program that draws the desktop, the clock, the notifications: each is a process somewhere among these branches.
Each of these processes has its own memory space, and whenever it needs something it asks the kernel with a system call. The pieces we learned one at a time in this area are falling into place inside the single scene of booting.
Now we can stack those pieces into one picture, layer by layer.
Built Up in Layers (from Hardware to Apps)
Here is the whole thing in one picture. At the bottom is the hardware, the physical parts such as the disk, memory, screen, and keyboard. Above it the small firmware wakes and takes the first step, and the firmware loads the kernel.
The kernel sits right on top of the hardware, talking to every part directly, putting up walls in memory and keeping the schedule. Above the kernel is the first process, and above that the apps we use are stacked one after another.
A lower layer has to hold firm before the one above can stand. Without hardware there is no firmware, without firmware no kernel, without the kernel no processes, and without processes no apps. An arrangement like this, where each layer holds up the one above, is usually called a layered structure.
Each press of the button lights one more layer, starting at the bottom: hardware, firmware, kernel, first process, apps. A lower layer has to stand before the next one can go up.
When the light reaches the apps at the very top, the screen we see is finally complete. The computer that was dark is now alive.
The interesting part is that once this tower is up, what the firmware did is all but forgotten. Using an app, we hardly ever think about the kernel holding it up from below, or the firmware and hardware below that.
Yet every one of those layers was raised from the bottom up, in order, in the single moment of booting. The maker's logo that flashes up when you turn a computer on is the firmware at work, and around the time it disappears, the kernel takes over.
One Press of the Power Button: the Whole Area on One Page
Strung on one line, it goes like this. You press the power button, the small firmware in the chip wakes, the firmware lifts the kernel from the disk into memory, the kernel starts the first process, and the apps branch out from there.
That one line, which plays out in a few seconds, holds almost everything we learned in this area: files asleep on the disk and memory, the kernel that always stays in memory, living processes, each process's own memory space, drivers that talk to the parts, permissions that decide who may do what, and the system calls processes use to ask the kernel for help.
Booting is the scene in which all these pieces appear together for the first time, and in a fixed order.
Press the five steps in order and one full boot strings together on a single line: power, the firmware waking, loading the kernel, the first process, and stacking the apps.
From now on, the brief moment of pressing the power button should look different. Inside it, a small startup program wakes the kernel, the kernel starts the first process, and our apps climb up layer by layer in one big piece of assembly.
This area began by asking what the invisible caretaker behind the screen actually does. Booting is the caretaker getting up in the morning and setting the whole household in order, step by step, from the very beginning. It is the moment, quietly repeated every day, when a dark machine finishes getting ready to greet us.