In-depth analysis of Linux Startup (2)

Source: Internet
Author: User
Tags syslog

Before the Linux system is started, we have analyzed the kernel boot and run init, more important work is to initialize the system, start the corresponding level of daemon, establish a terminal, and complete the login. This completes a complete Linux Startup Process.

Part 3: system initialization

There is such a line in the init configuration file:
Si: sysinit:/etc/rc. d/rc. sysinit
It calls/etc/rc. d/rc. sysinit, while rc. sysinit is a bash
Shell scripts are mainly used to initialize the system. rc. sysinit is an important script that must be run first at every running level. It mainly performs the following tasks: Activation of swap points
Check disks, load hardware modules, and perform other tasks first.
Rc. sysinit has more than 850 lines, but each single function is relatively simple and has annotations. It is recommended that interested users read the file on their own machines, to learn more about system initialization. This file is long, so it is not listed in this article, and will not be described in detail.
After the rc. sysinit program is executed, the system returns init to continue the next step.

Part 4: Start the running daemon

After rc. sysinit is executed, init will be returned to continue other actions. Normally, the/etc/rc. d/rc program will be executed next. Taking runtime Level 3 as an example, init will execute the following line in the configuration file inittab:
L5: 5: wait:/etc/rc. d/rc 5
This line indicates running/etc/rc with 5 as the parameter. d/rc,/etc/rc. d/rc is a Shell script that accepts 5 as the parameter and executes/etc/rc. d
All the rc startup scripts in the/rc5.d/directory, and these scripts in the/etc/rc. d/rc5.d/directory are actually some link files, rather than the real rc startup scripts,
The real rc startup scripts are actually stored in the/etc/rc. d/init. d/directory. These rc start scripts have similar usage. They generally accept start, stop,
Restart, status, and other parameters.
The rc STARTUP script in/etc/rc. d/rc5.d/is usually a link file starting with K or S.
The STARTUP script will be run with the start parameter. If the corresponding script is found to have a K-header link, and it is already in the running state (under/var/lock/subsys/
To stop the started daemon with the stop parameter, and then run the daemon again. This is done to ensure that when init changes the running level, all related daemon
All processes will be restarted.
You can use chkconfig or "System Services" in setup to set which daemon will run at each running level. Common daemon processes include:
Amd: automatically installs the NFS daemon.
Apmd: Advanced Power Management daemon
Arpwatch: records logs and constructs an ethernet address and IP address pair database that is visible on the LAN interface.
Autofs: automatically installs the management process automount, which is related to NFS and relies on NIS.
Crond: the daemon of scheduled tasks in Linux
Named: DNS Server
Netfs: Install NFS, Samba, and NetWare Network File Systems
Network: Activate the script program with configured network interfaces
Nfs: Enable the NFS service
Portmap: RPC portmap manager, which manages RPC-based connections
Sendmail: sendmail
Smb: Samba file sharing/printing service
Syslog: a script that enables syslog and klogd system logs to wait for processes during system boot.
Xfs: X Window server, which provides a font set for local and remote X Servers
Xinetd: supports core daemon processes of multiple network services and manages services such as wuftp, sshd, and telnet.
These daemon processes are also started, the rc program is executed, and the init is returned to continue the next step.

Part 5: Establish a terminal

After the rc is executed, init is returned. At this time, the basic system environment has been set and various daemon processes have been started. Init will then open six terminals so that users can log on to the system. You can switch between the six terminals by pressing Alt + Fn (n corresponds to 1-6. The following six lines in the inittab define six terminals:
1: 2345: respawn:/sbin/mingetty tty1
2: 2345: respawn:/sbin/mingetty tty2
3: 2345: respawn:/sbin/mingetty tty3
4: 2345: respawn:/sbin/mingetty tty4
5: 2345: respawn:/sbin/mingetty tty5
6: 2345: respawn:/sbin/mingetty tty6
 
From the above, we can see that the mingetty program will be run in the respawn mode in the 2, 3, 4, and 5 running levels. The mingetty program can open the terminal and set the mode. At the same time, it will
A text logon interface is displayed, which is a logon interface we often see. On this logon interface, a user is prompted to enter the user name, and the user input will be passed as a parameter to the login program for verification.
Verify the identity of the user.

Part 6: log on to the system and start the system

For graphical users with a running level of 5, their logon is through a graphical logon interface. After successful logon, you can directly go to the KDE, Gnome, and other Window managers. This article focuses on text-based Logon:
When we see the mingetty logon interface, we can enter the user name and password to log on to the system.
 
In Linux, the Account Verification Program is login. login receives the username sent from mingetty as the username parameter. Login then analyzes the User name: if the user name
If it is not root and the/etc/nologin file exists, login will output the content of the nologin file and then exit. This is usually used to prevent non-root users from logging on during system maintenance.
. Only terminals registered in/etc/securetty allow the root user to log on. If this file does not exist, the root user can log on to any terminal. /Etc
The/usertty file is used to restrict user access. If this file does not exist, there are no other restrictions.
After the username is analyzed, login searches for/etc/passwd and/etc/shadow to verify the password and set other information about the account, such as what is the main directory and what shell is used. If no main directory is specified, the root directory is used by default. If no shell is specified,/bin/bash is used by default.
 
After the login program is successful, the latest login information (recorded in/var/log/lastlog) will be output to the corresponding terminal, and check whether the user has any new emails (in/usr
/Spool/mail ). Then set various environment variables: For bash, the system first looks for the/etc/profile script file and runs
Then, if the. bash_profile file exists in the user's main directory, execute it. Other configuration files may be called in these files. After all the configuration files are executed, various environments will change.
The number is also set, and a familiar command line prompt will appear, and the entire startup process ends.
It is hoped that the analysis of the Linux Startup Process will help those who want to learn more about the Linux Startup Process of a Linux User, and further study how Linux works next.

  1. Linux system startup depth analysis 1)
  2. Analysis of Linux Process status: R, S, and D
  3. Parsing Linux Process status T, Z, and X
  4. Brief Introduction to Linux Process Operation commands
  5. In-depth discussion on Linux partition Solutions

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.