In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the example analysis of the system startup process in linux, the article is very detailed, has a certain reference value, interested friends must read it!
Generally speaking, the startup process of all operating systems is basically:
In general, the linux system startup process can be summarized as follows:
1) Post BIOS self-test and load the hard drive.
2) read MBR and boot MBR.
3) grub boot menu (Boot Loader).
4) load kernel kernel.
5) start the init process and set the running level according to the inittab file
6) init process, execute rc.sysinit file.
7) start the kernel module and execute different levels of scripting.
8) execute / etc/rc.d/rc.local
9) start mingetty and enter the system login interface.
When installing a linux system, if you want to set the startup item, you can:
Boot to the BIOS reminder interface, press F11 (the practice of Dell server) to enter BIOS to set BOOT MENU, and then set startup items: hard disk HD boot, CD CD/DVD boot, or U disk USB boot.
The following is a detailed analytical record of the startup process of the linux operating system:
Load kernel
After the operating system takes over the hardware, first read the kernel file in the / boot directory.
[root@bastion-IDC] # ll / boot/total 21668 RW Murray. 1 root root 105195 Nov 22 2013 config-2.6.32-431.el6.x86_64drwxr-xr-x. 3 root root 1024 Aug 22 16:31 efidrwxr-xr-x. 2 root root 1024 Aug 22 16:32 grub-rw-. 1 root root 15217153 Aug 22 16:32 initramfs-2.6.32-431.el6.x86mm 64.imgdrwxmuri. 2 root root 12288 Aug 22 16:24 lost+found-rw-r--r--. 1 root root 193758 Nov 22 2013 symvers-2.6.32-431.el6.x86mm 64.gzmurr RWMUR. 1 root root 2518236 Nov 22 2013 System.map-2.6.32-431.el6.x86_64-rwxr-xr-x. 1 root root 4128368 Nov 22 2013 vmlinuz-2.6.32-431.el6.x86_64
Start the initialization process
After the kernel file is loaded, you start running the first program / sbin/init, which initializes the system environment.
Since init is the first program to run, its process number (pid) is 1. All other processes are derived from it and are its child processes.
Determine the running level
Many programs need to be booted up. They are called "service" in Windows and "daemon" in Linux.
One of the major tasks of the init process is to run these boot-up programs. However, different programs need to be started in different situations, such as when used as a server, you need to start Apache, but not as a desktop. Linux allows different boot loaders to be assigned to different occasions, which is called "runlevel". That is, at startup, you determine which programs to run according to the run level.
Linux preset seven init operating levels (0-6):
0: shutdown mode (equivalent to poweroff)
1: single user mode (cracking root password)
2: multi-user mode without network support
3: multi-user mode with network support (that is, text mode, the most commonly used mode in work)
4: reserved, unused
5: X-windows with network support supports multi-user mode (that is, desktop graphics mode)
6: reboot the system, that is, restart (equivalent to reboot)
The init process first reads the file / etc/inittab, which is the run-level settings file.
If you open it, you can see that the first line looks like this:
[root@bastion-IDC ~] # cat / etc/inittab....id:3:initdefault:
The value of initdefault is 3, indicating that the system starts with a runlevel of 3. If you need to specify a different level, you can modify this value manually.
So, what programs are there at run level 3, and how does the system know which programs should be loaded at each level?
The answer is that each run level is under the / etc directory, with a corresponding subdirectory that specifies the program to load.
/ etc/rc0.d
/ etc/rc1.d
/ etc/rc2.d
/ etc/rc3.d
/ etc/rc4.d
/ etc/rc5.d
/ etc/rc6.d
The "rc" in the directory name above indicates run command (running the program), and the last d represents directory (directory). Let's see which programs are specified in the / etc/rc3.d directory.
[root@bastion-IDC] # ll / etc/rc3.d/total 0lrwxrwxrwx. 1 root root 19 Aug 22 16:30 K10saslauthd->.. / init.d/saslauthdlrwxrwxrwx. 1 root root 18 Aug 22 16:47 K15svnserve->.. / init.d/svnservelrwxrwxrwx. 1 root root 15 Aug 23 16:21 K25squid->.. / init.d/squidlrwxrwxrwx. 1 root root 19 Dec 23 13:14 K45memcached->.. / init.d/memcachedlrwxrwxrwx. 1 root root 20 Aug 22 16:30 K50netconsole->.. / init.d/netconsolelrwxrwxrwx. 1 root root 13 Dec 21 17:45 K60nfs->.. / init.d/nfslrwxrwxrwx. 1 root root 20 Dec 21 17:45 K69rpcsvcgssd->.. / init.d/rpcsvcgssdlrwxrwxrwx. 1 root root 17 Nov 24 14:45 K75ntpdate->.. / init.d/ntpdatelrwxrwxrwx. 1 root root 20 Aug 22 16:31 K87multipathd->.. / init.d/multipathdlrwxrwxrwx. 1 root root 21 Aug 22 16:30 K87restorecond->.. / init.d/restorecondlrwxrwxrwx. 1 root root 15 Aug 22 16:30 K89rdisc->.. / init.d/rdisclrwxrwxrwx. 1 root root 22 Aug 22 16:31 S02lvm2-monitor->.. / init.d/lvm2-monitorlrwxrwxrwx. 1 root root 16 Aug 22 16:31 S07iscsid->.. / init.d/iscsidlrwxrwxrwx. 1 root root 19 Aug 22 16:30 S08ip6tables->.. / init.d/ip6tableslrwxrwxrwx. 1 root root 18 Aug 22 16:30 S08iptables->.. / init.d/iptableslrwxrwxrwx. 1 root root 17 Aug 22 16:30 S10network->.. / init.d/networklrwxrwxrwx. 1 root root 16 Aug 22 16:31 S11auditd->.. / init.d/auditdlrwxrwxrwx. 1 root root 17 Aug 22 16:30 S12rsyslog->.. / init.d/rsysloglrwxrwxrwx. 1 root root 15 Dec 21 17:45 S13iscsi->.. / init.d/iscsilrwxrwxrwx. 1 root root 17 Dec 21 17:45 S13rpcbind->.. / init.d/rpcbindlrwxrwxrwx. 1 root root 17 Dec 21 17:45 S14nfslock->.. / init.d/nfslocklrwxrwxrwx. 1 root root 19 Aug 22 16:31 S15mdmonitor->.. / init.d/mdmonitorlrwxrwxrwx. 1 root root 17 Dec 21 17:45 S19rpcgssd->.. / init.d/rpcgssdlrwxrwxrwx. 1 root root 26 Aug 22 16:31 S25blk-availability->.. / init.d/blk-availabilitylrwxrwxrwx. 1 root root 15 Aug 22 16:30 S25netfs->.. / init.d/netfslrwxrwxrwx. 1 root root 19 Aug 22 16:30 S26udev-post->.. / init.d/udev-postlrwxrwxrwx. 1 root root 18 Oct 25 11:49 S50onealert->.. / init.d/onealertlrwxrwxrwx. 1 root root 14 Aug 22 16:31 S55sshd->.. / init.d/sshdlrwxrwxrwx. 1 root root 16 Oct 26 09:47 S56xinetd->.. / init.d/xinetdlrwxrwxrwx. 1 root root 17 Aug 22 16:30 S80postfix->.. / init.d/postfixlrwxrwxrwx. 1 root root 15 Aug 22 16:30 S90crond->.. / init.d/crondlrwxrwxrwx. 1 root root 11 Aug 22 16:30 S99local->.. / rc.local
You can see:
The letter S stands for Start, which means start (the running parameter of the startup script is start)
If this location is the letter K, it means Kill, that is, the program that needs to be closed if you switch from another run level (the running parameter of the startup script is stop).
The next two digits represent the processing order, and the smaller the number, the earlier the processing, so the first program to start is motd, followed by rpcbing, nfs. When the number is the same, it starts in alphabetical order of the program name, so rsyslog starts before sudo.
All the files in this directory (except README) are the programs to be loaded at startup. If you want to add or remove some programs, it is not recommended to manually modify the / etc/rcN.d directory, it is best to use some special commands to manage (see here and here).
Load the boot boot program
As mentioned earlier, each of the seven preset "run levels" has a directory for programs that need to be booted up. It is not hard to imagine that if multiple "run levels" need to start the same program, then the startup script of the program will have a copy in each directory. This can cause administrative problems: if you want to modify the startup script, don't you have to change every directory?
The solution for Linux is that the programs listed in the seven / etc/rcN.d directories are all set to link files and point to another directory / etc/init.d, where the real startup scripts are all placed. The init process loads the startup programs one by one, which is actually running the startup scripts in this directory.
Here is what the link file really points to
[root@bastion-IDC] # ls-l / etc/rc3.dlrwxrwxrwx. 1 root root 10 Aug 22 16:30 / etc/rc3.d-> rc.d/rc3.d
Another benefit of this is that if you want to shut down or restart a process manually, go directly to the directory / etc/init.d and look for the startup script.
For example, to restart the iptables server, run the following command:
[root@bastion-IDC ~] # / etc/init.d/iptables restart
The last letter d of the directory name / etc/init.d, which means directory, indicates that this is a directory to distinguish it from the program / etc/init.
User login
After the boot program is loaded, let the user log in.
Generally speaking, there are three ways for users to log in: command line login, ssh login and graphical interface login. In these three cases, there are their own ways to authenticate users.
1) Command line login: the init process invokes the getty program (meaning get teletype) and asks the user to enter a user name and password. When the input is complete, call the login program to check the password (Debian will run one more identity checker / etc/pam.d/login). If the password is correct, read the user-specified shell from the file / etc/passwd, and then start the shell.
2) ssh login: at this point, the system calls the sshd program (Debian will run / etc/pam.d/ssh again), replacing getty and login, and then starting shell.
3) graphical interface login: the init process calls the display manager, and the corresponding display manager of the Gnome graphical interface is gdm (GNOME Display Manager), and then the user enters the user name and password. If the password is correct, read / etc/gdm3/Xsession and start the user's session.
Enter login shell
The so-called shell is simply a command-line interface that allows users to talk directly to the operating system. The shell that a user opens when he logs in is called login shell.
The default shell for Linuix is Bash, which reads a series of configuration files. There are also differences in the treatment of the three cases in the previous step.
1) Command line login: first read in / etc/profile, which is a valid configuration for all users, and then look for the following three files in turn, which is the configuration for the current user.
~ / .bash_profile
~ / .bash_login
~ / .profile
It should be noted that as long as one of these three files exists, it will no longer be read into the following files. For example, if ~ / .bash_profile exists, the last two files will not be read in.
2) ssh login: exactly the same as in the first case.
3) graphical login: only / etc/profile and ~ / .profile are loaded. In other words, ~ / .bash_profile will not run with or without it.
Open non-login shell
To be honest, after the previous step, the startup process of Linux is over, and the user can already see the command line prompt or graphical interface. However, for the sake of the integrity of the content, this step must be introduced again.
After users enter the operating system, they will often manually open a shell. This shell is called non-login shell, which means that unlike the shell that appears when logging in, it does not read configuration files such as / etc/profile and .profile.
The importance of non-login shell lies not only in that it is the shell that users come into contact with most, but also in that it reads into the user's own bash profile ~ / .bashrc. Most of the time, our customization of bash is written in this file.
You might ask, if you don't enter non-login shell, .bashrc won't run, so bash won't be able to customize it. In fact, Debian has already considered this problem, please open the file ~ / .profile, you can see the following code:
If [- n "$BASH_VERSION"]; then if [- f "$HOME/.bashrc"]; then. "$HOME/.bashrc" fi fi
The above code first determines whether the variable $BASH_VERSION has a value, then determines whether a .bashrc file exists in the home directory, and runs it if it does. The dot at the beginning of the third line, shorthand for the source command, indicates that it is possible to run a file and write it as "source ~ / .bashrc".
Therefore, as long as you run the ~ / .profile file, the ~ / .bashrc file will run in conjunction with it. But as mentioned in the first case in the previous section, if the ~ / .profile file exists, the ~ / .profile file may not be run. To solve this problem, just write the following code into .bash _ profile.
If [- f ~ / .profile]; then. ~ / .profile fi
In this way, in either case, .bashrc will be executed, and the user's settings can be safely written to this file.
The reason why setting up Bash is so tedious is due to historical reasons. In the early days, the computer was slow and it took a long time to load the configuration file, so the authors of Bash had to divide the configuration file into several parts and load it in stages. The common settings of the system are placed in / etc/profile, the user's personal settings that need to be inherited by all child processes are placed in .profile, and the settings that do not need to be inherited are placed in .bashrc.
By the way, in addition to Linux, the shell used by Mac OS X is also Bash. However, it only loads .bash _ profile and then calls .bashrc in .bash _ profile. And this is true whether you are logging in to ssh or launching a shell window in a graphical interface.
The above is all the contents of the article "sample Analysis of the system Startup process in linux". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.