Linux system Boot Process

Source: Internet
Author: User

Linux boot process

Objective:

Linux is a free and open source Unix-like operating system. The kernel of the operating system was first released by Linus Torvalds on October 5, 1991. After adding the user-space application, it becomes the Linux operating system. Linux is the most famous example of the development of free software and open source software.

Contact Linux time is not short, has been directly using the Linux operating system to do some work, very little to understand the system from the boot to the use of the entire process, feel the need to understand the whole system of the START process, so write this blog to deepen understanding.

First through a graph to understand the whole system start process, the whole process can be divided into post-->bios-->mbr (GRUB)-->kernel-->init-->runlevel. The role of each procedure is explained in detail below.

Figure 1-1: System startup process

Bios

BIOS (Basicinput/outputSystem), the basic input and output systems, the system is stored on the motherboard ROM chip, the computer at boot, will be the first to read the system, and then there will be a power-on self-test process, which is actually checking the CPU and memory , the computer's most basic constituent unit (Controller, arithmetic, and memory) also checks other hardware and starts loading the BIOS program into memory without exception. Detailed BIOS function, this side does not say, the BIOS is a main function is to store the disk boot sequence, the BIOS will follow the boot sequence to find the first disk header MBR information, and load and execute the MBR of the bootloader program, if the first disk does not exist MBR, will continue to find the second disk (PS: Boot sequence can be set in the BIOS interface), once the bootloader program is detected and loaded in memory, the BIOS will transfer control to the bootloader program.

Mbr

MBR (master bootrecord), master boot record, MBR is stored on disk head, size 512bytes, where 446bytes is used to store bootloader program, 64bytes is used to store partition table information, The last 2bytes is used for the validity check of the MBR.

Grub

GRUB (Grand Unified Bootloader), a multi-system launcher, can be executed in three steps:

    Stage1: This is actually MBR, its main job is to find and load the second paragraph bootloader program (STAGE2), but the system does not start, the MBR can not find the file system, and can not find the location of the stage2, therefore, There's stage1_5.

    stage1_5: This step is to identify the file system

    Stage2: The GRUB program will be based on/boot/grub/ The grub.conf file looks for kernel information and then starts loading the kernel program, and when the kernel program is detected and loaded into memory, grub transfers control to the kernel program.

    PS: In fact this step/boot has not been mounted, grub directly identifies the filesystem of the disk on which grub is located, so it should actually be a/grub/grub.conf file with the following information :

   Grub.conf: 

    #boot =/DEV/SDA

Default=0 #设定默认启动的title的编号, starting from 0

Timeout=5 #等待用户选择的超时时间

Splashimage= (hd0,0)/boot/grub/splash.xpm.gz #GRUB的背景图片

Hiddenmenu #隐藏菜单

Title CentOS (2.6.18-194.el5pae) #内核标题

Root (hd0,0) #内核文件所在的设备

Kernel/vmlinuz-2.6.18-194.el5pae ro root=label=/ #内核文件路径以及传递给内核的参数

Initrd/initrd-2.6.18-194.el5pae.img #ramdisk文件路径

Kernel

Kernel, kernel, Kernel is the most important Linux system program, in fact, the Kernel file is very small, only the most basic module, and stored in compressed file form on the hard disk, when grub will Kernel read into memory, memory began to extract the kernel files. The kernel boot, you should first talk about the initrd this file,

INITRD (Initial RAM Disk), which is copied into memory at Stage2 This step, is generated when the system is installed and is a temporary root file system (ROOTFS). Because kernel in order to simplify, only retain the most basic module, therefore, kernel does not have a variety of hardware driver, also can not know rootfs device, therefore produced initrd this file, the file loaded the necessary driver module, when the kernel start, The driver module can be loaded from the INITRD file until the real rootfs is mounted, and the INITRD is removed from memory.

Kernel will mount the root filesystem as read-only, and when the root file system is mounted, the first process (user-space process) is loaded, the/sbin/init is executed, and control is then handed over to the INIT program.

Init

Init, initialized, as the name implies, the program is the OS initialization operation, is actually based on/etc/inittab (defined by the system default RunLevel) set the action to execute the script, the first executed script is/etc/rc.d/ Rc.sysinit, this is a real OS init script that simply tells the task of the script (you can go to the actual script and see what you've done):

1, activate Udev and selinux;2, according to the/etc/sysctl.conf file, set the kernel parameters, 3, set the system clock, 4, load the hard disk mapping, 5, enable the swap partition, 6, set the hostname, 7, root file system detection, and read and write to re-mount the root file system; 8 , activate raid and LVM devices, 9, enable disk quotas, 10, check and mount other file systems according to/etc/fstab, 11, clean outdated locks and PID files

After execution, according to the configured start level, executes the script under the corresponding directory, and finally executes the/etc/rc.d/rc.local script, at this point, the system starts to complete.

  

Runlevel

RunLevel, run level, different level will start the service is not the same, Init according to the defined level to execute the script under the corresponding directory, Linux boot level is divided into the following

0: Shutdown mode

1: Single user mode (directly into the administrator status)

2: Multi-user mode (no network)

3: Multi-user mode (command line)

4: Reserved

5: Multi-user mode (graphical interface)

6: Restart

Under different operating levels,/ETC/RC.D/RC this script executes scripts in different directories, respectively.

    • Run level 0–/etc/rc.d/rc0.d/
    • Run level 1–/etc/rc.d/rc1.d/
    • Run level 2–/etc/rc.d/rc2.d/
    • Run level 3–/etc/rc.d/rc3.d/
    • Run level 4–/etc/rc.d/rc4.d/
    • Run level 5–/etc/rc.d/rc5.d/
    • Run level 6–/etc/rc.d/rc6.d/

The scripts in these directories only k* and s* start files, K starts the file for the boot need to perform the shutdown service, s start the file for the boot need to perform the open service.

Reference:

http://www.thegeekstuff.com/2011/02/linux-boot-process/

http://www.ibm.com/developerworks/library/l-linuxboot/

Linux system Boot 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.