Linux system startup process

Source: Internet
Author: User

add self-test

Post: Power-on self-test. Power on the self testing. The current x86 CPU will automatically find a section of code to perform a self-test at the specified location after powering on.

The code is placed in the ROM. The ROM's representative component is called CMOS, which has a BIOS in ROM


Boot Sequence

In order to find each boot device, the first device that has a boot program is the device to be used for this boot.

boot loader/boot loader

Bootloader, this program is stored on disk.

Windows Bootloader is called Ntloader

Linuxbootloader is called Lilo Linux Loder this launcher has limited disk capacity, the initiator cannot load 1024 cylinders after the data andriod the bottom is LInux, it uses Lilo.

Grub is another launcher, and CentOS5 and CentOS6 use grub 0.x CentOS7 using the grub1.x

grub0.x is called Grub Legacy

Grub1.x is called GRUB2.

The role of the bootloader is to provide a menu that allows the user to select a system to boot or a different kernel version, and load the specified kernel into a specific space in memory, unzip the deployment, and then give the system control to the kernel.


Where is the boot loader stored?

Mbr. Main Boot Record. The first sector of a disk (sector No. 0) 512 bytes

A sector is 512 bytes and is divided into three parts.

1, the first 446 bytes, storage bootloader, this is a program for booting the operating system.

2, middle 64 bytes, storage partition table, every 16 bytes represents a partition, there can be only 4 partitions

3, the last two bytes, the effective identification of the MBR region: 55AA (normal), the other values are invalid

Grub divides the entire program into two parts, the first phase is stored in bootloader, and the second stage is stored on disk/boot/grub.

The primary role of bootloader in the first phase of grub is not to load the system kernel, but to load a piece of code stored in the second phase (containing the loaded kernel code) so that you can run some small programs before loading the system. In fact there is an intermediate stage between the first and second phases. Because if the code to load the partition needs to drive the disk, this phase requires the file system to mount and read the second stage of the code.

Note: Because the bootloader code is small, you cannot drive advanced features, such as Lvm,raid. Then the/boot file cannot be placed on the logical volume. The kernel files can only be placed on basic disk partitions.



Efi

This is also a bootstrap program that is made up of Intel developed its own underlying program to replace the BIOS. The BIOS assumes responsibility for initializing hardware, detecting hardware functionality, and booting the operating system. When the system is power up, the address of the first instruction of the processor will be located in the BIOS memory, so that the initialization program can be executed.

Traditional the disadvantage of the BIOS is that when the device is power-up, the processor switches to the operating mode of the system , because the BIOS is written in a four-bit assembly, and execution can only be performed in a Reduce the efficiency of use.

in intel The Itanium processor abandoned bios program, using the efi program. efi Extensible Firmware Interface (extensible Firemware Interface) efi system is not made up of code that can be run directly on the cpu EFI Byte code written. This is a set of virtual machine instructions dedicated to the efi drive, which must be interpreted in the efi drive running environment. Programs written by Efi can be 32 64 bit system operation.

Although EFI is conceptually very similar to a low-order operating system and has the ability to manipulate all hardware resources. But EFI 's creators have Limited EFI's capabilities. First it is just the interface specification between the hardware and the pre-boot software, and next , the EFI environment does not provide a terminal access mechanism, and each EFI driver must check the hardware status in a polling manner and need to run in an interpreted manner.

EFI is a class bash operating system. And you cannot use the MBR boot partition, only the GPT boot partition is supported. EFI brings fast boot and partitions above 2TB ( This feature is provided by GPT).

EFI's disadvantage:EFI 's running program is written in C , andthe BIOS is written by the assembler. as a result, EFI 's program security issues will be more serious than the BIOS.

The EFI initialization module and the drive execution environment are integrated in a read-only memory. The Pre-efi initialization program is executed first when the system is powered on. It is responsible for initializing the initial CPU, main bridge, and memory, and then loading the EFI Drive Execution Environment (DXE). When DXE is loaded into the runtime, the system has the ability to enumerate and load other EFI drivers. in a PCI architecture-based system, the EFI drivers for each PCI Bridge and PCI adapter are loaded and initialized successively. At this point, the system then enumerates and loads various bridges and the various bus and device drivers behind the adapter. Until the last device driver was loaded successfully. So the EFI driver can be placed anywhere on the system, as long as it can be correctly enumerated in order.

in theEFIspecification, the introduction ofGUIDDisk Partitioning System(GPT). In the new structure, the number of partitions on the disk is no longer limited by4primary partition, and the partition type will beGUIDto express. Among the many partition types,EFIsystem partitions can beEFIsystem access for storing part of the drivers and applications.

UEFI

EFI was developed separately by Intel, and UEFI was created to be able to work with other vendors to develop EFI programs .

Gpt

A GPT disk refers to a disk that uses a GUID partition table and is the standard for a newer disk partition structure table originating from the EFI standard.

in the The capacity of the MBR for storing partition information is a total of 4 bytes , and the information for each partition is in bytes, with a capacity of only 4 bytes for the number of partitions in the partition. So altogether is the total number of storage sectors,2 of the cubic sector, each sector of the bytes, then each partition size can not be greater than 2TB. Otherwise, the total number of partitions in the partition cannot be displayed.

The advantages of GPT with respect to MRB are as follows:

1.support hard disk above 2TB

2.number of partitions per disk ( limitations of Windows system )

3.use the certificate of the position to indicate the sector code. 2 of the four- time sector.

4, the partition table comes with the backup. A copy of the same partition table is saved on the first and last part of the disk.

5. Each partition can have a name


Load kernel

The first thing after the kernel loads is to initialize itself.

Step one: Detect all hardware devices that can be identified

Step two: Load the Hardware device driver (it is possible to load the driver with RAMDisk)

Step three: Mount the root file system in a read-only manner (prevent the kernel from corrupting the root file system and mount it in read-write mode when the system is running normally)

Fourth step: The first application running user space/sbin/init

/sbin/init is also just a link file

Init program Type

CENTOS5:SYSV Init

Configuration file/etc/inittab

Centos6:upstart

Configuration file:/etc/inittab (for compatibility with previous versions)/etc/init/*.conf (this is the primary profile)

Centos7:systemd

Configuration file:/usr/lib/systemd/system,/etc/systemd/system

RAMDisk

This technique borrows one of the features of Linux (using buffering and caching to speed up access to files on disk)

The tool used on CENTOS5 is INITRD to create the file system MKINITRD

Used on CentOS6 7 is the Initramfs tool room that created the file system DRACUT,MKINITRD (called or dracut)

Summarized under

System initialization process (Kernel level): Post->bootsequence (BIOS)->bootloader (MBR)->kernel (+ramdisk)->roofs (readonly)->/ Sbin/init


/sbin/init process (CentOS5)

Run level

A mechanism set up for the purpose of system operation or maintenance

0-6:7 A level

0: Indicates shutdown shutdown

1: Single user mode , root user does not need authentication; Maintenance Mode

2: Multiuser mode Multi user, with network-enabled maintenance mode but does not start NFS.

3: Multiuser mode Multi User, this is a normal mode,CLI mode

4: Reserved level

5: Multiuser mode Multi User, this is a normal mode,GUI mode

6: restart reboot

Default Level:3 5

level switch:init #

Level view

n represents the last level

Now switch to 3-level mode init 3

Before it was 5 and now it's 3.

And then switch to 5.

Init configuration file

/etc/initab

The Inittab file in CentOS7 is not available and you need to use the system file

Each row defines an action and the process that corresponds to that method only for CentOS5

Id:runlevel:aciton:process

ID: Task Name

RunLevel at which levels to start the task

Under what conditions the action starts the task

Process specific tasks


The action has several options:

1. wait for one time to switch to the level at which the task is located , such as switching from Level 3 to level 5

2. respawn: Automatically restarts when this task is terminated.

3.initdefault Set default runlevel This process will omit

4,sysinit Set the system initialization mode, here is generally designated as /etc/rc.d/rc.sysinit script.

Example:

LO:0:WAIT:/ETC/RC.D/RC 3

Lo is the name of the task

0 is the run level

Wait: Indicates when switching to level 0

/ETC/RC.D/RC 3 execute this command

RC3.D Services to be turned off (the smaller the number, the more priority to close ) The start of the service to open (the smaller the number, the higher the priority to start )


Set the default run level CentOS7

Systemctl Get-default

Systemctl Set-default graphical.target equivalent to level 5

Multi-user.target equivalent to Level 3

This is the current default RunLevel


Set the default run level CentOS6

/etc/inittab

Id:5:initdefault:


System initialization script (CENTOS5)

/etc/rc.d/rc.sysinit

1. Set host name

2. Set Welcome information

3. Activate udev and SELinux

4.Mount all file systems defined in the/etc/fstab file

5. Detect the root file system and re-mount the root file system in read-write mode

6, set the system clock.

7, according to the/etc/sysctl.conf file settings, to set the kernel parameters.

8. Activating LVM and soft RAID devices

9. Load drivers for additional devices

Clean Operation


/sbin/init process (CentOS6)

It's not the same here.

Init program: Upstart but still/sbin/init, its configuration file is/etc/init/*.conf file,/etc/inittab (only for defining the default run level)


/sbin/init process (CentOS7)

Init program: systemd, config file/usr/lib/systemd/system/* and/etc/systemd/system/*


Note here: Even if the configuration file specifies a process that starts automatically after the system starts, CentOS7 does not start the process until the user first accesses or uses the process.

Fully compatible with the SYSV scripting mechanism, so service commands are still available



Summary (User space initiation process)

/sbin/init (/etc/inittab,/etc/init/*.conf,/usr/lib/systemd/system/)

Set the default run level - run the system initialization script to complete the initialization of the system - Turn off services that you want to stop at the corresponding level and start the services that need to be turned on at the corresponding level - set up a login terminal - start the graphical interface ( optional )

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.