The Boot Process
- The Bootstrap Process – First Stage (BIOS)
The PC boot process is started on power-up . The processor will start execution of code contained in the Basic Input and Output System (BIOS). The BIOS is a program stored in Read Only Memory (ROM) and is the lowest level interface between the computer and peripherals.
BIOS then does the Power On Self Test, or POST routine runs to find certain hardware and to test that the hardware is working at a basic level. It compares the hardware settings in the CMOS (Complementary Metal Oxide Semiconductor) to what is physically on the system. It then initialize the hardware devices.
Once the POST is completed, the hardware jumps to a specific, predefined location in RAM. The instructions located here are relatively simple and basically tell the hardware to go look for a boot device. Depending on how your CMOS is configured, the hardware first checks your floppy and then your hard disk.
When a boot device is found (let’s assume that it’s a hard disk), the hardware is told to go to the 0th (first) sector (cylinder 0, head 0, sector 0), then load and execute the instructions there. This is the master boot record, or MBR .
The BIOS will first load the MBR into memory which is only 512 bytes in size and points to the boot loader (LILO: Linux boot loader) or GRUB.
Once the BIOS finds and loads the boot loader program into memory, it yields control of the boot process to it.
The Boot Loader – Stage 2
LILO or GRUB allows the root user to set up the boot process as menu-driven or command-line, and permits the user to choose from among several boot options.
It also allows for a default boot option after a configurable time-out, and current versions are designed to allow booting from broken Level 1 (mirrored) RAID arrays.
It has the ability to create a highly configurable, “GUI-fied” boot menu, or a simple, text-only, command-line prompt.
Depending on the kernel boot option chosen or set as default, lilo or grub will load that kernel .
The boot loader will load the kernel and initial root file system image into memory and then start the kernel, passing in the memory address of the image. At the end of its boot sequence, the kernel tries to determine the format of the image from its first few blocks of data:
* In the initrd scheme, the image may be a file system image (optionally compressed), which is made available in a special block device (/dev/ram) that is then mounted as the initial root file system. The driver for that file system must be compiled statically into the kernel. Many distributions originally used compressed ext2 file system images. Others (including Debian 3.1) used cramfs in order to boot on memory-limited systems, since the cramfs image can be mounted in-place without requiring extra space for decompression.
Once the initial root file system is up, the kernel executes /linuxrc as its first process. When it exits, the kernel assumes that the real root file system has been mounted and executes /sbin/init to begin the normal user-space boot process.
- In the initramfs scheme (available in Linux 2.6.13 onwards), the image may be a cpio archive (optionally compressed). The archive is unpacked by the kernel into a special instance of a tmpfs that becomes the initial root file system. This scheme has the advantage of not requiring an intermediate file system or block drivers to be compiled into the kernel. Some systems use the dracut package to create the initramfs.
On an initramfs, the kernel executes /init as its first process. /init is not expected to exit.
Kernel Loading – Stage 3
4. Final Stage – Init
The first thing the kernel does after completing the boot process is to execute init program.
The /sbin/init program (also called init) coordinates the rest of the boot process and configures the environment for the user.Init is the root/parent of all processes executing on Linux which becomes process number 1.
When the init command starts, it becomes the parent or grandparent of all of the processes that start up automatically on a Red Hat Linux system.
Based on the appropriate run-level in the /etc/inittab file , scripts are executed to start various processes to run the system and make it functional.
5. The Init Program
As seen in the previous section, the kernel will start a program called init or /sbin/init
The init process is the last step in the boot procedure and identified by process id “1”.
The init command then runs the /etc/inittab script.
The first thing init runs out of the inittab is the script /etc/rc.d/rc.sysinit , which sets the environment path, starts swap, checks the file systems, and takes care of everything the system needs to have done at system initialization.
Next, init looks through /etc/inittab for the line with initdefault in the third field. The initdefault entry tells the system what run-level to enter initially.
id:5:initdefault: ( 5 is the default runlevel)