usage.xml 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
  4. <!ENTITY % general-entities SYSTEM "../general.ent">
  5. %general-entities;
  6. ]>
  7. <sect1 id="ch-scripts-usage">
  8. <?dbhtml filename="usage.html"?>
  9. <title>How Do These Bootscripts Work?</title>
  10. <indexterm zone="ch-scripts-usage">
  11. <primary sortas="a-Bootscripts">Bootscripts</primary>
  12. <secondary>usage</secondary>
  13. </indexterm>
  14. <para>Linux uses a special booting facility named SysVinit that is based on a
  15. concept of <emphasis>run-levels</emphasis>. It can be quite different from one
  16. system to another, so it cannot be assumed that because things worked in one
  17. particular Linux distribution, they should work the same in LFS too. LFS has its
  18. own way of doing things, but it respects generally accepted standards.</para>
  19. <para>SysVinit (which will be referred to as <quote>init</quote> from now on)
  20. works using a run-levels scheme. There are seven (numbered 0 to 6) run-levels
  21. (actually, there are more run-levels, but they are for special cases and are
  22. generally not used. See <filename>init(8)</filename> for more details), and
  23. each one of those corresponds to the actions the computer is supposed to
  24. perform when it starts up. The default run-level is 3. Here are the
  25. descriptions of the different run-levels as they are implemented:</para>
  26. <literallayout>0: halt the computer
  27. 1: single-user mode
  28. 2: multi-user mode without networking
  29. 3: multi-user mode with networking
  30. 4: reserved for customization, otherwise does the same as 3
  31. 5: same as 4, it is usually used for GUI login (like X's <command>xdm</command> or KDE's <command>kdm</command>)
  32. 6: reboot the computer</literallayout>
  33. <sect2 id="conf-sysvinit" role="configuration">
  34. <title>Configuring Sysvinit</title>
  35. <indexterm zone="conf-sysvinit">
  36. <primary sortas="a-Sysvinit">Sysvinit</primary>
  37. <secondary>configuring</secondary>
  38. </indexterm>
  39. <indexterm zone="conf-sysvinit">
  40. <primary sortas="e-/etc/inittab">/etc/inittab</primary>
  41. </indexterm>
  42. <para>During the kernel initialization, the first program that is run
  43. is either specified on the command line or, by default
  44. <command>init</command>. This program reads the initialization file
  45. <filename>/etc/inittab</filename>. Create this file with:</para>
  46. <screen><userinput>cat &gt; /etc/inittab &lt;&lt; "EOF"
  47. <literal># Begin /etc/inittab
  48. id:3:initdefault:
  49. si::sysinit:/etc/rc.d/init.d/rc S
  50. l0:0:wait:/etc/rc.d/init.d/rc 0
  51. l1:S1:wait:/etc/rc.d/init.d/rc 1
  52. l2:2:wait:/etc/rc.d/init.d/rc 2
  53. l3:3:wait:/etc/rc.d/init.d/rc 3
  54. l4:4:wait:/etc/rc.d/init.d/rc 4
  55. l5:5:wait:/etc/rc.d/init.d/rc 5
  56. l6:6:wait:/etc/rc.d/init.d/rc 6
  57. ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
  58. su:S016:once:/sbin/sulogin
  59. 1:2345:respawn:/sbin/agetty --noclear tty1 9600
  60. 2:2345:respawn:/sbin/agetty tty2 9600
  61. 3:2345:respawn:/sbin/agetty tty3 9600
  62. 4:2345:respawn:/sbin/agetty tty4 9600
  63. 5:2345:respawn:/sbin/agetty tty5 9600
  64. 6:2345:respawn:/sbin/agetty tty6 9600
  65. # End /etc/inittab</literal>
  66. EOF</userinput></screen>
  67. <para>An explanation of this initialization file is in the man page for
  68. <emphasis>inittab</emphasis>. For LFS, the key command that is run is
  69. <command>rc</command>. The intialization file above will instruct
  70. <command>rc</command> to run all the scripts starting with an S in the
  71. <filename class="directory">/etc/rc.d/rcsysinit.d</filename> directory
  72. followed by all the scripts starting with an S in the <filename
  73. class="directory">/etc/rc.d/rc?.d</filename> directory where the question
  74. mark is specified by the initdefault value.</para>
  75. <para>As a convenience, the <command>rc</command> script reads a library of
  76. functions in <filename class="directory">/lib/lsb/init-functions</filename>.
  77. This library also reads an optional configuration file,
  78. <filename>/etc/sysconfig/rc.site</filename>. Any of the system
  79. configuration file parameters described in subsequent sections can be
  80. alternatively placed in this file allowing consolidation of all system
  81. parameters in this one file.</para>
  82. <para>As a debugging convenience, the functions script also logs all output
  83. to <filename>/run/var/bootlog</filename>. Since the <filename
  84. class="directory">/run</filename> directory is a tmpfs, this file is not
  85. persistent across boots, however it is appended to the more permanent file
  86. <filename>/var/log/boot.log</filename> at the end of the boot process.</para>
  87. </sect2>
  88. <sect2 id="init-levels" >
  89. <title>Changing Run Levels</title>
  90. <para>Changing run-levels is done with <command>init
  91. <replaceable>&lt;runlevel&gt;</replaceable></command>, where
  92. <replaceable>&lt;runlevel&gt;</replaceable> is the target run-level. For example, to
  93. reboot the computer, a user could issue the <command>init 6</command> command,
  94. which is an alias for the <command>reboot</command> command. Likewise,
  95. <command>init 0</command> is an alias for the <command>halt</command>
  96. command.</para>
  97. <para>There are a number of directories under <filename
  98. class="directory">/etc/rc.d</filename> that look like <filename
  99. class="directory">rc?.d</filename> (where ? is the number of the run-level) and
  100. <filename class="directory">rcsysinit.d</filename>, all containing a number of
  101. symbolic links. Some begin with a <emphasis>K</emphasis>, the others begin with
  102. an <emphasis>S</emphasis>, and all of them have two numbers following the
  103. initial letter. The K means to stop (kill) a service and the S means to start a
  104. service. The numbers determine the order in which the scripts are run, from 00
  105. to 99&mdash;the lower the number the earlier it gets executed. When
  106. <command>init</command> switches to another run-level, the appropriate services
  107. are either started or stopped, depending on the runlevel chosen.</para>
  108. <para>The real scripts are in <filename
  109. class="directory">/etc/rc.d/init.d</filename>. They do the actual work, and
  110. the symlinks all point to them. K links and S links point to
  111. the same script in <filename class="directory">/etc/rc.d/init.d</filename>.
  112. This is because the scripts can be called with different parameters like
  113. <parameter>start</parameter>, <parameter>stop</parameter>,
  114. <parameter>restart</parameter>, <parameter>reload</parameter>, and
  115. <parameter>status</parameter>. When a K link is encountered, the appropriate
  116. script is run with the <parameter>stop</parameter> argument. When an S link
  117. is encountered, the appropriate script is run with the
  118. <parameter>start</parameter> argument.</para>
  119. <para>There is one exception to this explanation. Links that start
  120. with an <emphasis>S</emphasis> in the <filename
  121. class="directory">rc0.d</filename> and <filename
  122. class="directory">rc6.d</filename> directories will not cause anything
  123. to be started. They will be called with the parameter
  124. <parameter>stop</parameter> to stop something. The logic behind this
  125. is that when a user is going to reboot or halt the system, nothing
  126. needs to be started. The system only needs to be stopped.</para>
  127. <para>These are descriptions of what the arguments make the scripts
  128. do:</para>
  129. <variablelist>
  130. <varlistentry>
  131. <term><parameter>start</parameter></term>
  132. <listitem>
  133. <para>The service is started.</para>
  134. </listitem>
  135. </varlistentry>
  136. <varlistentry>
  137. <term><parameter>stop</parameter></term>
  138. <listitem>
  139. <para>The service is stopped.</para>
  140. </listitem>
  141. </varlistentry>
  142. <varlistentry>
  143. <term><parameter>restart</parameter></term>
  144. <listitem>
  145. <para>The service is stopped and then started again.</para>
  146. </listitem>
  147. </varlistentry>
  148. <varlistentry>
  149. <term><parameter>reload</parameter></term>
  150. <listitem>
  151. <para>The configuration of the service is updated.
  152. This is used after the configuration file of a service was modified, when
  153. the service does not need to be restarted.</para>
  154. </listitem>
  155. </varlistentry>
  156. <varlistentry>
  157. <term><parameter>status</parameter></term>
  158. <listitem>
  159. <para>Tells if the service is running and with which PIDs.</para>
  160. </listitem>
  161. </varlistentry>
  162. </variablelist>
  163. <para>Feel free to modify the way the boot process works (after all,
  164. it is your own LFS system). The files given here are an example of how
  165. it can be done.</para>
  166. </sect2>
  167. </sect1>