0% found this document useful (0 votes)
93 views

Linux Boot Process

Uploaded by

Milad Norouzi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views

Linux Boot Process

Uploaded by

Milad Norouzi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Inside the Linux boot process

Skip to main content

Country/region
[ select ]

Allofof
All dWdW Search

Home
Solutions
Services

IT services

All IT services
Business continuity and resiliency services
End-user services
Integrated communications services
IT strategy and architecture services
Maintenance and technical support services
Middleware services
Security services
Server services
Site and facilities services
Storage and data services
IT services A-Z
Business consulting

Global Business Services


Business analytics and optimization
Strategy and transformation
Thought leadership
Application services

All application services


Custom application development and system integration
Application management
Outsourcing services

Applications outsourcing
Business process outsourcing
IT outsourcing and hosting
Training

Small and medium business

Other services

Asset recovery
Software services
More
Products

Special offers

Software

Software overview
Products
Trials and demos
Events and conferences

Business Analytics
- Cognos
- SPSS
Enterprise Content Management
Information Management
- DB2
- Informix
- InfoSphere
Lotus
Rational
Tivoli
WebSphere
System z software
Storage

All storage

http://www.ibm.com/developerworks/linux/library/l-linuxboot/[12/24/2010 5:53:09 PM]


Inside the Linux boot process

Disk systems
Tape systems
Storage area networks
Network attached storage
Storage software
Hard drives/microdrives
Storage A to Z
Servers & systems

All servers and systems


Systems software
Power Systems
System i (iSeries)
System p (pSeries)
System z (Mainframe)
System x (xSeries)
BladeCenter
Cluster systems

UNIX servers
Linux servers

Intel processor-based servers


AMD processor-based servers

OEM systems
Internet security

Networking

Personal computers

Point of sale

Printing systems from InfoPrint

Semiconductors

Upgrades, accessories & parts

Certifed used systems & storage

Communities

Small business products

Medium business products

Hardware
Software
More

Support & downloads

Download

Fixes, updates and drivers


Trials and demos
Troubleshoot

Search

Documentation

Forums & communities

Plan

Install

Use

Open a technical service request

Support by product

Software
Servers and systems
System storage
Printing systems from InfoPrint
Lenovo ThinkPads and ThinkCentres
Customer support

http://www.ibm.com/developerworks/linux/library/l-linuxboot/[12/24/2010 5:53:09 PM]


Inside the Linux boot process

More

My IBM

My accounts

My profle

My interests

My community spaces

My technical support

My customer support

Shopping cart
Contracts
Orders and delivery
Inventory and maintenance
Invoices and payments
Self-service tools
More customer support
Subscriptions

More

developerWorks
Linux
Technical library

Inside the Linux boot process


Take a guided tour from the Master Boot Record to the frst user-space application

M. Tim Jones, Consultant Engineer, Emulex Date:  31 May 2006


Level:  Introductory
Summary:  The process of booting a Linux® system consists of a number of stages. But In
Also available in:  Korean  Russian  Portuguese
whether you're booting a standard x86 desktop or a deeply embedded PowerPC® target, the
much of the fow is surprisingly similar. This article explores the Linux boot process from the early
initial bootstrap to the start of the frst user-space application. Along the way, you'll learn about Activity:  175142 views
various other boot-related topics such as the boot loaders, kernel decompression, the initial Comments:   4 ( View | Add comment - Sign in)
RAM disk, and other elements of Linux boot.
Average rating (998 votes)
Tags for this article:  boot, bootstrapping, boottrapping, kernal, linux, process, sequence, Rate this article
system, tech
days, bootstrapping a computer meant
Tag this! Update My dW interests (Log in | What's this?) Skip to help for feeding a paper tape containing a boot
Update My dW interests program or manually loading a boot
program using the front panel
address/data/control switches.
Today's computers are equipped with facilities to simplify the boot process, but that doesn't necessarily make it simple.

Let's start with a high-level view of Linux boot so you can see the entire landscape. Then we'll review what's going on at each of the
individual steps. Source references along the way will help you navigate the kernel tree and dig in further.

Overview
Figure 1 gives you the 20,000-foot view.

Figure 1. The 20,000-foot view of the Linux boot process

http://www.ibm.com/developerworks/linux/library/l-linuxboot/[12/24/2010 5:53:09 PM]


Inside the Linux boot process

When a system is frst booted, or is reset, the processor executes code at a well-known location. In a personal computer (PC), this
location is in the basic input/output system (BIOS), which is stored in fash memory on the motherboard. The central processing unit
(CPU) in an embedded system invokes the reset vector to start a program at a known address in fash/ROM. In either case, the result
is the same. Because PCs offer so much fexibility, the BIOS must determine which devices are candidates for boot. We'll look at this
in more detail later.

When a boot device is found, the frst-stage boot loader is loaded into RAM and executed. This boot loader is less than 512 bytes in
length (a single sector), and its job is to load the second-stage boot loader.

When the second-stage boot loader is in RAM and executing, a splash screen is commonly displayed, and Linux and an optional
initial RAM disk (temporary root fle system) are loaded into memory. When the images are loaded, the second-stage boot loader
passes control to the kernel image and the kernel is decompressed and initialized. At this stage, the second-stage boot loader checks
the system hardware, enumerates the attached hardware devices, mounts the root device, and then loads the necessary kernel
modules. When complete, the frst user-space program (init) starts, and high-level system initialization is performed.

That's Linux boot in a nutshell. Now let's dig in a little further and explore some of the details of the Linux boot process.

Back to top

System startup
The system startup stage depends on the hardware that Linux is being booted on. On an embedded platform, a bootstrap
environment is used when the system is powered on, or reset. Examples include U-Boot, RedBoot, and MicroMonitor from Lucent.
Embedded platforms are commonly shipped with a boot monitor. These programs reside in special region of fash memory on the
target hardware and provide the means to download a Linux kernel image into fash memory and subsequently execute it. In addition
to having the ability to store and boot a Linux image, these boot monitors perform some level of system test and hardware
initialization. In an embedded target, these boot monitors commonly cover both the frst- and second-stage boot loaders.

In a PC, booting Linux begins in the BIOS at address 0xFFFF0. The


Extracting the MBR
frst step of the BIOS is the power-on self test (POST). The job of the
POST is to perform a check of the hardware. The second step of the
BIOS is local device enumeration and initialization. To see the contents of your MBR, use this command:

Given the different uses of BIOS functions, the BIOS is made up of two # dd if=/dev/hda of=mbr.bin bs=512 count=1
parts: the POST code and runtime services. After the POST is # od -xa mbr.bin
complete, it is fushed from memory, but the BIOS runtime services
remain and are available to the target operating system. The dd command, which needs to be run from root, reads
the frst 512 bytes from /dev/hda (the frst Integrated Drive
To boot an operating system, the BIOS runtime searches for devices Electronics, or IDE drive) and writes them to the mbr.bin
that are both active and bootable in the order of preference defned by fle. The od command prints the binary fle in hex and
the complementary metal oxide semiconductor (CMOS) settings. A ASCII formats.
boot device can be a foppy disk, a CD-ROM, a partition on a hard disk,
a device on the network, or even a USB fash memory stick.

Commonly, Linux is booted from a hard disk, where the Master Boot Record (MBR) contains the primary boot loader. The MBR is a
512-byte sector, located in the frst sector on the disk (sector 1 of cylinder 0, head 0). After the MBR is loaded into RAM, the BIOS
yields control to it.

Back to top

Stage 1 boot loader

http://www.ibm.com/developerworks/linux/library/l-linuxboot/[12/24/2010 5:53:09 PM]


Inside the Linux boot process

The primary boot loader that resides in the MBR is a 512-byte image containing both program code and a small partition table (see
Figure 2). The frst 446 bytes are the primary boot loader, which contains both executable code and error message text. The next
sixty-four bytes are the partition table, which contains a record for each of four partitions (sixteen bytes each). The MBR ends with two
bytes that are defned as the magic number (0xAA55). The magic number serves as a validation check of the MBR.

Figure 2. Anatomy of the MBR

The job of the primary boot loader is to fnd and load the secondary boot loader (stage 2). It does this by looking through the partition
table for an active partition. When it fnds an active partition, it scans the remaining partitions in the table to ensure that they're all
inactive. When this is verifed, the active partition's boot record is read from the device into RAM and executed.

Back to top

Stage 2 boot loader


The secondary, or second-stage, boot loader could be more aptly called the kernel loader. The task at this stage is to load the Linux
kernel and optional initial RAM disk.

The frst- and second-stage boot loaders combined are called Linux
GRUB stage boot loaders
Loader (LILO) or GRand Unifed Bootloader (GRUB) in the x86 PC
environment. Because LILO has some disadvantages that were
corrected in GRUB, let's look into GRUB. (See many additional The /boot/grub directory contains the stage1,
resources on GRUB, LILO, and related topics in the Resources section stage1.5, and stage2 boot loaders, as well as a
later in this article.) number of alternate loaders (for example, CR-ROMs use
the iso9660_stage_1_5).
The great thing about GRUB is that it includes knowledge of Linux fle
systems. Instead of using raw sectors on the disk, as LILO does,
GRUB can load a Linux kernel from an ext2 or ext3 fle system. It does this by making the two-stage boot loader into a three-stage
boot loader. Stage 1 (MBR) boots a stage 1.5 boot loader that understands the particular fle system containing the Linux kernel
image. Examples include reiserfs_stage1_5 (to load from a Reiser journaling fle system) or e2fs_stage1_5 (to load from an
ext2 or ext3 fle system). When the stage 1.5 boot loader is loaded and running, the stage 2 boot loader can be loaded.

With stage 2 loaded, GRUB can, upon request, display a list of available kernels (defned in/etc/grub.conf, with soft links from
/etc/grub/menu.lst and /etc/grub.conf). You can select a kernel and even amend it with additional kernel parameters.
Optionally, you can use a command-line shell for greater manual control over the boot process.

With the second-stage boot loader in memory, the fle system is consulted, and the default kernel image andinitrd image are
loaded into memory. With the images ready, the stage 2 boot loader invokes the kernel image.

Back to top

http://www.ibm.com/developerworks/linux/library/l-linuxboot/[12/24/2010 5:53:09 PM]


Inside the Linux boot process

Kernel
With the kernel image in memory and control given from the stage 2
Manual boot in GRUB
boot loader, the kernel stage begins. The kernel image isn't so much an
executable kernel, but a compressed kernel image. Typically this is a
zImage (compressed image, less than 512KB) or a bzImage (big From the GRUB command-line, you can boot a specifc
compressed image, greater than 512KB), that has been previously kernel with a named initrd image as follows:
compressed with zlib. At the head of this kernel image is a routine that
does some minimal amount of hardware setup and then decompresses grub> kernel /bzImage-2.6.14.2
the kernel contained within the kernel image and places it into high   [Linux-bzImage, setup=0x1400,
memory. If an initial RAM disk image is present, this routine moves it size=0x29672e]
into memory and notes it for later use. The routine then calls the kernel
and the kernel boot begins. grub> initrd /initrd-2.6.14.2.img
  [Linux-initrd @ 0x5f13000, 0xcc199 bytes]
When the bzImage (for an i386 image) is invoked, you begin at
./arch/i386/boot/head.S in the start assembly routine (see grub> boot
Figure 3 for the major fow). This routine does some basic hardware
setup and invokes the startup_32 routine in Uncompressing Linux... Ok, booting the
./arch/i386/boot/compressed/head.S. This routine sets up a kernel.
basic environment (stack, etc.) and clears the Block Started by Symbol
(BSS). The kernel is then decompressed through a call to a C function
called decompress_kernel (located in If you don't know the name of the kernel to boot, just type
./arch/i386/boot/compressed/misc.c). When the kernel is a forward slash (/) and press the Tab key. GRUB will
decompressed into memory, it is called. This is yet another display the list of kernels and initrd images.
startup_32 function, but this function is in
./arch/i386/kernel/head.S.

In the new startup_32 function (also called the swapper or process 0), the page tables are initialized and memory paging is
enabled. The type of CPU is detected along with any optional foating-point unit (FPU) and stored away for later use. The
start_kernel function is then invoked (init/main.c), which takes you to the non-architecture specifc Linux kernel. This is, in
essence, the main function for the Linux kernel.

Figure 3. Major functions fow for the Linux kernel i386 boot

With the call to start_kernel, a long list of initialization functions are called to set up interrupts, perform further memory
confguration, and load the initial RAM disk. In the end, a call is made to kernel_thread (in arch/i386/kernel/process.c) to
start the init function, which is the frst user-space process. Finally, the idle task is started and the scheduler can now take control
(after the call to cpu_idle). With interrupts enabled, the pre-emptive scheduler periodically takes control to provide multitasking.

During the boot of the kernel, the initial-RAM disk (initrd) that was loaded into memory by the stage 2 boot loader is copied into
RAM and mounted. This initrd serves as a temporary root fle system in RAM and allows the kernel to fully boot without having to
mount any physical disks. Since the necessary modules needed to interface with peripherals can be part of the initrd, the kernel
can be very small, but still support a large number of possible hardware confgurations. After the kernel is booted, the root fle system
is pivoted (via pivot_root) where the initrd root fle system is unmounted and the real root fle system is mounted.

The initrd function allows you to create a small Linux kernel with
decompress_kernel output
drivers compiled as loadable modules. These loadable modules give
the kernel the means to access disks and the fle systems on those
disks, as well as drivers for other hardware assets. Because the root The decompress_kernel function is where you see the
fle system is a fle system on a disk, the initrd function provides a usual decompression messages emitted to the display:
means of bootstrapping to gain access to the disk and mount the real
root fle system. In an embedded target without a hard disk, the Uncompressing Linux... Ok, booting the
initrd can be the fnal root fle system, or the fnal root fle system kernel.

http://www.ibm.com/developerworks/linux/library/l-linuxboot/[12/24/2010 5:53:09 PM]


Inside the Linux boot process

can be mounted via the Network File System (NFS).

Back to top

Init
After the kernel is booted and initialized, the kernel starts the frst user-space application. This is the frst program invoked that is
compiled with the standard C library. Prior to this point in the process, no standard C applications have been executed.

In a desktop Linux system, the frst application started is commonly /sbin/init. But it need not be. Rarely do embedded systems
require the extensive initialization provided by init (as confgured through /etc/inittab). In many cases, you can invoke a simple
shell script that starts the necessary embedded applications.

Back to top

Summary
Much like Linux itself, the Linux boot process is highly fexible, supporting a huge number of processors and hardware platforms. In
the beginning, the loadlin boot loader provided a simple way to boot Linux without any frills. The LILO boot loader expanded the boot
capabilities, but lacked any fle system awareness. The latest generation of boot loaders, such as GRUB, permits Linux to boot from a
range of fle systems (from Minix to Reiser).

Resources
Learn

Boot Records Revealed is a great resource on MBRs and the various boot loaders. This resource not only disassembles
MBRs, but also discusses GRUB, LILO, and the various Windows® boot loaders.

Check out the Disk Geometry page to understand disks and their geometries. You'll fnd an interesting summary of disk
attributes.

A live CD is an operating system that's bootable from a CD or DVD without needing a hard drive.

"Boot loader showdown: Getting to know LILO and GRUB" (developerWorks, August 2005) gives you a detailed look at the
LILO and GRUB boot loaders.

In the Linux Professional Institute (LPI) exam prep series of developerWorks tutorials, get a comprehensive introduction to
booting a Linux system and many other fundamental Linux tasks while you prepare for system administrator certifcation.

LILO was the precursor to GRUB, but you can still fnd it booting Linux.

The mkintrd command is used to create an initial RAM disk image. This command is useful for building an initial root fle
system for boot confguration that allows preloading of block devices needed to access the real root fle system.

At the Debian Linux Kernel Project, fnd more information on the Linux kernel, boot, and embedded development.

In the developerWorks Linux zone, fnd more resources for Linux developers.

Stay current with developerWorks technical events and Webcasts.

Get products and technologies

The MicroMonitor provides a boot environment for a variety of small target devices. You can use this monitor to boot Linux in
an embedded environment. It has ports for ARM, XScale, MIPS, PowerPC, Coldfre, and Hitachi's Super-H.

GNU GRUB is a boot shell flled with options and fexibility.

LinuxBIOS is a BIOS replacement. Not only does it boot Linux, LinuxBIOS, itself, is a compressed Linux kernel.

OpenBIOS is another portable BIOS project that operates on a variety of architectures such as x86, Alpha, and AMD64.

At kernel.org, grab the latest kernel tree.

Order the SEK for Linux, a two-DVD set containing the latest IBM trial software for Linux from DB2®, Lotus®, Rational®,
Tivoli®, and WebSphere®.

http://www.ibm.com/developerworks/linux/library/l-linuxboot/[12/24/2010 5:53:09 PM]


Inside the Linux boot process

With IBM trial software, available for download directly from developerWorks, build your next development project on Linux.

Discuss

Check out developerWorks blogs and get involved in the developerWorks community.

About the author

M. Tim Jones is an embedded software architect and the author ofGNU/Linux Application Programming, AI Application Programming,
and BSD Sockets Programming from a Multilanguage Perspective. His engineering background ranges from the development of
kernels for geosynchronous spacecraft to embedded systems architecture and networking protocols development. Tim is a Consultant
Engineer for Emulex Corp. in Longmont, Colorado.

Rate this article


Average rating (998 votes)

1 star

2 stars

3 stars

4 stars

5 stars

Submit

Comments
Add comment:

Sign in or register to leave a comment.

Note: HTML elements are not supported within comments.

1000 characters left

Post

Total comments ( 4)

I am amazed by the quality of articles by Tim. Articles are crisp, clear and very educational, something that you experience in a class
room setups. Not even expansive books covers the most basic stuff called 'boot' in such a reader friendly manner. Thank you so
much!

Posted by ashwinwriter on 18 October Report abuse


2010

http://www.ibm.com/developerworks/linux/library/l-linuxboot/[12/24/2010 5:53:09 PM]


Inside the Linux boot process

Its reall good.got good understanding about boot process..


Thanks Tim.

Regards
Raja

Posted by rajagottipati on 09 October Report abuse


2010

Very Nice Article to understand Linux Boot Process.


Thanks Tim.

With Regards,
Ashish Barot.

Posted by linux4begin on 03 September Report abuse


2010

Error in the Overview

"At this stage, the second-stage boot loader checks the system hardware, enumerates the attached hardware devices, mounts
the root device, and then loads the necessary kernel modules."

It's the Linux kernel, not the boot loader.

Posted by evaldaz on 08 December Report abuse


2009

Back to top

Trademarks  |  My developerWorks terms and conditions

Table of contents

Overview
System startup
Stage 1 boot loader
Stage 2 boot loader
Kernel
Init
Summary
Resources
About the author
Comments

Local resources

developerWorks 中国
developerWorks Japan
developerWorks 한국
developerWorks Vietnam
Technical Briefngs in Asia

My developerWorks community

http://www.ibm.com/developerworks/linux/library/l-linuxboot/[12/24/2010 5:53:09 PM]


Inside the Linux boot process

Interact, share, and communicate with


developers worldwide.

My Home
Profles
Groups
Blogs
Bookmarks
Activities
Files
Wikis
Forums
Podcasts

My developerWorks overview

Tags

Use the search feld to fnd


all types of content in My
developerWorks with that
tag. Popular tags shows
the top tags for this
particular content zone
(for example, Java
technology, Linux,
WebSphere). My tags
shows your tags for this
particular content zone
(for example, Java
technology, Linux,
WebSphere).
Search all tags

Popular article tags | 


My article tagsSkip to tags list

Popular tags

ajax (145)  
and (28)  
android (50)  
apache (34)  
api (23)  
apis (23)  
application_a... (72)
 
application_... (260)
 
architecture (188)  
architecture_... (41)
 
architecture_-...
(23)  
atom (27)  
bpel4ws_(bpel_...
(23)  
business_model...
(25)  
business_proce...
(38)  

http://www.ibm.com/developerworks/linux/library/l-linuxboot/[12/24/2010 5:53:09 PM]


Inside the Linux boot process

business_proc...
(48)  
business_servi...
(24)  
cloud (69)  
cloud_computi...
(71)  
components (40)  
confguration_...
(23)  
databases_and...
(75)  
design (35)  
development (29)  
dojo (28)  
dom_(document_...
(33)  
eclipse (77)  
frameworks (25)  
general_progr...
(66)  
green_it (26)  
html (53)  
html5 (27)  
integration (47)  
interoperabil... (46)
 
j2ee_(java_2_e...
(25)  
java (249)  
java_technol...
(109)  
javascript (78)  
jquery (33)  
jsf (27)  
json (24)  
linux (197)  
mashups (30)  
messaging (60)  
on_demand_busi...
(26)  
open_source (139)
 
open_technolog...
(26)  
parsing (28)  
patterns (35)  
performance (66)  
perl (27)  
php (87)  
php_(hypertex...
(66)  
programming (30)  
python (58)  

http://www.ibm.com/developerworks/linux/library/l-linuxboot/[12/24/2010 5:53:09 PM]


Inside the Linux boot process

rest (47)  
schemas (46)  
security (66)  
services (43)  
soa (71)  
soa_(service...
(148)  
soap_(simple_...
(92)  
spring (25)  
standards (84)  
standards_and...
(56)  
tips (44)  
virtualization (27)  
web (89)  
web_2.0 (76)  
web_authoring (24)
 
web_developme...
(54)  
web_services (251)
 
websphere (47)  
wsdl_(web_ser...
(46)  
xhtml_(extensi...
(27)  
xml (301)  
xpath_(xml_pat...
(34)  
xquery_(xml_qu...
(24)  
xslt (35)  
xslt_(xsl_tran... (35)
 

End of Popular tags

My tags

To access My Tags, please


sign in
Read Popular tags

End of My tags

More Less

ajax (145)   and (28)   android


(50)   apache (34)   api (23)   apis
(23)   application_a... (72)  
application_... (260)  
architecture (188)  
architecture_... (41)  
architecture_-... (23)   atom (27)  
bpel4ws_(bpel_... (23)  
business_model... (25)  
business_proce... (38)  

http://www.ibm.com/developerworks/linux/library/l-linuxboot/[12/24/2010 5:53:09 PM]


Inside the Linux boot process

business_proc... (48)  
business_servi... (24)   cloud (69)  
cloud_computi... (71)  
components (40)  
confguration_... (23)  
databases_and... (75)   design
(35)   development (29)   dojo (28)  
dom_(document_... (33)   eclipse
(77)   frameworks (25)  
general_progr... (66)   green_it
(26)   html (53)   html5 (27)  
integration (47)  
interoperabil... (46)  
j2ee_(java_2_e... (25)   java
(249)   java_technol...
(109)   javascript (78)   jquery
(33)   jsf (27)   json (24)   linux
(197)   mashups (30)  
messaging (60)  
on_demand_busi... (26)  
open_source (139)  
open_technolog... (26)   parsing (28)
  patterns (35)   performance (66)  
perl (27)   php (87)  
php_(hypertex... (66)  
programming (30)   python (58)  
rest (47)   schemas (46)  
security (66)   services (43)  
soa (71)   soa_(service...
(148)   soap_(simple_... (92)  
spring (25)   standards (84)  
standards_and... (56)   tips
(44)   virtualization (27)   web (89)
  web_2.0 (76)   web_authoring
(24)   web_developme... (54)  
web_services (251)  
websphere (47)  
wsdl_(web_ser... (46)  
xhtml_(extensi... (27)   xml
(301)   xpath_(xml_pat... (34)  
xquery_(xml_qu... (24)   xslt (35)  
xslt_(xsl_tran... (35)  

View as cloud | list

Dig deeper into Linux on


developerWorks

Overview

New to Linux

Downloads and products

Open source projects

Technical library (articles,


tutorials, training, and more)

Forums
Events

Newsletter

Stay ahead of the latest cloud


trends

http://www.ibm.com/developerworks/linux/library/l-linuxboot/[12/24/2010 5:53:09 PM]


Inside the Linux boot process

Cloud Computing resources from


developerWorks

Special offers

Trial software offers

About IBM
Privacy
Contact
Terms of use
IBM Feeds
Jobs

http://www.ibm.com/developerworks/linux/library/l-linuxboot/[12/24/2010 5:53:09 PM]

You might also like