Linux has its own set of complete boot system, grasp the context of Linux start-up, Linux startup process will no longer mysterious.
It is advisable to look at the drawings before reading.
In this article, suppose that the init tree set in Inittab is:
/etc/rc.d/rc0.d
/etc/rc.d/rc1.d
/etc/rc.d/rc2.d
/etc/rc.d/rc3.d
/etc/rc.d/rc4.d
/etc/rc.d/rc5.d
/etc/rc.d/rc6.d
/etc/rc.d/init.d
1. About Linux Startup
Init is the father of all processes
Init reads/etc/inittab, executes Rc.sysinit script
(Note that the filename is not necessarily, and some Unix will even write the statement directly in Inittab)
The Rc.sysinit script does a lot of work:
Init $PATH
Config network
Start Swap function
Set hostname
Check root file system, repair if needed
Check root space
....
Rc.sysinit perform RC according to Inittab? D Script
Linux is a multiuser system, Getty is the watershed between multi-user and Single-user
The system script was run before Getty
. About RC.D
All startup scripts are placed under/ETC/RC.D/INIT.D
RC?. D is the link to the script in Init.d,
The name format is:
S{number}{name}
K{number}{name}
S-Starting file passes the start argument to the script
K-initiated file passes the Stop argument to the script
Number determines the order of execution
3. Startup script Example
This is a/etc/rc.d/init.d/apache script to start the httpd:
Code:
#!/bin/bash
Source/etc/sysconfig/rc
SOURCE $RC _functions
Case "$" in
Start
echo "Starting Apache daemon ..."
/usr/local/apache2/bin/apachectl-k start
Evaluate_retval
;;
Stop
echo "Stopping Apache daemon ..."
/usr/local/apache2/bin/apachectl-k stop
Evaluate_retval
;;
Restart)
echo "Restarting Apache daemon ..."
/usr/local/apache2/bin/apachectl-k restart
Evaluate_retval
;;
Status
Statusproc/usr/local/apache2/bin/httpd
;;
*)
echo "Usage: $ {Start|stop|restart|status}"
Exit 1
;;
Esac can see that he accepts start,stop,restart,status parameters
And then you can build RC? D's Links:
Code:
CD/ETC/RC.D/INIT.D &&
Ln-sf.. /init.d/apache.. /rc0.d/k28apache &&
Ln-sf.. /init.d/apache.. /rc1.d/k28apache &&
Ln-sf.. /init.d/apache.. /rc2.d/k28apache &&
Ln-sf.. /init.d/apache.. /rc3.d/s32apache &&
Ln-sf.. /init.d/apache.. /rc4.d/s32apache &&
Ln-sf.. /init.d/apache.. /rc5.d/s32apache &&
Ln-sf.. /init.d/apache.. /rc6.d/k28apache4. About Rc.local
Often used rc.local is completely a matter of habit, not standard.
There are different implementations for each distribution, and you can do this:
Code:
Touch/etc/rc.d/rc.local
chmod +x/etc/rc.d/rc.local
Ln-sf/etc/rc.d/rc.local/etc/rc.d/rc1.d/s999rc.local &&
Ln-sf/etc/rc.d/rc.local/etc/rc.d/rc2.d/s999rc.local &&
Ln-sf/etc/rc.d/rc.local/etc/rc.d/rc3.d/s999rc.local &&
Ln-sf/etc/rc.d/rc.local/etc/rc.d/rc4.d/s999rc.local &&
Ln-sf/etc/rc.d/rc.local/etc/rc.d/rc5.d/s999rc.local &&
Ln-sf/etc/rc.d/rc.local/etc/rc.d/rc6.d/s999rc.local5. About bash Startup scripts
/etc/profile
/etc/bashrc
~/.bash_profile
~/.bashrc
It's bash's startup script.
Generally used to set the single user's startup environment, you can also achieve the boot single user's program, but to be clear that they are in the bash category rather than the system category.
Their specific role is described as follows:
/bin/bash This command interpreter (shell after abbreviation) uses a series of startup files to create a running environment:
/etc/profile
/etc/bashrc
~/.bash_profile
~/.bashrc
~/.bash_logout
Each file has a special function and has a different impact on the landing and interaction environment.
/etc/profile and ~/.bash_profile are invoked when an interactive landing shell is started.
/ETC/BASHRC and ~/.BASHRC are invoked when an interactive, non-landing shell is started.
~/.bash_logout is read when the user logs out of the login
An interactive landing shell will run after the/bin/login is successfully logged in. An interactive, non-landing shell is run through the command line, such as [prompt] $/bin/bash. Generally a non-interactive shell appears when running a shell script. A non-interactive shell is called because it does not wait for input on the command line but simply executes the script.