Linux Kernel Initialization

The boot loader passes two or three pieces of information to the Linux kernel initilization routine:
  1. A pointer to the beginning of the initilization RAM disk.
  2. A pointer to a string containing parameters for initializing the kernel. This string is commonly referred to as the kernel command-line parameters.
  3. 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:

  1. The kernel initializes hardware as well as kernel data structures.
  2. The kernel command line is saved.
  3. Hard-drive information is retrieved from the BIOS or UEFI.
  4. The memory size is determined, again through the BIOS or UEFI..
  5. 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.
  6. 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.)
  7. All interupts are disabled.
  8. The "Protected Mode Enabled" bit is set in the Machine Status Word. This step actually turns on protected mode.
  9. The page tables are initialized. These are part of virtual memory support.
  10. Paging is enabled by setting the PG bit in control register 0. This turns on virtual memory.
  11. Exception handlers are installed. These routines get control when a programming error is detected by the hardware.
  12. 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.
  13. The timer interrupt is installed.
  14. Interrupts are enabled.
  15. 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.)
  16. 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.
  17. 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).
  18. 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:
    1. Call the scheduler to pick and run an application program (or "task" as it is known to the kernel.)
    2. Either the application program or some other hardware event creates an interrupt. This causes the CPU to switch back to the kernel.
    3. The kernel "services the interrupt", i.e. it does whatever is needed to handle the cause of the interrupt.
    4. 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.

  19. The kthreadd task, running as a kernel thread then manages the other kernel threads which kthreadd creates.
  20. The init task, also running as a kernel thread, does additional initialization.
  21. 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