Linux Kernel Initialization
The boot loader passes two or three pieces of information to the Linux kernel
initilization routine:
- A pointer to the beginning of the initilization RAM disk.
- A pointer to a string containing parameters for
initializing the kernel. This string is commonly referred to as
the kernel command-line parameters.
- A pointer to the EFI System Table (for UEFI systems only).
These will be saved into kernel variables during early initialization.
On most platforms, the kernel file is compressed to save space on disk. The
compressed data is then preceded with a relatively small assembly-language
routine that will decompress the kernel proper and then transfer control to
the "real" kernel it just decompressed.
The "real" Linux kernel initialization then begins, consisting
of the following steps:
- The kernel initializes hardware as well as kernel data
structures.
- The kernel command line is saved.
- Hard-drive information is retrieved from the BIOS or UEFI.
- The memory size is determined, again through the BIOS or UEFI..
- The hardware is prepared to move to protected mode.
(Protected mode is the normal memory mode that the system
runs in. It allows for the use of virtual memory that
allows to use more memory (virtual memory) than is
physically present on the processor. Protected mode is
also the mode that allows individual programs to run in
isolation from one another so that one program cannot
accidentally or maliciously damage another program.
- Segment registers are set and Interrupt Descriptor Table
is initialized. These are used in protected mode.
Segment registers are used with vitual memory. The
Interrupt Descriptor Table is a list of routines in the
kernel to be given control when an interrupt has
occurred. (An interrupt is a hardware mechanism for
giving control to the kernel from an application program.)
- All interupts are disabled.
- The "Protected Mode Enabled" bit is set in the Machine
Status Word. This step actually turns on protected mode.
- The page tables are initialized. These are part of
virtual memory support.
- Paging is enabled by setting the PG bit in control
register 0. This turns on virtual memory.
- Exception handlers are installed. These routines get
control when a programming error is detected by the hardware.
- The time of day is read from the CMOS clock. The CMOS
clock runs (on a battery) whether the computer is running or
not. Thus the date and time can be preserved even when the
computer is powered off.
- The timer interrupt is installed.
- Interrupts are enabled.
- INITRD (the intialization ram disk) is mounted. (Mounting
a file system makes the files within that file system
available to the kernel and to application programs.)
- Various subsystem initialization
routines are called. The kernel is made up of a number
of subsystems and most of them have their on initialization
code which is called at this time.
- Other SMP processors are started. Most modern systems
have more than one processor. Up until now only one processor
has been running. This step starts up the other processor(s).
- At this stage kernel initialization is essentially completed with
the exception of I/O devices. At this point in time, the kernel is
ready to enter its normal processing mode which consists of the
following cycle:
-
Call the scheduler to pick and run an application program (or "task"
as it is known to the kernel.)
- Either the application program or some other hardware event
creates an interrupt. This causes the CPU to switch back to the
kernel.
- The kernel "services the interrupt", i.e. it does whatever is
needed to handle the cause of the interrupt.
- Return to step 1 to resume application-program execution. Note
that the application selected to run may or may not be the same
program that was interrupted.
At this point in the startup sequence, there are no tasks (or
programs) to run. The kernel therefore creates the first task in the
task queue. This task (process ID 1)
is called the init
task.
The kernel then creates a second task, known as kthreadd.
- The kthreadd task, running as a kernel thread then manages the other kernel threads which
kthreadd creates.
- The init task, also running as a kernel thread, does
additional initialization.
- After the above is completed, the init thread executes the program
init which is found in the root directory of the initrd file system.
Next: The init process.
Return to main PC Boot Sequence page
Return to my writing page
Return to my home page