The Linux Boot Process

Linux OS Topics
Post Reply
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

The Linux Boot Process

Post by Saman » Fri Oct 02, 2009 11:54 pm

One of the more powerful features of Linux is how the system boots. Linux can run in many different ways and with specific goals. Do you want to run a graphical user interface (GUI) such as KDE or do you strictly want to run only enough applications to get you to a command line? Linux is highly flexible and can run under many different conditions.

This section will give you a basic understanding as to what is happening when a Linux system is powered on and what Linux will do in order for it to become functional to the end user.

Turning Your System On
As soon as you turn on your system, your computer (specifically your motherboard's BIOS) will run a series of tests. These tests are called POST (for Power On Self Test). The purpose of these tests is to make sure your hardware settings are configured correctly. It will test to see how much memory is installed, if your devices are working correctly and locate what devices the system can use to continue the boot process.

This process is operating system agnostic. Meaning regardless of what operating system you are currently using, the POST will be executed as soon as you hit the power button on your system.

Boot Loader
Once the BIOS finds a hard drive to boot from, it passes control over to the boot loader. Since a hard drive can have multiple operating systems installed on multiple partitions, the boot loaders function is to give the user a list of choices he/she can make to continue. A user could potentially have MS Windows and a few Linux distributions on one hard drive. The boot loader will give the user the option to choose which operating system they want to run.

The two most popular boot loaders for Linux are the LInux LOader (LILO) and the GRand Unified Bootloader (GRUB). The latter being more popular and flexible.

As soon as a selection is made to boot a Linux system, control is passed over to start the kernel (the "core" of the operating system).

Process Number One
Once the kernel is loaded, it will then execute the first program, init. Init will always be the first program since it's main function is to start other programs.

The first thing init does is look for its configuration file at /etc/inittab. This file tells init how we want it to run. Init then goes ahead and sets up the proper working environment.

Run Levels
Linux can be set up to run in 5 configurable states. Each of these states is called a run level. Each run level can be set up to run Linux in a different "mode". Say you wanted Linux to boot up only to a command line with no graphical user interface? You can configure one run level to execute all the programs needed in order for Linux to achieve that goal.

The basic breakdown of the run levels could looks something like:

Code: Select all

# Default run level. The run levels are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without networking 
#	(The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
This should give you a better visual idea on the purpose of run levels. As you can see in the earlier paragraph, there are 5 configurable run levels. The 0 and 6 options are non-configurable options. Every run level from 1 to 5 can be manually changed and tinkered with. You as the owner of the system are not confined to what the above run levels say. If you want to run X11 (required by KDE and GNOME) to run on run level 3 you are free to do so. The above specification is only meant as a guideline.

Note: Most of the popular Linux distributions follow this run level specification, although some use a custom one.

Init Scripts
Just because you told init to run in run level 3 means nothing. init needs a method of starting and stopping programs to achieve this goal. This is where init scripts come into play. Most of the Linux distributions use a specific method called SysV. If you navigate to your /etc directory, you should see a folder called rcX.d (The X will be a number from 0-6).

A basic listing will look something like:

[user@localhost:/etc/rc3.d]$ ls
READMES20dkms_autoinstallerS30kdmS89anacron
S01policykitS20hotkey-setupS31atieventsdS89atd
S10acpidS20lastfmproxyS50avahi-daemonS89cron
S10apmdS20postfixS50cupsS90binfmt-support
S10sysklogdS20powernowdS50NetworkManagerS91apache2
S11klogdS20sambaS50pulseaudioS98usplash
S12dbusS20ushareS50rsyncS99acpi-support
S16sshS20vboxdrvS50sanedS99laptop-mode
S17mysql-ndb-mgmS20winbindS50system-tools-backendsS99ondemand
S18mysql-ndbS24halS70bootlogs.shS99rc.local
S19mysqlS25bluetoothS70dns-cleanS99rmnologin
S20apportS30gdmS70pppd-dnsS99stop-readahead
As you can see from above each file starts with a S than a number. The S stands for start and the number is the priority in which each script will run, with lower numbers having a higher priority thus starting before others with a higher number.

Note: On run level 0 and 6, each script starts with a K instead of a S. This signifies that the process should be killed instead of started.

Turning Off
If you wanted to shut off your computer, you can issue the reboot, halt or shutdown command. Just like other operating systems, Linux requires enough time to properly shutdown all background processes and programs. Simply cutting the power or hitting the power button on your machine can cause damage to your system.

Note: On some newer Linux distributions, when you hit the power button on your computer, Linux will recognize this and issue the proper shutdown command.
Post Reply

Return to “Linux”