Linux startup flowchart

Source: Internet
Author: User
Tags syslog system log

http://blog.163.com/x_ares/blog/static/101548562011710112613165/

http://baogf92.blog.51cto.com/10869243/1728752

Http://blog.chinaunix.net/uid-23069658-id-3142047.html

Http://blog.chinaunix.net/uid-26495963-id-3066282.html

Http://www.ruanyifeng.com/blog/2013/08/linux_boot_process.html

Http://blog.chinaunix.net/uid-21516619-id-4106231.html

http://blog.csdn.net/zhoudaxia/article/details/6666872

Profiling Linux system startup process--Redhattaking the RedHat9.0 and i386 platforms as an example, this paper analyzes the entire Linux boot process from the user turning on the power supply until the command line prompt appears on the screen.   and introduces the various files involved in the launch. Reading the Linux source code is undoubtedly the best way to learn Linux in depth. In this article on the Linux boot process, we also try to dig deeper into the Linux startup process from the source code perspective, so it is also simple to relate to some of the relevant Linux source code, Linux boot this part of the source is mainly used in the C language, but also involves a small number of compilations. The startup process also executes a large number of scripts written by the shell (mostly bash shell). In order to facilitate readers to read, the entire Linux startup process is divided into the following sections, we can refer to: When the user turned on the power of the PC, BIOS post, according to the BIOS set up the boot device (usually a hard disk) boot, Then boot loader installed on the device Lilo or GRUB start booting Linux, Linux first boot the kernel, then execute the INIT program, The INIT program calls the Rc.sysinit and RC programs, Rc.sysinit and RC after the completion of the system initialization and operation of the service, after the return init;init started the Mingetty, opened the terminal for users to log on the system, the user login successfully entered the shell, so that the completion of the boot to the login The entire startup process of the recording. Here are a few of the key parts: the first part: Kernel boot (in-core boot) Red Hat9.0 can start booting the Linux system with a boot program such as Lilo or grub, and when the boot program successfully completes the boot task, Linux takes control of the CPU from them, then the CPU starts executing the Linux core Image code and starts the Linux boot process. Several assembler programs are used to boot Linux, and this step is generalized to the Linux source tree "Arch/i386/Boot "Under these several files: Bootsect. S, Setup. S, video.   S and so on. Which bootsect. S is the assembly source that generates the boot sector, and it jumps directly to setup after the load action is completed. S of the program entrance. Setup. The main function of S is to copy system parameters (including memory, disk, etc.) to special memory so that they can be read by code in protected mode later. In addition, Setup. s also includes the code in VIDEO.S to detect and set the display and display modes. Finally, Setup. s converts the system to protected mode and jumps to0x100000. So 0x100000 what code is stored in this memory address?   And where does this code come from? 0x100000 This memory address is stored in the extracted kernel, because Red Hat provides the kernel contains a lot of drivers and functions are relatively large, so in the kernel compiled by using the "Makebzimage" method, to generate a compressed kernel, In Redhat, the kernel is often named Vmlinuz, which is used during the initial boot of Linux"arch/i386/boot/compressed/"in the head.   S uses the Decompress_kernel () function defined in MISC.C to extract the kernel vmlinuz to 0x100000. When the CPU jumps to 0x100000, it executes the"Arch/i386/kernel/head. S"In the startup_32, it is also the entrance of Vmlinux, and then jumps to the Start_kernel (). Start_kernel () is"init/main.c"The defined function in Start_kernel () invokes a series of initialization functions to complete the settings of the kernel itself. In the Start_kernel () function, a lot of work has been done to build a basic Linux core environment.   If the Start_kernel () is executed successfully, the basic Linux core environment is already set up. At the end of Start_kernel (), by calling the Init () function, the system creates the first core thread and initiates the init process. The core thread init () is primarily to perform some peripheral initialization work, including calling Do_basic_setup () to complete the loading and initialization of peripherals and their drivers.   and complete the file system initialization and installation of the root file system. When the Do_basic_setup () function returns init (), Init () opens again/dev/console device, redirect three standard input and output files stdin, stdout and stderr to the console, and finally, search for the INIT program in the file system (or by init=command-line arguments, and use the EXECVE () system call to load the execution init program. By the end of this init () function, the boot portion of the kernel has ended. Part II: Running INIT init process number is 1, from this point can be seen, the INIT process is the starting point of all processes of the system, Linux after the completion of the kernel boot, began to run the INIT program. The INIT program needs to read the configuration file/etc/inittab. Inittab is a non-executable text file that consists of several lines of instructions. In the Redhat system, the contents of Inittab are as follows ("# # #"The beginning of the note for the author added):# # Inittab This file describes how the INIT process shouldSetUp # The systeminchA certain run-Level . # # Author:miquel van Smoorenburg,<[email protected]># Modified forRHS Linux by Marc Ewing and Donnie Barnes # # Default RunLevel. The runlevels used by RHS is: #0-Halt (Do notSetInitdefault to This) #1-Single user mode #2-Multiuser, without NFS (the same as 3,ifYou DoNot havenetworking) #3-Full multiuser mode #4-Unused #5-X11 #6-Reboot (Do notSetInitdefault to This# # # # #表示当前缺省运行级别为5 (initdefault); ID:5: Initdefault: # # #启动时自动执行/etc/rc.d/rc.sysinit Script (sysinit) # System initialization. Si::sysinit:/etc/rc.d/rc.sysinit l0:0: WAIT:/ETC/RC.D/RC0L1:1: WAIT:/ETC/RC.D/RC1L2:2: WAIT:/ETC/RC.D/RC2L3:3: WAIT:/ETC/RC.D/RC3L4:4: WAIT:/ETC/RC.D/RC4# # #当运行级别为5时, run as parameter 5/etc/rc.d/RC script, Init will wait for it to return (wait) L5:5: WAIT:/ETC/RC.D/RC5L6:6: WAIT:/ETC/RC.D/RC6# # #在启动过程中允许按CTRL-alt-Delete reboot system # Trap CTRL-alt-DELETE Ca::ctrlaltdel:/SBIN/SHUTDOWN-T3-R now # when our UPS tells us Power had failed, assume we have a few minutes # of power left. Schedule a shutdown for 2Minutes fromNow .   # This does, the course, assume you have Powerd installed and your # UPS connected and working correctly. PF::p owerfail:/sbin/shutdown-f-H +2 "Power Failure; System shutting down"# If Power was restored before the shutdown kickedinch, cancel it. PR:12345:p owerokwait:/sbin/shutdown-c"Power restored; Shutdown Cancelled"# # #在2,3、4, Level 5 on the Ttyx parameter execution/sbin/mingetty Program, open Ttyx terminal for user login, # # #如果进程退出则再次运行mingetty程序 (respawn) # Run GettysinchStandard Runlevels1:2345: respawn:/sbin/Mingetty tty12:2345: respawn:/sbin/Mingetty Tty23:2345: respawn:/sbin/Mingetty Tty34:2345: respawn:/sbin/Mingetty Tty45:2345: respawn:/sbin/Mingetty tty56:2345: respawn:/sbin/mingetty Tty6 # # #在5级别上运行xdm程序, provides XDM graphical login interface and re-executes on exit (respawn) # Run XDminchRunLevel5x:5: RESPAWN:/ETC/X11/PREFDM-Nodaemon Take the above Inittab file as an example to illustrate the format of Inittab. Where the line begins with # is the comment line, in addition to the comment line, each row has the following format: Id:runlevel:action:process the above items are explained in detail as follows:1The . ID ID refers to the entry identifier, which is a string, and for other login program items such as Getty or Mingetty, the ID is the same as the TTY number, otherwise the Getty program will not function properly. 2The . RunLevel RunLevel is the identity of the runlevel at which Init is located, typically using 0-6 and s or S. 0、1, 6 runlevel is reserved by the system: 0 as a shutdown action, 1 as a reboot to single user mode, 6 for reboot, S and s for single user mode, without inittab files, and therefore not in inittab, in fact, when entering single user mode, Init runs/sbin/sulogin directly on the console (/dev/console). In the general system implementation, the use of 2,3、4, 5 levels, in the Redhat system, 2 represents a multiuser mode without NFS support, 3 represents a full multiuser mode (also the most commonly used level), 4 is reserved for user customization, and 5 represents the XDm graphical login method.7-9 levels are also available, and traditional UNIX systems do not define these levels.   RunLevel can be multiple values in parallel to match multiple runlevel, and for most actions, only if RunLevel matches the current runlevel is successful. 3The . Action action is a description of how the process subsequently runs. Action-desirable values include: Initdefault, Sysinit, boot, bootwait, and so on: Initdefault is a special action value that identifies the default boot level, and when Init is activated by the core, It reads the Initdefault entry in Inittab, obtains runlevel in it, and acts as the current runlevel.   If there is no Inittab file, or there are no Initdefault entries in it, INIT will request input runlevel on the console.   Actions such as sysinit, boot, bootwait, and so on, will run unconditionally when the system starts, ignoring the runlevel. The rest of the action (without initdefault) is related to a runlevel.   The definitions of each action are described in detail in the Inittab Man Handbook. 4the. Process process is a concrete execution procedure.   The program can be followed with parameters. The third part: System initialization in the INIT configuration file has this line: Si::sysinit:/etc/rc.d/Rc.sysinit It calls the executed/etc/rc.d/Rc.sysinit, and Rc.sysinit is a bash shell script that is primarily about doing some system initialization, Rc.sysinit is an important script to run at every runlevel.   Its main tasks are: Activating the swap partition, checking the disk, loading the hardware modules, and some other priorities that need to be performed. Rc.sysinit has about 850 rows, but each single feature is relatively simple, with comments, suggesting that interested users can read the file on their own machine in order to understand the details of the initialization of the system.   Because this file is longer, it is not listed in this article, and does not make a specific introduction. When the Rc.sysinit program finishes executing, it will return to Init to continue to the next step. Part IV: The daemon that initiates the corresponding runlevel will return to Init to continue with other actions after the rc.sysinit is executed, usually next to/etc/rc.d/RC Program. For example, run Level 3, Init executes the following line in the configuration file Inittab: L5:5: WAIT:/ETC/RC.D/RC5This line represents the run as parameter 5/ETC/RC.D/RC,/ETC/RC.D/RC is a shell script that accepts 5 as a parameter to execute all RC startup scripts under the/etc/rc.d/rc5.d/directory,/etc/rc.d/rc5.d/ These startup scripts in the directory are actually some linked files, not the actual RC startup scripts, and the actual RC startup scripts are actually placed on the/etc/rc.d/init.d/directory.   These RC startup scripts have a similar usage, and they generally accept start, stop, restart, status, and so on. The RC startup script in/etc/rc.d/rc5.d/is usually a link file starting with K or S, and will run with the start parameter for startup scripts starting with S. And if there is a corresponding script found there is a K-link, and is already in the running state (in/var/Lock/subsys/file as a flag, the daemons that have been started are stopped first with the stop parameter, and then run again.   This is done to ensure that when Init changes the RunLevel, all associated daemons are restarted. As to which Daemons will be run at each run level, the user can pass the Chkconfig or Setup"System Services"from row settings. Common daemons are: AMD: Automatic installation of the NFS Daemon APMD: Advanced Power Management Daemon Arpwatch: Log and build an Ethernet address and IP address to the database that you see on the LAN interface AutoFS: Automatically install the management process AutoMount, and NFS    dependent, daemon that relies on scheduled tasks under NIS crond:linux named:dns Server netfs: Installing NFS, Samba, and NetWare Network File system networks: Activating a scripted program that has configured Network Interfaces NFS: Open NFS Service PORTMAP:RPC Portmap Manager, which manages RPC service-based connections sendmail: Mail server sendmail Smb:samba file share/Print Service syslog: A script that lets the system boot up syslog and klogd the system log waiting process xfs:x The window font server, providing a font set for both local and remote X servers Xinetd: A core daemon that supports multiple network services Can manage Wuftp, sshd, Telnet and other services these daemons also start to complete, the RC program is finished, and then return to Init to continue to the next step. Part V: When the terminal RC is established, it returns to Init. At this point the basic system environment has been set up, various daemons have been started. Init then opens 6 terminals so that the user can log on to the system. by pressing ALT+FN (n corresponds to 1-6) can be toggled in these 6 terminals. The following 6 lines in Inittab define 6 terminals:1:2345: respawn:/sbin/Mingetty tty12:2345: respawn:/sbin/Mingetty Tty23:2345: respawn:/sbin/Mingetty Tty34:2345: respawn:/sbin/Mingetty Tty45:2345: respawn:/sbin/Mingetty tty56:2345: respawn:/sbin/Mingetty Tty6 from the above can be seen in 2,3、4, 5 of the operating level will be respawn run Mingetty program, mingetty program can open terminal, set mode.   At the same time it will display a text login interface, which is the login interface we often see, in this login screen will prompt the user to enter a user name, and the user input user will be passed as a parameter to the login program to verify the identity of the user. Part VI: Logging in to the system, starting to complete for graphical users with a run level of 5, their login is via a graphical login interface. After successful login, you can go directly to KDE, GNOME and other window manager.   This article is mainly about the text mode of login: When we see the Mingetty login interface, we can enter the user name and password to log into the system. Linux Account Verification Program is Login,login will receive mingetty from the user name parameters. Login will then parse the username: If the user name is not root and there is/etc/nologin file, login will output the contents of the Nologin file and then exit. This is typically used for system maintenance to prevent non-root users from logging on. Only the terminal registered in/etc/securetty allows the root user to log on, and if the file does not exist, root can log on at any terminal. /etc/The usertty file is used to make additional access restrictions to the user, and there are no additional restrictions if the file does not exist. After parsing the user name, login will search for/ETC/PASSWD and/etc/shadow to verify the password and set up additional information about the account, such as what the home directory is and what shell to use. If you do not specify a home directory, the default is the root directory, and if you do not specify a shell, the default is/bin/bash. When the login program succeeds, it will output the last login information to the corresponding terminal (in/var/log/lastlog) and check to see if the user has a new message (recorded in/usr/spool/mail/'s corresponding user list). Then start setting up various environment variables: for bash, the system first looks for/etc/Profile script file and execute it, and then if there is a. bash_profile file in the user's home directory, execute it, and another configuration file may be called in these files, and after all the configuration files have been executed, the various environment variables are set.   A familiar command-line prompt appears, and the entire startup process is over.   It is hoped that the above analysis of the Linux boot process will help those who want to learn more about Linux users to establish a relevant Linux startup process, and then can further study how Linux works next. 

Linux startup flowchart

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.