Summary Linux system startup process

Source: Internet
Author: User

Linux system startup Process analysis:

  Press Power--BIOS self-test--system boot (lilo/grub)--Start the kernel--Initialize the system--User Login

1. BIOS Self-test:

The BIOS (Basic input/output system), also known as the basic input and output system, can be regarded as a permanent recording of a software in ROM, which is part of the operating system input and output management.
There are two functions of the BIOS: The post code and the runtime service. After the post phase is complete it will be purged from memory and the runtime service will remain for the target operating system to start
The detailed work done in the BIOS two phases is as follows:
(1) power-on self-test post (power-on), mainly responsible for detecting the peripheral critical equipment is working properly. For example: The most common is the memory is loose, the BIOS self-test phase will be error.
(2) After step 1 succeeds, a small program is executed to enumerate the local device and initialize it. This step is primarily based on the system boot order that we set up in the BIOS to search for the drive that is used to boot the system.
Such as: Hard disk, CD-ROM, USB drive, floppy disk and network.
Take the hard drive as an example: the BIOS now reads the first sector of the hard disk (MBR 512 bytes) and executes the code inside. In fact, the BIOS does not matter what is inside the first sector, it is only responsible for reading the sector content and executing it.
At this point, the BIOS task is completed, and then the control of the system starts to hand over the MBR part of the code.

2. System boot:
    mbr (Master boot Record): Disk 0 cylinders, 0 heads, 1 sectors are referred to as the primary boot sector. It consists of three parts: the Master Boot Program (bootloader), the hard disk partition table DPT, the hard disk valid flag
     Typically, such as: Lilo/grub These common boot programs are installed directly in the bootloader of the MBR.
    
    grub boot is also divided into two stages stage1 and Stage2
         Stage1 is directly written to the MBR of the bootloader, the machine starts, the control to the bootloader, bootloader stored in the STAGE1 code, its task is simple, only the hard disk 0 Head 0 2 sector
          read in memory. The 0-First 0-Channel 2-sector content is/stage2/start in the source code. S compiled 512 bytes, Stage1 is not capable of identifying file systems.
        

3. Boot the kernel:
When Stage2 is loaded into memory execution, it first resolves/boot/grub/grub.conf, then loads the kernel image into memory and transfers control to the kernel. The kernel immediately initializes each device in the system and configures it.
The loading of Linux device drivers is partially compiled directly into the kernel, while the other drivers are placed in initrd in the form of modules.
In fact, the Linux kernel only contains basic hardware drivers, during the system installation process will detect the system hardware information, according to the installation information and system hardware information to the part of the device driver written to INITRD, so that in the future when the system, a part
The device driver is placed in the INITRD to load.
Another concept: Initramfs when the kernel starts, the kernel unlocks the CPIO package and releases the file systems it contains into ROOTFS. Some of the initialization code in the kernel is put into this filesystem and executed as a user-level process.
The obvious benefit is that the kernel initialization code is streamlined, and the kernel initialization process is made easier.

Grub's stage2 loads the INITRD into memory and then releases the contents into memory, and the kernel executes the init script in Initrd, when the kernel gives control to the init file processing. Init is primarily loaded with various storage media related device drivers,
When the required driver is loaded, a root device is created, and the root file system is mounted as read-only. At this point, INITRD is freed from memory, converted to the real root filesystem, running the/sbin/init program, executing
The system's process number 1th. The control of the system has since been given full power to the/sbin/init process.

4. Initialize the system:

/sbin/init---/etc/inittab---/etc/rc.d/rc.sysinit,/etc/rc.d/*--and/etc/rc.local--Login interface ( USERNAME/PASSWD) --/etc/profile.d/file--/etc/profile
 |
|-->/etc/sysctl.conf
|-->/etc/fstab

--/ETC/BASHRC-- ~/.BASHRC-~/.bash_profile

/sbin/init is the parent process of all processes, when it takes over control of the system:
(1) It will first read the/etc/inittab file to execute the corresponding script to initialize the system, such as: Set the keyboard, font, loading module, configure the network.
(2) Get the network environment and host type. First read the network environment Profile '/etc/sysconfig/network ' to get the host name and default gateway network environment
(3) Detection and loading of memory device/proc and USB device/sys in addition to/proc, the system will proactively detect if there is a USB device, and actively load the USB drive, try to mount the USB file system
(4) Decide whether to start SELinux
(5) Testing of interface devices and test of Plug and Play parameters
(6) Loading of user-defined modules. The user can add a custom module to the '/etc/sysconfig/modules/*.modules ', which is then loaded into the system.
(7) Load the core related settings. Press '/etc/sysctl.conf ' to configure the function for this file setting value.
(8) Set the system time.
(9) Set the font for the terminal console.
(10) Set up RAID and LVM HDD function
(11) Read-only detection of disk file systems
(12) Conversion of disk quota quota
(13) Re-enter system disk as read-only
(14) Start quota function
(15) Start the system random number device
(16) Clear the temporary files during the startup process.
(17) Load the boot information into the '/VAR/LOG/DMESG ' file

When the/etc/rc.sysinit is finished, the system will work smoothly. Just need to start the system requires a variety of services, so that the host can provide the relevant network and host functions.

Finally put a diagram to explain the start-up process:

Summary Linux system startup 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.