You are on page 1of 6

InitRD, GRUB, and You: A Description of

the Linux Kernel Boot Process

Mike Castner
ENGL 202C: Section 012
Ms. Sara Woolfitt
October 26th, 2010
Introduction
The purpose of this document is to give the reader a better understanding of the specific
components and processes that enable the Linux kernel to progress from the initial bootloader stage to
the fully-booted kernel. To give a bit of context, the Linux operating system was created in the early
1990's by a Finnish programmer named Linus Torvalds, and is considered one of the champions of open
source software. It is unique in that it is not developed by a single company or individual, but by a group
of independent contributors and hobbyists in their spare time. It has grown from a very niche system
with no practical application into a robust business solution in place at almost all major corporations
across the globe.

Although Linux has achieved so much in such a short time, and is used on a regular basis by
millions of people throughout the world, it has at least one large flaw that many quickly agree
upon...few people actually know how the system functions on a technical level. Its open nature has
allowed for many companies to create customized installers and troubleshooting tools that have
eliminated a need for in-depth understanding of some parts of the system. While it is far from being
easy-to-use, some components have become so well developed that many take their functionality for
granted. The kernel boot process is one such part of Linux, and its obscure functionality will hopefully
become easier to understand by continuing to read this document.

With that said, this guide is aimed at those who are already familiar with Linux, and have
perhaps worked on it at a System Administrator level. It is assumed that basic concepts are already
understood, as a complete explanation of Linux itself is far beyond the scope of this guide. An
explanation of the boot process preceding the bootloader stage is also outside the scope of this
document, as all operating systems follow the same BIOS, hardware, and MBR steps initially. We begin
with the bootloader stage because it is the first part of the boot process unique to Linux. After the
bootloader, we then progress into the actual kernel stage, and finally into the Init stage. The total
process can be seen in Figure 1 below. With all of these things in mind, we can now begin our actual
technical analysis.

Figure 1: Entire Boot Process / Sub-Processes


Bootloader
The bootloader is the first thing that a user is greeted with upon turning on their computer if
Linux is installed. At a visible level, it is a simple text-based application in which a user can select an
operating system from a list of choices. The most popular bootloader among Linux users is a program
called GRUB (GRand Unified Bootloader), which has a unique process for loading the kernel into memory
and will be used as the de facto example for this document.

When GRUB is initiated, the first thing that the program does is access the attached storage
devices (usually the system hard disks) and probe the file systems contained on them, so that it can find
its own configuration files. These files tell the program how to behave, and will dictate which version of
Linux or other operating systems will boot and when. After GRUB finds and reads these configuration
files, it prints back the results in the form of a list:

Figure 2: Taken from HowToGeek.com

The user can then choose whichever kernel they want, or else GRUB will time out and
automatically select an option for them. Either way, GRUB will then once again search through the file
system, this time looking for the correct kernel and InitRD images. While you may be aware that the
kernel is the heart of the Linux operating system, you may need a bit of a refresher on exactly what it
does. The kernel is an essential part of any operating system that lies between the hardware and the
software. The entire purpose of the kernel is to facilitate interaction between the physical hardware of
the computer, and any installed software that may need to access or make use of that hardware. That's
the idea of a kernel in a nutshell.

Another thing worth explaining at this point would be the aforementioned InitRD (pronounced
"In-It-R-D") image. InitRD is a miniature, compressed kernel image, used as a stepping stone between
simple system initialization and the more full-fledged functions of the larger kernel. It is a very
rudimentary kernel, however, and is only meant to do basic hardware detection before it loads the real
kernel and tells it to boot. It is a necessary part of the boot process, however, and is always paired with
the actual Linux kernel so that the full system can actually be used. Once the kernel and InitRD images
are found, GRUB loads the tiny, compressed INITRD image into the system memory and tells it to
execute.

Kernel
With the execution of the InitRD image, we move from the bootloader stage into the actual
kernel stage. GRUB has now completed its job and InitRD is the only thing running and loaded into
memory. As we briefly mentioned before, InitRD is compressed by default. Thus, the first thing that the
compressed InitRD does is decompress itself and expand into the computer's memory. Once it is fully
decompressed, it executes again and performs its expanded functions.

The entire purpose of InitRD is to execute the real Linux kernel, but it first has to create a proper
environment for this to happen. To do this, it examines all connected hardware, catalogues it, and then
loads the appropriate driver or module. Once InitRD has done everything it can to make all system
hardware available, it tells the actual kernel to execute and initialize. This change signals the end of the
kernel stage, and the beginning of the INIT stage. An overview of the entire kernel stage, with relative
size comparisons of what is loaded into memory, can be seen in the figure below:

Figure 3: Kernel Boot Stage

Before we move on to the final part of the boot process, it may have occurred to you that it
would be much easier for GRUB to simply call the Linux kernel itself, have it do the hardware detection,
and boot without InitRD at all. This is an entirely valid concern, though there is actually a reason for
InitRD's existence. The idea behind the compressed image is that it can boot without loading any
specific hardware resources at all, and have a minimal, functional system without being dependent on a
specific hard drive, wireless card, or other device that would stop the larger Linux kernel from
completing its boot. That way, if the Linux kernel does have a problem, it can fall back on InitRD and the
user will still have a minimal system available to troubleshoot and correct the error.
INIT
The third and final stage in the Linux boot process is the INIT stage. As we now know, the first
stage of the process gave us a working InitRD image. The subsequent stage used that InitRD process to
call the Linux kernel. This stage will use the Linux kernel to start applications and spawn a terminal
session for the user to actually interact with. Once the kernel reaches this point, the boot process will
be complete. There are a few more steps between the initial kernel start and the terminal session,
however.

The first thing that the Linux kernel will do after it has been called into memory by InitRD is find
all relevant storage devices (particularly those where the boot, swap, and root partitions are stored) and
mount the file systems that they contain. At this point, Linux is no longer confined to temporary
memory and is free to modify the disk on which it resides or interact with files that exist on it. The INIT
process continues from this point and begins to start the required system tasks. These would include
monitoring daemons, logging utilities, and DHCP programs that allow network connectivity. These core
programs are loaded first, usually to tell the detected hardware to begin performing its function. The
next programs to be loaded are user-specified, and can be anything ranging from a server program to a
database to an interactive desktop. The INIT process will only load programs that the user has
specifically told it to load at this time, as the overall startup time of the system is increased with each
program that needs to be started.

After the system has all of its necessary programs running, and the user also has all of their
programs running, the final step in the Linux boot process occurs: the terminal session. At this point,
the system is done preparing itself, and needs the user to tell it what to do next. It starts a shell session
that a user can login to, and once they have authenticated they can input any commands that they wish
into the system. At this point, the boot process is officially complete.

Conclusion
To summarize, the Linux boot process is a multi-stage process that encompasses many small
subtasks such as these:

1. Bootloader
a. GRUB
b. File System
c. Kernel Selection
d. Kernel Execution
2. Kernel
a. Decompression
b. Load InitRD into RAM
c. Hardware / CPU Detection
d. Modules
e. Switch from InitRD to Real Root
3. INIT
a. Mount File Systems
b. Start System Services
c. Start User Services
d. Start Terminal Session

Each of these tasks are absolutely necessary for the system to function correctly, and when
they are all combined they make up an integral part of the Linux kernel. I hope that this guide has been
informative, and that you now understand a bit more about how and why Linux continues to work!

You might also like