Booting process of Linux
![]() | This article needs attention from an expert in Linux. Please add a reason or a talk parameter to this template to explain the issue with the article. |
The Linux Startup Process is the process by which Linux based operating systems initialize.
Boot Loader phase
The boot loader phase varies by platform. Since the earlier phases are not specific to the OS, the boot process is considered to start:
- For x86 or x64: when the partition boot sector code is executed in real mode and loads the first stage boot loader (typically a part of LILO or GRUB).
From that point, the boot process continues as follows:
The first stage boot loader loads the remainder of the boot loader, which gives a prompt asking which operating system (or type of session) you wish to initialize. Under LILO, this is done via the map installer which reads the configuration file /etc/lilo.conf
to identify the available systems. It includes data such as boot partition and kernel location for each, as well as customized options if any. Upon selection, the appropriate kernel is loaded into RAM memory as an image file ("initrd"), and along with with the appropriate parameters, control is passed to it.
LILO and GRUB differ in some ways:[1]
- LILO does not understand file systems, so it uses raw disk offsets and the BIOS for data load. It loads the menu code, and then depending on the response loads either the 512 byte disk sectors for an MBR system such as Windows, or the kernel image for Linux.[1]
- GRUB by contrast does have understanding of the common ext2 and ext3 file systems.[2] Because GRUB stores its data in a configuration file rather than the MBR and contains a command line interface, it is often easier to rectify or modify GRUB if misconfigured or corrupt.[3]
GRUB
- Source: Redhat GRUB description.
- The first stage loader is read by the BIOS from the MBR.
- The first stage loads the rest of the boot loader (second stage). If the second stage is on a large drive, sometimes an intermediate 1.5 stage is loaded, which contains extra code to allow cylinder heads above 1024, or LBA type drives, to be read. The 1.5 boot loader is stored (if needed) in the MBR or the boot partition.
- The second stage boot loader executes, and displays the GRUB startup menu. It also allows choice of operating environment, and examination of system parameters.
- When an operating system is chosen, it is loaded and control is passed.
GRUB supports both direct and chain-loading boot methods, LBA, ext2, and "a true command-based, pre-OS environment on x86 machines". It contains three interfaces: a selection menu, a configuration editor, and a command line console.
LILO
LILO, the older of the two boot loaders, is almost identical to GRUB in process, except that it does not contain a command line interface. Thus all changes must be made to its configuration and written to the MBR, and then the system restarted. An error in configuration can therefore leave a disk unable to be booted without use of a separate boot device (floppy disk etc) containing a program capable of fixing this.[3] Additionally it does not understand file systems, instead locations of image files are stored within the MBR directly[3] and the BIOS is used to access them directly.
Kernel and Init phases
The kernel in Linux handles core processes, such as memory management, task scheduling, I/O, interprocess communication, and overall system control. Upon being loaded and executing, the kernel starts by looking for an init process to run.
Kernel phase
The kernel initializes devices, mounts the root filesystem specified by the boot loader as read only, and runs Init (/sbin/init
) which is designated as the first process run by the system (PID = 1).[1] A message is printed by the kernel upon mounting the file system, and by Init upon starting the Init process. It may also optionally run Initrd to allow setup and device related matters (ram disk or similar) to be handled before the root file system is mounted.[1]
Init phase
"Init is the father of all processes. Its primary role is to create processes from a script stored in the file /etc/inittab
. This file usually has entries which cause init to spawn gettys on each line that users can log in. It also controls autonomous processes required by any particular system. A run level is a software configuration of the system which allows only a selected group of processes to exist. The processes spawned by init for each of these run levels are defined in the /etc/inittab file.– manual page for Init[4]
Init's job is "to get everthing running the way it should be", [5] including checking and mounting file systems, starting up services, and ultimately switching to a user-based environment when system startup is completed. It is similar to the Unix and BSD init processes, from which it derived, but in some cases has diverged or become customized. In a standard Linux system, Init is executed with a parameter, known as a runlevel, that takes a value from 1 to 6, and that determines which subsystems are to be made operational. Each runlevel has its own script which codifies the process involved for the given runlevel, and it is these scripts which are referenced as necessary in the boot process. Init scripts are typically held in directories with names such as "/etc/rc..."
. Corresponding scripts also exist to direct the process required when leaving each runlevel. The top level configuration file for init is at /etc/inittab
.[5]
During system boot, it checks whether a default runlevel is specified in /etc/inittab, and requests the runlevel to enter via the system console if not. It then proceeds to run all the relevant boot scripts for the given runlevel, including loading modules, checking the integrity of the root file system (which was mounted read-only) and then remounting it for full read-write access, and sets up the network.[1]
After it has spawned all of the processes specified, init waits for processes it started to die, for a power failure signal, or a request via /sbin/telinit
to further change the runlevel.[4]
Sources
References
- ^ a b c d e http://oldfield.wattle.id.au/luv/boot.html Linux Boot Process - by Kim Oldfield (2001)]
- ^ http://www.redhat.com/docs/manuals/linux/RHL-9-Manual/ref-guide/s1-boot-init-shutdown-process.html
- ^ a b c http://www.redhat.com/docs/manuals/linux/RHL-9-Manual/ref-guide/s1-grub-lilo.html
- ^ a b http://man.he.net/man8/init
- ^ a b http://axiom.anu.edu.au/~okeefe/p2b/power2bash/power2bash-6.html