📄 init.8
字号:
.\"{{{}}}.\"{{{ Title.TH INIT 8 "29 Jul 2004" "" "Linux System Administrator's Manual".\"}}}.\"{{{ Name.SH NAMEinit, telinit \- process control initialization.\"}}}.\"{{{ Synopsis.SH SYNOPSIS.B /sbin/init.RB [ " -a " ].RB [ " -s " ].RB [ " -b " ].RB [ " -z xxx " ].RB [ " 0123456Ss " ].br.B /sbin/telinit.RB [ " \-t sec " ].RB [ " 0123456sSQqabcUu " ].\"}}}.\"{{{ Description.SH DESCRIPTION.\"{{{ init.SS Init.B Initis the parent of all processes. Its primary role is to create processesfrom a script stored in the file \fB/etc/inittab\fP (see\fIinittab\fP(5)). This file usually has entries which cause \fBinit\fPto spawn \fBgetty\fPs on each line that users can log in. It alsocontrols autonomous processes required by any particular system..PP.\"{{{ Runlevels.SH RUNLEVELSA \fIrunlevel\fP is a software configuration of the system which allowsonly a selected group of processes to exist. The processes spawned by\fBinit\fP for each of these runlevels are defined in the\fB/etc/inittab\fP file. \fBInit\fP can be in one of eight runlevels:\fB0\(en6\fP and \fBS\fP or \fBs\fP. The runlevel ischanged by having a privileged user run \fBtelinit\fP, which sendsappropriate signals to \fBinit\fP, telling it which runlevel to changeto..PPRunlevels \fB0\fP, \fB1\fP, and \fB6\fP are reserved. Runlevel 0 is used tohalt the system, runlevel 6 is used to reboot the system, and runlevel1 is used to get the system down into single user mode. Runlevel \fBS\fPis not really meant to be used directly, but more for the scripts that areexecuted when entering runlevel 1. For more information on this,see the manpages for \fBshutdown\fP(8) and \fBinittab\fP(5)..PPRunlevels 7-9 are also valid, though not really documented. This isbecause "traditional" Unix variants don't use them.In case you're curious, runlevels \fIS\fP and \fIs\fP are in fact the same.Internally they are aliases for the same runlevel..\"}}}.PP.SH BOOTINGAfter \fBinit\fP is invoked as the last step of the kernel boot sequence,it looks for the file \fB/etc/inittab\fP to see if there is an entry of thetype \fBinitdefault\fP (see \fIinittab\fP(5)). The \fBinitdefault\fP entrydetermines the initial runlevel of the system. If there is no suchentry (or no \fB/etc/inittab\fP at all), a runlevel must beentered at the system console..PPRunlevel \fBS\fP or \fBs\fP bring the system to single user modeand do not require an \fB/etc/inittab\fP file. In single user mode,\fB/sbin/sulogin\fP is invoked on \fB/dev/console\fP..PPWhen entering single user mode, \fBinit\fP initializes the consoles\fBstty\fP settings to sane values. Clocal mode is set. Hardwarespeed and handshaking are not changed..PPWhen entering a multi-user mode for the first time, \fBinit\fP performs the\fBboot\fP and \fBbootwait\fP entries to allow file systems to bemounted before users can log in. Then all entries matching the runlevelare processed..PPWhen starting a new process, \fBinit\fP first checks whether the file\fI/etc/initscript\fP exists. If it does, it uses this script tostart the process..PPEach time a child terminates, \fBinit\fP records the fact and the reasonit died in \fB/var/run/utmp\fP and \fB/var/log/wtmp\fP,provided that these files exist..SH CHANGING RUNLEVELSAfter it has spawned all of the processes specified, \fBinit\fP waitsfor one of its descendant processes to die, a powerfail signal, or untilit is signaled by \fBtelinit\fP to change the system's runlevel. When one of the above three conditions occurs, it re-examinesthe \fB/etc/inittab\fP file. New entries can be added to this file atany time. However, \fBinit\fP still waits for one of the above threeconditions to occur. To provide for an instantaneous response, the\fBtelinit Q\fP or \fBq\fP command can wake up \fBinit\fP to re-examine the\fB/etc/inittab\fP file..PPIf \fBinit\fP is not in single user mode and receives a powerfailsignal (SIGPWR), it reads the file \fB/etc/powerstatus\fP. It then startsa command based on the contents of this file:.IP F(AIL)Power is failing, UPS is providing the power. Execute the \fBpowerwait\fPand \fBpowerfail\fP entries..IP O(K)The power has been restored, execute the \fBpowerokwait\fP entries..IP L(OW)The power is failing and the UPS has a low battery. Execute the\fBpowerfailnow\fP entries..PPIf /etc/powerstatus doesn't exist or contains anything else then theletters \fBF\fP, \fBO\fP or \fBL\fP, init will behave as if it has readthe letter \fBF\fP..PPUsage of \fBSIGPWR\fP and \fB/etc/powerstatus\fP is discouraged. Someonewanting to interact with \fBinit\fP should use the \fB/dev/initctl\fPcontrol channel - see the source code of the \fBsysvinit\fP packagefor more documentation about this..PPWhen \fBinit\fP is requested to change the runlevel, it sends thewarning signal \s-1\fBSIGTERM\fP\s0 to all processes that are undefinedin the new runlevel. It then waits 5 seconds before forciblyterminating these processes via the \s-1\fBSIGKILL\fP\s0 signal.Note that \fBinit\fP assumes that all these processes (and theirdescendants) remain in the same process group which \fBinit\fPoriginally created for them. If any process changes its process groupaffiliation it will not receive these signals. Such processes need tobe terminated separately..\"}}}.\"{{{ telinit.SH TELINIT\fB/sbin/telinit\fP is linked to \fB/sbin/init\fP. It takes aone-character argument and signals \fBinit\fP to perform the appropriateaction. The following arguments serve as directives to\fBtelinit\fP:.IP "\fB0\fP,\fB1\fP,\fB2\fP,\fB3\fP,\fB4\fP,\fB5\fP or \fB6\fP"tell \fBinit\fP to switch to the specified run level..IP \fBa\fP,\fBb\fP,\fBc\fPtell \fBinit\fP to process only those \fB/etc/inittab\fP fileentries having runlevel \fBa\fP,\fBb\fP or \fBc\fP..IP "\fBQ\fP or \fBq\fP"tell \fBinit\fP to re-examine the \fB/etc/inittab\fP file..IP "\fBS\fP or \fBs\fP"tell \fBinit\fP to switch to single user mode..IP "\fBU\fP or \fBu\fP"tell \fBinit\fP to re-execute itself (preserving the state). No re-examining of \fB/etc/inittab\fP file happens. Run level should be one of \fBSs12345\fP,otherwise request would be silently ignored..PP\fBtelinit\fP can also tell \fBinit\fP how long it should waitbetween sending processes the SIGTERM and SIGKILL signals. The defaultis 5 seconds, but this can be changed with the \fB-t sec\fP option..PP\fBtelinit\fP can be invoked only by users with appropriateprivileges..PPThe \fBinit\fP binary checks if it is \fBinit\fP or \fBtelinit\fP by lookingat its \fIprocess id\fP; the real \fBinit\fP's process id is always \fB1\fP.From this it follows that instead of calling \fBtelinit\fP one can alsojust use \fBinit\fP instead as a shortcut..\"}}}.\"}}}.SH ENVIRONMENT\fBInit\fP sets the following environment variables for all its children:.IP \fBPATH\fP\fI/bin:/usr/bin:/sbin:/usr/sbin\fP.IP \fBINIT_VERSION\fPAs the name says. Useful to determine if a script runs directly from \fBinit\fP..IP \fBRUNLEVEL\fPThe current system runlevel..IP \fBPREVLEVEL\fPThe previous runlevel (useful after a runlevel switch)..IP \fBCONSOLE\fPThe system console. This is really inherited from the kernel; howeverif it is not set \fBinit\fP will set it to \fB/dev/console\fP by default..SH BOOTFLAGSIt is possible to pass a number of flags to \fBinit\fP from theboot monitor (eg. LILO). \fBInit\fP accepts the following flags:.TP 0.5i.B -s, S, singleSingle user mode boot. In this mode \fI/etc/inittab\fP isexamined and the bootup rc scripts are usually run beforethe single user mode shell is started..PP.TP 0.5i.B 1-5Runlevel to boot into..PP.TP 0.5i.B -b, emergencyBoot directly into a single user shell without running anyother startup scripts..PP.TP 0.5i.B -a, autoThe LILO boot loader adds the word "auto" to the command line if itbooted the kernel with the default command line (without user intervention).If this is found \fBinit\fP sets the "AUTOBOOT" environmentvariable to "yes". Note that you cannot use this for any securitymeasures - of course the user could specify "auto" or \-a on thecommand line manually..PP.TP 0.5i.B -z xxxThe argument to -z is ignored. You can use this to expand the commandline a bit, so that it takes some more space on the stack. \fBInit\fPcan then manipulate the command line so that \fBps\fP(1) showsthe current runlevel..PP.SH INTERFACEInit listens on a \fIfifo\fP in /dev, \fI/dev/initctl\fP, for messages.\fBTelinit\fP uses this to communicate with init. The interface is notvery well documented or finished. Those interested should study the\fIinitreq.h\fP file in the \fIsrc/\fP subdirectory of the \fBinit\fPsource code tar archive..SH SIGNALSInit reacts to several signals:.TP 0.5i.B SIGHUPHas the same effect as \fBtelinit q\fP..PP.TP 0.5i.B SIGUSR1On receipt of this signals, init closes and re-opens its control fifo,\fB/dev/initctl\fP. Useful for bootscripts when /dev is remounted..TP 0.5i.B SIGINTNormally the kernel sends this signal to init when CTRL-ALT-DEL ispressed. It activates the \fIctrlaltdel\fP action..TP 0.5i.B SIGWINCHThe kernel sends this signal when the \fIKeyboardSignal\fP key is hit.It activates the \fIkbrequest\fP action.\"{{{ Conforming to.SH CONFORMING TO\fBInit\fP is compatible with the System V init. It works closelytogether with the scripts in the directories\fI/etc/init.d\fP and \fI/etc/rc{runlevel}.d\fP.If your system uses this convention, there should be a \fIREADME\fPfile in the directory \fI/etc/init.d\fP explaining how these scripts work..\"}}}.\"{{{ Files.SH FILES.nf/etc/inittab/etc/initscript/dev/console/var/run/utmp/var/log/wtmp/dev/initctl.fi.\"}}}.\"{{{ Warnings.SH WARNINGS\fBInit\fP assumes that processes and descendants of processesremain in the same process group which was originally createdfor them. If the processes change their group, \fBinit\fP can'tkill them and you may end up with two processes reading from oneterminal line..\"}}}.\"{{{ Diagnostics.SH DIAGNOSTICSIf \fBinit\fP finds that it is continuously respawning an entrymore than 10 times in 2 minutes, it will assume that there is an errorin the command string, generate an error message on the system console,and refuse to respawn this entry until either 5 minutes has elapsed orit receives a signal. This prevents it from eating up system resourceswhen someone makes a typographical error in the \fB/etc/inittab\fP fileor the program for the entry is removed..\"}}}.\"{{{ Author.SH AUTHORMiquel van Smoorenburg (miquels@cistron.nl), initial manualpage by Michael Haardt (u31b3hs@pool.informatik.rwth-aachen.de)..\"}}}.\"{{{ See also.SH "SEE ALSO".BR getty (1),.BR login (1),.BR sh (1),.BR runlevel (8),.BR shutdown(8),.BR kill (1),.BR inittab (5),.BR initscript (5),.BR utmp (5).\"}}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -