Linux system startup process

Source: Internet
Author: User
Tags delete key

The overall startup process for the Linux system is as follows:

POST-to -BIOS (Boot Sequence)--MBR (bootloader)--kernel + INITRAMFS (or INITRD)--Mount Rootfs (RO) --/sbin/init Set the default run level--use/etc/rc.d/rc.sysinit to initialize the system--start and close the specified service, respectively--ctrl+alt+delete key combination--Start character terminal --Start the graphics terminal

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/75/81/wKiom1Y62VaRdkt7AA7jVE4tLVo737.jpg "title=" 20775448_1443168421fwik.jpg "width=" "height=" 496 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:700px;height : 496px; "alt=" wkiom1y62vardkt7aa7jve4tlvo737.jpg "/>


The Linux system starts at various stages in detail :

1, Post: Power-on self-test. After powering on, the CPU loads the BIOS program in the CMOS , which consists of a series of assembly instructions that identify and detect all the hardware on the motherboard, then search for the bootable device in the boot order set in the BIOS, and then stop looking for it once it is found


2, MBR: The CPU reads the first sector of the bootable device, the MBR(master boot Record), also known as the "Master boot recording", is 512 bytes in size, which holds:

boot loader (bootloader): 446bytes, the commonly used boot loader have Lilo and grub, and are now based on Grub ;

Partition table: 64bytes

Validity tag: 2bytes

The CPU loads the boot loader into memory,and the boot loader helps us find the kernel from the disk and load it into memory .


3, Kernel: After the kernel is loaded, it will do the main work is: Probe hardware, load the driver, read-only load the root file system (ROOTFS), start the first process/sbin/init.

There will be a "chicken egg" or "egg raw chicken" problem, the root file system exists on the disk, the kernel to mount the root file system needs to be able to drive the disk, that is, the driver needs to be loaded first, and the driver is on disk. To resolve this issue, the boot loader loads the kernel while loading the Initramfs(or INITRD) into memory (the detailed instructions for INITRAMFS and INITRD are at the end of this section), which is a temporary root filesystem, It contains the necessary drive modules for the boot. The kernel mounts this temporary root, loads the driver, then releases the temporary root, mounts the actual root filesystem, and starts the first process/sbin/init.

The kernel and Initramfs files are located under the boot partition (or directory):

Kernel:/boot/vmlinux-version-release

Initramfs:/boot/initramfs-version-release.img

[Email protected] ~]# ls/bootconfig-2.6.32-431.el6.x86_64 Grub Lost+found System.map-2.6.32-431.el6.x86_64efi initramfs-2.6.32-431.el6.x86_64.img symvers-2.6.3 2-431.el6.x86_64.gz vmlinuz-2.6.32-431.el6.x86_64


4. Init: The last step of kernel initialization is to start the/sbin/init process with PID 1. This process is the first process of the system and it is responsible for generating all other processes. The first thing to do on the INIT process is to read /etc/inittab and /etc/init/*.conf(only inittab files on Centos 5)

In/etc/inittab and/etc/init/*.conf, the following actions are broadly defined:

Get runlevel that's run level

Using/etc/rc.d/rc.sysinit for system initialization

Start the appropriate service according to RunLevel and close services that need to be stopped

Determining the Ctrl+alt+delete key combination function

Start character terminal

Start the graphics terminal

system operating level :

0: Turn off the machine

1:single user mode, single-user

2:multi user mode, NFS feature not supported

3: Full multi-user mode, text interface

4: Not used, reserved level

5: Full multi-user mode, graphical interface

6: Restart

Can switch levels at the command line: Init #

[[Email protected] ~]# cat /etc/inittab# inittab is only used by  upstart for the default runlevel.## ADDING OTHER CONFIGURATION  Here will have no effect on your system.## system initialization  is started by /etc/init/rcs.conf## individual runlevels are started  by /etc/init/rc.conf## ctrl-alt-delete is handled by /etc/init/ Control-alt-delete.conf## terminal gettys are handled by /etc/init/tty.conf  and /etc/init/serial.conf,# with configuration in /etc/sysconfig/init.##  for information on how to write upstart event handlers, or  How# upstart works, see init (5),  init (8),  and initctl (8). ## Default  runlevel. the runlevels used are:#   0 - halt  (do not set initdefault  To this) #   1 - single user mode#   2 -  multiuser, without nfs  (the same as 3, if you do not  have networking) #   3 - full multiuser mode#   4 -  unused#   5 - X11#   6 - reboot  (Do not  set initdefault to this) # id:3:initdefault:   #这里设置的运行级别是3 [[email  protected] ~]# ls /etc/initcontrol-alt-delete.conf  plymouth-shutdown.conf   rc.conf             rcs-sulogin.conf           readahead-disable-services.conf   start-ttys.confinit-system-dbus.conf    prefdm.conf              rcs.conf            readahead-collector.conf   serial.conf                       tty.confkexec-disable.conf        quit-plymouth.conf      rcs-emergency.conf  readahead.conf             splash-manager.conf


Supplement:/etc/inittab in CentOS 5

Unlike CentOS 6, only/etc/inittab on CentOS 5, all initialization actions are defined in this file, the entries defined in this file are separated by: four segments, in the following format:

id:runlevels:action:process such as Si::sysinit:/etc/rc.d/rc.sysinit

The meaning of each field:

ID: The identifier of the enlisted item, which must be unique

Runlevels: The operating level of the system, which indicates the level at which the action of the process is to run, which can be defined at multiple levels, with no separators at all levels, or null to run at all RunLevel

The specific action is:

Respawn: Start a new one as soon as the process terminates

Wait: process does not start once after entering the specified runlevels, and until it leaves Runlevels

Initfault: Set the default run level

Sysinit: System initialization, process will be executed only once the system is powered on or restarted


5, Sysinit: After setting the operating level, the Linux system executes the first user layer file is the /etc/rc.d/rc.sysinit script, it does the work including:

Set host name: Read the hostname parameter in the/etc/sysconfig/network file and set the hostname

Print Text Welcome message

Activating SELinux and Udev

Mount other file systems defined in the/etc/fstab file

Activate swap

Detects the root file system and re-mounts it in read-write mode

Setting the system clock

Setting kernel parameters according to/etc/sysctl.conf

Activating LVM and RAID devices

Load drivers for additional devices

Cleanup operations


6. Start the specified default level by default for services that are started, stop services that are turned off by default at the specified level

/ETC/RC.D/RC#.D (#表示运行级别), the directory is a symbolic link file that points to the actual service script in the /etc/rc.d/init.d directory (which has a soft link/etc/init.d). These linked files start with S or K:

s##: The service started

k##: Discontinued Services

##:01-99, the smaller the number, the higher the priority to start or close

[[EMAIL PROTECTED] ~]# LS /ETC/RC.D/INIT.D  RC  RC0.D  RC1.D   rc2.d  rc3.d  rc4.d  rc5.d  rc6.d  rc.local   rc.sysinit[[email protected] ~]# ll /etc/rc.d/rc3.dtotal 0...lrwxrwxrwx.  1 ROOT ROOT 19 AUG  6 04:38 K75QUOTA_NLD ->&NBSP, .... /init.d/quota_nldlrwxrwxrwx. 1 root root 16 aug  6 04:44  K76YPBIND ->&NBSP, .... /init.d/ypbindlrwxrwxrwx. 1 root root 15 aug  6 04:53 k80kdump  ->&NBSP, .... /init.d/kdumplrwxrwxrwx  1 root root 24 oct 31 07:28 k84wpa_ SUPPLICANT ->&NBSP, .... /init.d/wpa_supplicantlrwxrwxrwx. 1 root root 21 aug  6 04:34  K87RESTORECOND ->&NBSP, .... /init.d/restorecondlrwxrwxrwx  1 ROOT ROOT 14 OCT 31 07:28 K88SSSD ->&NBSP, .... /init.d/sssdlrwxrwxrwx. 1 root root 15 aug  6 04:34 k89rdisc  ->&NBSP, .... /init.d/rdisclrwxrwxrwx. 1 root root 14 aug  6 04:38 k99rngd  ->&NBSP, .... /init.d/rngdlrwxrwxrwx. 1 root root 22 aug  6 04:38  S02LVM2-MONITOR ->&NBSP, .... /init.d/lvm2-monitorlrwxrwxrwx. 1 root root 19 aug  6 04:36  S08IP6TABLES ->&NBSP, .... /init.d/ip6tables...lrwxrwxrwx. 1 root root 11 aug  6 04:34  S99LOCAL ->&NBSP, .... /rc.local   #最后一个启动链接文件指向父目录rc. local[[email protected] ~]# cat /etc/rc.d/rc.local #!/bin/sh## this script will be executed *after* all the other  init scripts.# you can&nbsP;put your own initialization stuff in here if you don ' t#  want to do the full sys v style init stuff.touch /var/lock/ Subsys/local

See above, the last boot link file is s99local, it points to /etc/rc.d/rc.local, if we do not want to put some post-boot operations specifically written script, can be written to this file. /etc/rc.d/rc.local also has a soft link/etc/rc.local


To control whether a script is booting, use the Chkconfig command

chkconfig: To View or modify the startup options that the service launches with the system , it does not directly activate or stop a service, but only modifies its symbolic link . Use the following:

① let the specified service accept chkconfig command management:

First step: Add one or more lines of comments in the service script located in the/ETC/RC.D/INIT.D directory:

# chkconfig:level SPRI kpri , e.g. # chkconfig:-

Chkconfig is followed by three fields, which have the following meanings:

Level: When this service is controlled by Chkconfig, the default is on which run levels are started. If the default does not start at any run level, the "-" number indicates

SPRI: Start priority

KPRI: Turn off priority

Step Two:chkconfig add SERVICE, which automatically creates a linked file in the/ETC/RC.D/RC#.D directory

②chkconfig del Service: Let the specified service no longer accept chkconfig management, delete the linked file

chkconfig--list [service]: Displays start-up settings for all services or specified services

Chkconfig [--level # #] SERVICE on/off/reset: If you do not specify the--level option, the on and off actions are only valid for run Level 2, 3, 4, 5, and Reset is valid for all run levels by default. Reset means reset, which restores the initial settings in the service script

[[email protected] ~]# cp testsrv /etc/rc.d/init.d/testsrv  # The service scripts that accept Chkconfig managed services must be located in the INIT.D directory [[email protected] ~]# vim /etc/init.d/testsrv #!/ bin/bash## chkconfig: 2345 90 10   #添加这一行, which indicates that the boot srv= ' basename is started by default at run Level 2, 3, 4, 5  $0 ' lockfile= '/var/lock/subsys/$srv "[ $# -lt 1 ] && echo " usage:  $srv  {start|stop|restart|status} " && exit 4[  $UID  -ne 0  ] && echo  "Only root."  && exit 5if [  "$"  ==  ' start '  ]; then    if [ -f  $lockFile  ]; then        echo  "$ Srv is running. "         exit 7 ... [[email protected] ~]# chkconfig --add testsrv   # Let Testsrv accept the Chkconfig command.Manage [[email protected] ~]# ll /etc/rc.d/rc3.d | grep  ' testsrv '   # Show linked files created Lrwxrwxrwx  1 root root 17 oct 31 08:29 s90testsrv  ->&NBSP, .... /init.d/testsrv[[email protected] ~]# chkconfig --list testsrv   # Display boot settings at all levels testsrv        0:off1:off2:on3:on4:on5:on6:off[[email  protected] ~]# chkconfig testsrv off   #默认关闭2-5-stage boot [[email protected]  ~]# chkconfig --list testsrvtestsrv        0:off1 : Off2:off3:off4:off5:off6:off[[email protected] ~]# chkconfig --level 23 testsrv  on   #指定在2, Level 3 with boot [[email protected] ~]# chkconfig --list  testsrvtestsrv        0:off1:off2:on3:on4:off5:off6:off[[email  protected] ~]# chkconfig testsrv reset   #重置 [[email protected] ~]# chkconfig -- list testsrv   #显示已恢复成初始设置testsrv         0:off1:off2:on3 : on4:on5:on6:off[[email protected] ~]# chkconfig --del testsrv[[email protected]  ~]# ll /etc/rc.d/rc3.d | grep  ' TestSvr ' [[Email protected] ~]# rm  -f /etc/init.d/testsrv


7.Ctrl+alt+delete combination key

After starting the system service is to determine the function of the Ctrl+alt+delete key combination, the configuration file is/etc/init/control-alt-delete.conf

[Email protected] ~]# cat/etc/init/control-alt-delete.conf # control-alt-delete-emergency keypress handling## this TAS  K is run whenever the Control-alt-delete key combination is# pressed. Usually used to shut down the machine.## does not edit this file directly.  If you want to change the behaviour,#, create a file control-alt-delete.override and put your changes there.start on Control-alt-deleteexec/sbin/shutdown-r Now "Control-alt-delete pressed" #Control The default function of the-alt-delete key combination to restart the system


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.