Linux Learning Path Start-up process

Source: Internet
Author: User

Linux boot-up process

At the beginning of the system, the system will actively read the BIOS loading hardware information and hardware self-detection, and according to the set of the first boot device to obtain the MBR (main boot record area) in the boot loader (boot management program, such as Grub), The boot manager can then load the kernel into memory to decompress and execute, and the kernel can run in memory. The kernel then detects all the hardware, and if some hardware is not recognized, it is necessary to load the hardware driver to mount the root filesystem. At this point the kernel can run the first program Init, and wait until the INIT program has finished running, the entire Linux runtime is ready, waiting for the user to log in.

The Linux boot process can be divided into the following sections:

1, read the BIOS load hardware information and self-detection

2. Read the boot loader in the MBR of the first bootable device.

3. Boot loader load kernel into memory to decompress and run

4. The kernel detects all hardware information and loads the relevant hardware driver to mount the root file system

5, run/sbin/init this program, to manage the user space of all processes or services

6, init This program after running, waiting for users to log in.


The design style of the kernel

Single core: The kernel of this design is to compile many modules directly into the kernel, so the core capacity of the design is relatively large

Microkernel: This design kernel designs many sub-functions into modules, so when the system requires only the relevant modules to be loaded

, so this design has a smaller core size.

and the module in kernel is called kernel object (KO).

In the kernel, designed by Redhat and SuSE, is composed of cores and modules that can load kernel modules to do the functions.


We know that the kernel accesses the root file system to access the/sbin/init on the disk, and to access the root filesystem, the root filesystem must be mounted before it can be accessed, and the root file system mount requires kernel to load the hardware driver to identify the disk. This completes the mount of the root file system.

Generally speaking, our hardware driver or other function module is placed in the/lib/modules/' uname-r '/kernel/directory, so this driver is also stored on the disk, and the kernel is unable to recognize the hard disk, then how to load the corresponding driver?

At this time we need to use INITRD this program. Boot loader can load this file into memory and unzip it into a root directory to form a virtual file system (RAMDisk). This virtual file system contains the relevant modules required for booting. Usually these modules are USB, RAID, LVM, SCSI and other file system and disk interface driver. The kernel can therefore load these related modules and release the virtual file system to identify the disk. To actually complete the mount of the root file system. After the root file system is mounted, then kernel can rerun the/sbin/init program, completing the process initialization of the user space.

In Rhel 5, the virtual file system was formed using the INITRD program.

In Rhel 6, the virtual file system was formed by INITRAMFS.


Starting from above, we found that the Linux kernel was loaded into memory by the boot Manager (boot loader). If there is no boot loader kernel that cannot be loaded into memory, then the system will not be able to run. So boot loader is the most important program in the whole system startup process. Now the most mainstream boot loader is the GRUB program.

So how did grub complete the kernel load?

Grub complete kernel loading can be divided into 2 phases:

The first stage: main implementation of the boot loader main program, this program is placed in the MBR

Second Stage: Boot loader load the main configuration file, this configuration file is/boot/grub/grub.conf

The main information included are as follows:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/41/5D/wKiom1PTxQOyMwXoAAG_lRsBD8w224.jpg "title=" Grub.png "alt=" Wkiom1ptxqoymwxoaag_lrsbd8w224.jpg "/>

Default=0: Set the title number of the default startup, starting with 0

Timeout=5: Waits for the user's timeout length (if not pressed on the keyboard), in seconds

Splashimage= (hd0,0)/grub/splash.xmp.gz

Hiddenmenu: Hide Menu

Title Red Hat Enterprise Linux Server (2.6.18-308.el5): kernel title or operating system name, can be freely modified

Root (hd0,0) #表示内核所在的设备, for grub, all types of hard drives are HD, so the device format is

HD (#,n), where # represents the first few hard disks, and the last N represents the first partition on the disk. The default numbers are

is starting from 0.

Kernel/vmlinuz-2.6.18-308.el5 ro root=lable=/rhgb quiet #内核文件所在的路径, as well as delivery

parameters to the kernel; if/boot does not have a separate partition, then the path is/boot/vmlinuz*

Initrd/initrd-2.6.28-308-el5.img #ramdisk文件路径

Where 2.6.18-308.el5 is the kernel version, you can use Uname-r to view


In the/proc directory, there is a file called CmdLine which is used to save the parameters of the kernel.

In the/pooc/directory, under each process directory, there is also a cmdline file, which is the command that executes when the process starts.


The configuration file for Init is/etc/inittab

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/41/5D/wKiom1PTzK-zLI4KAASJWMp1FGc077.jpg "title=" Init.png "alt=" Wkiom1ptzk-zli4kaasjwmp1fgc077.jpg "/>

Each part of the information represents the meaning of:

Id:3:initdefault: #表示该系统默认运行的等级为3

Si::sysinit:/etc/rc.d/rc.sysinit #表示系统初始化

/etc/rc.d/rc.sysinit's main tasks include the following sections:

1. Activate Udev and SELinux

2, according to/etc/sysctl.conf to set the kernel parameters

3. Set the clock

4. Load Keyboard mapping

5. Start the swap partition

6. Set Host name

7, the root file system detection, and read-write innovative mount

8. Activating RAID and LVM devices

9. Boot Disk quotas

10, according to/etc/fstab to mount other file system

11. Purge expired locks and PID files

L0:0:WAIT:/ETC/RC.D/RC 0
L1:1:WAIT:/ETC/RC.D/RC 1
L2:2:WAIT:/ETC/RC.D/RC 2
L3:3:WAIT:/ETC/RC.D/RC 3
L4:4:WAIT:/ETC/RC.D/RC 4
L5:5:WAIT:/ETC/RC.D/RC 5
L6:6:WAIT:/ETC/RC.D/RC 6

#这里的每一行可以使用id: Runlevels:action:process to show

#这里的每一行都是用冒号来分成四段的, the meaning of each paragraph is that:

The first paragraph represents the ID of the run level

The second paragraph indicates the level of system operation

The third paragraph indicates under what circumstances the system will perform this line

The fourth paragraph represents the program that the system operates, usually a few scripts

Where action (the third piece of information) can have these:

Initdefault: Setting the default Run level

Sysinit: Performing system initialization

Wait: Execution when the waiting level switches to this level

Respawn: Restarts immediately once the program is terminated

Where/ETC/RC.D/RC 3 represents the information of the script to be executed at a certain level, followed by the number [0-6], which represents the argument when the script is run, that is, $ $.

Take/ETC/RC.D/RC 3 As an example: Get the script directory to execute by means of---/etc/rc$1.d/

(Here is/etc/rc3.d/) This directory, which contains a lot of k* and s* files.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/41/5D/wKiom1PT1LGjx-LtAALZDmsQTQE421.jpg "title=" Rc.d.png "alt=" Wkiom1pt1lgjx-ltaalzdmsqtqe421.jpg "/>

When switching to the specified level, the k* file is closed first, and then the s* file is started, the files are system services, and are linked files, the real service file exists/etc/init.d/or/etc/rc.d/init.d/this directory.

Each file is represented by a two-digit # #组成, which represents the priority order in which the service starts or shuts down, and the smaller the number, the more priority is chosen.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/41/5D/wKioL1PT173xZvuIAAIbeM5Sjq8800.jpg "title=" ll.png "alt=" Wkiol1pt173xzvuiaaibem5sjq8800.jpg "/>

Where/etc/rc.local is a script file, a file that is executed at the end of the system

This article from the "Linux Learning Path" blog, declined reprint!

Linux Learning Path Start-up process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.