Linux start-up process detailed

Source: Internet
Author: User

LinuxSTART ProcessFirst PartLinuxstart a basic knowledge1.1 Linux centos6.8Start Flowchart

650) this.width=650; "width=" 696 "height=" 323 "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd; "alt=" Spacer.gif "/>

BIOS power On self test à load mbrà load boot grub à load kernel à start/sbin/init process à start/bin/login process à Go to landing page

1.2 BIOS(Basic Input/output System) basic input/output system

The BIOS is the most basic software code that is loaded on a computer's hardware system. Its main function is to provide the lowest, most direct hardware setup and control for the computer. It holds the computer's most important basic input and output programs, System setup information, post-boot self-test programs and system self-starter programs. The BIOS program is generally stored in the motherboard ROM (read-only memory chip), even after the shutdown or power down, the program will not be lost.

The main functions of the BIOS can be divided into the following three points:

    • Self-Test and Initialization program post (Power on self test):

After the computer is powered on, the post program will check all internal devices, complete self-test includes the CPU, 640K basic memory, 1M expansion memory, ROM, motherboard, CMOS memory, serial port, display card, soft and hard plate system and keyboard testing. If a problem is found during the self-test, the BIOS will give you a message or whistle warning. If there is no problem, the BIOS will search for a valid boot drive such as soft, hard disk drive and CDROM, network server and so on in the boot order of the system CMOS setup, read the operating system boot record, then give the system control to the master boot record, and complete the system startup by the master boot record.

    • Hardware Interrupt Handling:

When the computer is powered on, the BIOS tells the CPU and other hardware devices that the interrupt number, enter the operating system before entering the command of a hardware, it will be based on the interrupt number with the corresponding hardware to complete the operation of the command.

    • Program Service Request:

The control of hardware can be achieved by issuing instructions on specific ports to send and receive data from external devices.

The BIOS is present in the hardware system before the operating system is installed, so the BIOS is not part of the kernel kernel.

1.3 MBR(Master Boot Record) master boot record

MBR Master boot Record

Composition

Size

Master bootstrapper

446byte

partition table

64byte

Valid identifiers

(also known as magic number Magic numbers)

2byte

The MBR is a sector on the hard disk, consisting of the master boot program, the hard disk partition table DPT, and the partition valid flag three parts.

MBR has a total of 512 bytes of space, the first part of the main boot program (boot loader) accounted for 446 bytes, the second part of the partition table DPT (Disk Partition table) for 64 bytes, every 16 bytes record a partition, record the number of partitions and their size The third part of the partition valid flag accounted for 2 bytes, the flag disk has been formatted, the operating system can be loaded correctly.

By the composition and function of MBR, it is also known that the MBR does not belong to the Linux kernel kernel.

1.4 LinuxKernelKernelcomposition1.4.1 Kernel composition diagram

650) this.width=650; "Width=" 655 "height=" 620 "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd; "alt=" Spacer.gif "/>

1.4.1 Kernel Composition Explanation

The Linux kernel kernel consists of five subsystems, namely process scheduling (SCHED), memory Management (MM), virtual file system (Vsan SYSTEM,VFS), network Interface (NET), and interprocess communication (IPC).

    • process Scheduling : Controls the process's access to the CPU. When you want to select the next process to run, the scheduler chooses the process that is most worth running. A running process is actually a process that waits only for CPU resources, and if a process waits for another resource, the process is not running. Linux uses a relatively simple priority-based process scheduling algorithm to select a new process.

    • Memory Management : Memory Management (MM) allows multiple processes to safely share the main memory area. Linux memory management supports virtual memory, that is, the program running on the computer, its code, data, the total amount of the stack can exceed the actual memory size, the operating system just keep the currently used block in memory, the rest of the program blocks remain on the disk. If necessary, the operating system is responsible for swapping the program blocks between disk and memory. Memory management is logically divided into hardware-independent parts and hardware-related parts. The Hardware-independent section provides the mapping of processes and the swapping of logical memory, and the hardware-related sections provide virtual interfaces for memory-management hardware.

    • virtual file System : Hides the specifics of various hardware, provides a unified interface for all devices, and VFS provides up to dozens of different file systems. Virtual file systems can be divided into logical file systems and device drivers. A logical file system is a file system supported by Linux, such as Ext2,fat, which refers to a device driver module written for each hardware controller.

    • Network Interface: provides access to a variety of network standards and support for a variety of network hardware. Network interface can be divided into network protocol and network driver. The Network Protocol section is responsible for implementing each of the possible network transport protocols. The network device driver is responsible for communicating with the hardware device, and each of the possible hardware devices has a corresponding device driver.

    • Interprocess Communication : supports multiple communication mechanisms between processes, including semaphores, shared memory, pipelines, and so on. These mechanisms can assist in multiple processes, mutually exclusive access to multiple resources, and synchronous messaging between processes.

(for space reasons, kernel kernel is no longer discussed here, but the composition and operating mechanism of the kernel are discussed in detail later in this article)

1.5 LinuxSystem Partitioning----Kernel space(Kernelspace)and user space(userspace)

Kernel space: Store kernel source code and data

User space: Store user applications and data.

Part IIcentos6.8Verbose startup process2.1 BIOS

System power on, load the BIOS, turn on the post (Power On Self Test) power-on-check program, identify and detect all motherboard hardware, if the problem is found, the system will give a message or whistle warning, if not found the problem, Follow the boot order (bootsequence) to find the bootable device in turn. After the self-test is finished, the MBR master boot record is loaded into memory.

2.2 MBR

MBR loads into memory, that is, the boot program grub and the partition information home in memory, will load the boot multi-system boot loader grub (GRand Unified Bootloader).

2.3 GRUB

The grub boot is divided into two stages:

The first stage, running the MBR in the Stage1 (in MBR, written in assembly language):

    • Initialize basic hardware;

    • Prepares space for loading stage2 (present on disk, written in C).

    • Load the stage2 into the RAM space;

    • Set up the stack;

    • Jump to Stage2 's C program entry

Second stage, start/boot/grub/stage2, read the/boot/grub/grub.conf configuration file:

    • Initialize the hardware devices to be used at this stage;

    • Detection system memory mapping;

    • Load the kernel image (/boot/vmlinuz) and virtual root file system image (/BOOT/INTRAMFS) from Flash into RAM space;

    • Set startup parameters for the kernel;

    • Call the kernel.

2.4Kernel space2.4.1 booting the kernel

First stage: Access the virtual root file system (/BOOT/INTRAMFS), execute the INIT process, complete the loading of the driver module and other tasks;

Second stage: Mount the real root file system in read-only mode, and execute the/sbin/init process of user space.

2.5User Space

2.5.1/sbin/init process

    • Set the default system operating level according to/etc/inittab;

    • Execute/etc/rc.d/rc.sysinit system initialization script;

    • Load the/lib/modules system kernel module;

    • According to the previously set operation level, execute the/ETC/RC.D/RC script accordingly, complete the corresponding initialization work and start the related service;

    • Execute the/etc/rc.d/rc.local script to perform user-personalized settings or programs.

Enter login status.

Part III startup process Important Files3.1 Stage1
    • In MBR:

x86 boot sector;

GRand Unified Bootloader, stage1 version 0x3, boot drive 0x80, 1stsector stage2 0x6224, GRUB version 0.94;

Partition 1:id=0x83, active, Starthead, Startsector 2048, 409600sectors;

Partition 2:id=0x82, Starthead 159, Startsector 411648, 1572864sectors;

Partition 3:id=0x83, Starthead 135, Startsector 1984512, 18987008sectors, code offset 0x48

    • In/boot/grub/stage1:

x86 boot sector;

GRand Unified Bootloader, stage1 version 0x3, GRUB version 0.94,code offset 0x48

    • Load the boot record information from the MBR and view the method:

[[email protected] grub]# DD IF=/DEV/SDA count=1 of=/tmp/mbr

1+0 Records in

1+0 Records out

Bytes (+ B) copied, 4.9834e-05 S, 10.3 mb/s

[Email protected] grub]# FILE/TMP/MBR

/tmp/mbr:x86 boot sector; GRand Unified Bootloader, stage1 version0x3, boot drive 0x80, 1st sector Stage2 0x6224, GRUB version 0.94; Partition 1:id=0x83, active, Starthead, startsector 2048, 409600 sectors; Partition 2:id=0x82, Starthead 159, Startsector 411648, 1572864 sectors; Partition 3:id=0x83, Starthead 135, Startsector 1984512, 18987008 sectors, code offset 0x48

3.2/boot/*stage1_5and the/boot/grub/stage2 1) Stage1_5:

E2fs_stage1_5 ffs_stage1_5 jfs_stage1_5 reiserfs_stage1_5 vstafs_stage1_5

Fat_stage1_5 iso9660_stage1_5 minix_stage1_5 ufs2_stage1_5 xfs_stage1_5

2) Stage2:

GRand Unified Bootloader stage2 version 3.2,

Installed partition 65535,

Identifier 0x0,

GRUB version 0.97,

Configuration file (hd0,0)/grub/grub.conf

3.3/boot/grub/grub.conf

The configuration file for grub.

# NOThave to rerun Grub after making changes to the This file You do not need to rerun the file after you change it, or you can complete the configuration modification

# notice:you has a/boot partition. This means that specifies the location of the kernel and virtual file system

# all kernel and INITRD paths arerelative to/boot/, eg.

# root (hd0,0)

# kernel/vmlinuz-version Roroot=/dev/sda3

# initrd/initrd-[generic-]version.img

#boot =/DEV/SDA

Default=0

Timeout=5

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

Hiddenmenu

Title CentOS 6 (2.6.32-573.el6.x86_64)

Root (hd0,0)

kernel/vmlinuz-2.6.32-573.el6.x86_64 roroot=uuid=f6eff611-2e35-4d5e-bf28-06f5fca7fc59 Rd_NO_LUKS rd_NO_LVMLANG=en _us. UTF-8 rd_no_md sysfont=latarcyrheb-sun16 crashkernel=auto keyboardtype=pc keytable=us rd_NO_DM rhgbquiet #内核版本, default system character set

Initrd/initramfs-2.6.32-573.el6.x86_64.img #虚拟文件系统的版本

3.4/etc/inittab

# Defaultrunlevel. The runlevels used is:

# 0-halt (do not set Initdefault to this) shutdown status

# 1-single User mode single

# 2-multiuser, without NFS (the same as 3, if you don't have networking) multiuser mode (no NFS)

# 3-fullmultiuser mode multi-user modes

# 4–unused not used

# 5-x11 Desktop mode

# 6-reboot (do not set Initdefault to this) reboot

#

Id:3:initdefault: (This line is the default run level set)

3.5/etc/rc.d/rc.sysinit
    • Set host name;

    • Set welcome information;

    • Activating Udex and selinux/;

    • Mount the file system defined in the/etc/fstab file;

    • Set the system clock;

    • Set kernel parameters according to/etc/sysctl.conf file;

    • Activating LVM and soft raid devices;

    • Activates the swap partition;

    • Load drivers for additional devices;

    • Performing cleanup operations

3.6/etc/fstab

Set the file system, including the file system name, type, address.

# Created by Anaconda Ontue APR 25 14:56:28 2017

#

# Accessible Filesystems,by Reference, is maintained under '/dev/disk '

# See mans Pages Fstab (5), Findfs (8), mount (8) and/or Blkid (8) for more info

#

UUID=F6EFF611-2E35-4D5E-BF28-06F5FCA7FC59/EXT4 Defaults 1 1

Uuid=97012ecf-af98-4063-9839-722e0e06a30f/boot EXT4 Defaults 1 2

Uuid=dbf823e7-030f-4ef5-b27d-04408b7e3b8fswap Swap Defaults 0 0

TMPFS/DEV/SHM TMPFS Defaults 0 0

Devpts/dev/pts devpts gid=5,mode=620 0 0

Sysfs/sys Sysfs Defaults 0 0

PROC/PROC proc Defaults 0 0

3.7/etc/rc.d/rc.local

This process executes after the other init scripts have been executed, where you can set the actions you want to perform.

#!/bin/sh

#

# This script would beexecuted *after* all the other init scripts.

# can put your owninitialization stuff in here if you don ' t

# want to does the full SysV style init stuff.

Touch/var/lock/subsys/local # Creating a/var/lock/subsys/local file

Reference Documents:

"Process analysis from BIOS to kernel", SEEK_0380,CSDN blog;

"BIOS", Baidu Encyclopedia;

The main role of the BIOS, if wood, learning network;

"MBR", Baidu Encyclopedia;

"Components of the Linux kernel", leafhunter, Sina blog;

"Mbr&/boot and grub Three relations summary", DALE_CHENJIAWEN,CSDN blog;

"Linux system Startup process detailed", WANG7396,CSDN blog;

What is the BIOS? What is the role of the BIOS? ", hix747810800, Baidu experience;




Because the level is limited, in the summary process inevitably have some mistakes, I hope you can find out after the problem or have any puzzled, can comment on the message, I will promptly change the error and reply to everyone, greatly appreciated.

This article is from the "0 Tolerance" blog, be sure to keep this source http://lingrongren.blog.51cto.com/12744457/1925425

Linux start-up process detailed

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.