Linux system startup process

Source: Internet
Author: User

Post-->bios (Boot Sequence)-->mbr (bootload,446)-->kernel-->init


Post: Power-on self-test, the CPU will find its own ROM inside the program to self-test, after checking the control to the BIOS

BIOS: Our operating system can be installed in a variety of locations, the BIOS has a boot Sequence, you can specify the media (U disk, hard disk, etc.) in the search order, find the MBR inside the media and give control to it, (if the MBR is not found in the media, then find the next Media, If the MBR inside the media is damaged, the error message is indicated and stopped.

MBR:MBR inside a two-part 446-byte bootload and 16-byte partition table, Bootload finds the kernel of the active partition and mounts it based on the partitioned table, and then passes control

Kernel:kernel acquires control and then detects the hardware and mounts it, initializes the environment for its functions (file system, process management, network management, security functions, etc.), and then generates the first user process Init

Init: The first process of user space, ID number 1, parent process for all processes


We know that the init process is/sbin, so we must first identify the partition where the/sbin resides, and we know that some of the Linux system partitions can be partitioned separately, and some cannot. No separate partitioning is associated with system initialization, such as/bin,/sbin, and initialization, which provides a separate partition for third-party features, such as/HOME,/USR. Both have one thing in common and must be identified from the root, and we call the filesystem the root file system.

The kernel is designed with two design styles: Microkernel and single core.  The micro-kernel separates the core and peripheral functions, and then loads the corresponding subsystems when certain functions are needed, so there is a congenital advantage, but this style of kernel design logic is complex, hedging its advantages. The single core makes the function and the core together, so the logic implementation is relatively simple. We know that the root file system to use hardware must have a relative hardware driver, but the hardware is diverse, the required drivers are different, if these drivers are made into the kernel, will undoubtedly make the kernel is very large, and our hardware devices are often single, Therefore, the single-core design style refers to the micro-core design concept, the need to drive some of the core, and some into the module, the kernel compiled only choose to compile, so the kernel has become streamlined. Linux is a single-core design style, when the system loads only the core, while the module to the hard disk/lib/modules/"kernel version number named directory"/down to read, so the core only about one or two trillion, the module can be very large. But this can also lead to a problem: when we do not have the disk drive of the module is compiled into the core, we will get into a dilemma, we want to access the disk will need to load the corresponding module, to load the corresponding module, you need to access the disk first.

To solve this problem, Linux uses a man-in-the-middle role file that contains the driver for the corresponding disk, and how does this file know what drivers are needed? The reason for this is that the system is installed by the system installation program, the installer can identify the corresponding driver, and according to the rules to determine the system kernel needs to be generated dynamically. This file is called RAMDisk in the REDHAT5, Redhat6 called Ramfs.


Core, dynamic load kernel module

Kernel:/lib/modules/"kernel version number named directory"/

Kernel design style:

Single core: Linux (LWP)

Core: KO (Kernel object)

Micro-kernel: windows,solaris (thread)

Redhat5:ramdisk-->initrd

Redhat6:ramfs-->initramfs

Chroot: Change/File system, switch the path inside need to include binary program and dependent library file

chroot [OPTION] newroot [COMMAND [ARG] ...]

Ldd/path/to/binary_file: Determine which libraries are required for a binary program


Linux operating level: 0-6

0:halt

1:single User mode

2:multi User Mode,no NFS

3:multi user mode, text

4:reserved

5:multi User mode,graphic Mode

6:reboot


The system boot process using INITRD is as follows:

Post-->bios-->mbr-->kernel-->initrd-->init


MBR (bootloader):

Bootloader has a variety of tools that are more common with Lilo and grub

Lilo:linux LOader does not recognize the data after 1024 cylinder, so the large hard disk is not supported, it is more commonly used in embedded

Grub:grand Unified Bootloader

Stage1:mbr

Stage1.5: Identifying the file system

stage2:/boot/grub/boot the kernel and transfer control


The grub work process is divided into two parts, stage1 in the MBR, to find and boot to stage2, so that the MBR bootload is no longer limited to 446 bytes, when the stage1 stage of grub does not recognize the file system of the disk on which the stage is located, It will derive stage1.5, The role of stage1.5 is to load the filesystem drive of the stage2 disk, so that grub has the ability to read the data (this is why grub can load the kernel, the kernel can not load the root of the reason, the kernel is loaded into memory, if the kernel itself does not recognize the root filesystem disk drive, then it is not method to load the file system, that is, need to initrd this software to transition, identification requires two necessary conditions: 1 disk drive, 2 file system driver)


grub.conf Explanation:

Default=0 #多个title的默认选项, the first one is 0

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

Splashimage= (hd0,0)/grub/splash.xpm.gz #设置背景图片

Hiddenmenu #是否隐藏菜单, hidden boot requires additional keys to display

Title CentOS 6 (2.6.32-573.el6.x86_64) #标题, customizable

Root (hd0,0) #根文件系统所在位置, this is not the same as Linux, either the IDE or the other hard disk is recognized as hd# 0 for the first few partitions

kernel/vmlinuz-2.6.32-573.el6.x86_64 ro root=uuid=b670d3c5-487a-43be-9624-5ad90ffda293 Rd_NO_LUKS rd_NO_LVM LANG=en _us. UTF-8 rd_no_md sysfont=latarcyrheb-sun16 crashkernel=auto keyboardtype=pc keytable=us rd_NO_DM rhgb quiet #内核所在位置及其参数, note If the boot is separate partition, then the kernel location is/vmlinuzxxx, if boot is not separate partition then the kernel location is/path/to/boot/vmlinzxxx

Initrd/initramfs-2.6.32-573.el6.x86_64.img #initrd的位置, ibid.

Password--md5 xxxxxxxxxx #选项的加密, you need to enter a password to access, password can be generated by the Grub-md5-crypt command, can also be stored without--md5 plaintext, placed in front of the title to edit the grub boot requires a password, Put in the title to indicate that you want to boot this kernel requires a password.


To view the run level:

RunLevel

Who-r


There are two ways to install grub Stage1:

The first type:

#grub

grub> Root (hd0,0)

Grub>setup (hd0)

The second type:

Grub-install--root-directory=/path/to/boot ' S_father_dir


Booting the system in the GRUB command line:

Grub> Find (hd#,n)/tab to view files under this path

Grub>root (Hd#,n)

Grub> Kernel/path/to/kernel_file

Grub>initrd/path/to/initrd_file

Grub>boot


Kernel initialization process:

1, device detection

2, driver initialization (INITRD may be used)

3, Mount root file system as read-only

4, Load First process init (PID 1)


Configuration file for the init process/etc/inittab

Format: id:runlevel:action:process

ID: identifier

RunLevel: At which run level does this line

Action: Under what circumstances to run this row

Process: The program to run


ACTION:

Initdefault: Setting the default Run level

Sysinit: System Initialization

Wait: Run when the waiting level switches to the secondary level

Respawn: Once the program is terminated, it restarts


Tasks completed by/etc/inittab:

    1. Set the system run level

    2. Execute the System initialization script

    3. Executing the corresponding level of service script

    4. Definition: Ctrl-alt-del Key Execution Program

    5. UPS Power outage/Midway Call execution operation

    6. Start a virtual terminal

Start the graphics terminal

/etc/inittab execution of System boot SYSV style script features:

    1. It's all in the/etc/init.d/directory.

    2. Scripts must support at least four pass parameters [Start|stop|restar|status]

    3. At each level of the link, the service that begins with K starts stop,s the start

    4. To automatically create a link in chkconfig automatically at each runlevel, the comment line must contain chkconfig and description


Chkconfig Comment Line format in SysV script:

#chkconfig: RunLevel SS KK

Example: chkconfig:2345 08 92

RunLevel represents the run level in which the script is started

The SS represents the sequence number followed by the start of/etc/rc#.d/S, such as this example/ETC/RC3.D/S08IPTABLES,SS represents 08

KK represents the number after the K, generally ss+kk=99 around, this is to follow the first boot after the close principle (because the first boot may be dependent on the latter service)


Chkconfig command:

Chkconfig--list [Name]

Chkconfig--add Name

Chkconfig--del Name

Chkconfig [--level levels] name <on|off|reset|resetpriorities>

Chkconfig [--level levels] Name

Name represents the service name under/etc/init.d/

Level indicates at which levels to run, can be omitted, default 2345


A special file:/etc/rc.local This is the last script that the system launches, and the links in each level are S99, so some commands that you want to boot can be written here.


Daemon Type:

Standalone Daemon: Process startup shutdown is managed by the process itself, similar to the service script above

Transient daemon: A process that manages multiple services, whether the service starts or not depends on the management process, and is suitable for services that are seldom accessed at ordinary times, a process that is xinetd in CentOS and acts like a proxy


A sysv style script case:

#!/bin/bash

#

#chkconfig: 2345 22 77

#description: Edit by LINZB.

#

Lock_file=/var/lock/subsys/myservice

Usage () {

echo "' basename ' [Start|stop|status|restart]"

}

Start () {

Touch $LOCK _file

echo "Starting ..."

}

Stop () {

Rm-f $LOCK _file $>/dev/null

echo "Stoping ..."

}

Status () {

If [-F $LOCK _file];then

echo "Running ..."

Else

echo "Stopped"

Fi

}

Case $ in

Start

start;;

Stop

stop;;

Restart

Stop

start;;

Status

status;;

*)

Usage;;

Esac



Note:/var/lock/subsys/This directory often put the service lock file, a lot of services according to the file to determine whether the service started




This article is from the "single Season rice" blog, please be sure to keep this source http://linzb.blog.51cto.com/5192423/1790459

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.