usage.xml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
  3. <!ENTITY % general-entities SYSTEM "../general.ent">
  4. %general-entities;
  5. ]>
  6. <sect1 id="ch-scripts-usage">
  7. <title>How Do These Bootscripts Work?</title>
  8. <?dbhtml filename="usage.html"?>
  9. <indexterm zone="ch-scripts-usage">
  10. <primary sortas="a-Bootscripts">Bootscripts</primary>
  11. <secondary>usage</secondary></indexterm>
  12. <para>Linux uses a special booting facility named SysVinit that is based on a
  13. concept of <emphasis>run-levels</emphasis>. It can be quite different from one
  14. system to another, so it cannot be assumed that because things worked in one
  15. particular Linux distribution, they should work the same in LFS too. LFS has its
  16. own way of doing things, but it respects generally accepted standards.</para>
  17. <para>SysVinit (which will be referred to as <quote>init</quote> from now on)
  18. works using a run-levels scheme. There are seven (numbered 0 to 6) run-levels
  19. (actually, there are more run-levels, but they are for special cases and are
  20. generally not used. The init manual page describes those details), and each one
  21. of those corresponds to the actions the computer is supposed to perform when it
  22. starts up. The default run-level is 3. Here are the descriptions of the
  23. different run-levels as they are implemented:</para>
  24. <literallayout>0: halt the computer
  25. 1: single-user mode
  26. 2: multi-user mode without networking
  27. 3: multi-user mode with networking
  28. 4: reserved for customization, otherwise does the same as 3
  29. 5: same as 4, it is usually used for GUI login (like X's <command>xdm</command> or KDE's <command>kdm</command>)
  30. 6: reboot the computer</literallayout>
  31. <para>The command used to change run-levels is <command>init
  32. <replaceable>[runlevel]</replaceable></command>, where
  33. <replaceable>[runlevel]</replaceable> is the target run-level. For example, to
  34. reboot the computer, a user could issue the <command>init 6</command> command,
  35. which is an alias for the <command>reboot</command> command. Likewise,
  36. <command>init 0</command> is an alias for the <command>halt</command>
  37. command.</para>
  38. <para>There are a number of directories under <filename
  39. class="directory">/etc/rc.d</filename> that look like <filename
  40. class="directory">rc?.d</filename> (where ? is the number of the run-level) and
  41. <filename class="directory">rcsysinit.d</filename>, all containing a number of
  42. symbolic links. Some begin with a <emphasis>K</emphasis>, the others begin with
  43. an <emphasis>S</emphasis>, and all of them have two numbers following the
  44. initial letter. The K means to stop (kill) a service and the S means to start a
  45. service. The numbers determine the order in which the scripts are run, from 00
  46. to 99&mdash;the lower the number the earlier it gets executed. When
  47. <command>init</command> switches to another run-level, the appropriate services
  48. are either started or stopped, depending on the runlevel chosen.</para>
  49. <para>The real scripts are in <filename
  50. class="directory">/etc/rc.d/init.d</filename>. They do the actual
  51. work, and the symlinks all point to them. Killing links and starting
  52. links point to the same script in <filename
  53. class="directory">/etc/rc.d/init.d</filename>. This is because the
  54. scripts can be called with different parameters like
  55. <parameter>start</parameter>, <parameter>stop</parameter>,
  56. <parameter>restart</parameter>, <parameter>reload</parameter>, and
  57. <parameter>status</parameter>. When a K link is encountered, the
  58. appropriate script is run with the <parameter>stop</parameter>
  59. argument. When an S link is encountered, the appropriate script is run
  60. with the <parameter>start</parameter> argument.</para>
  61. <para>There is one exception to this explanation. Links that start
  62. with an <emphasis>S</emphasis> in the <filename
  63. class="directory">rc0.d</filename> and <filename
  64. class="directory">rc6.d</filename> directories will not cause anything
  65. to be started. They will be called with the parameter
  66. <parameter>stop</parameter> to stop something. The logic behind this
  67. is that when a user is going to reboot or halt the system, nothing
  68. needs to be started. The system only needs to be stopped.</para>
  69. <para>These are descriptions of what the arguments make the scripts
  70. do:</para>
  71. <variablelist>
  72. <varlistentry>
  73. <term><parameter>start</parameter></term>
  74. <listitem><para>The service is started.</para></listitem>
  75. </varlistentry>
  76. <varlistentry>
  77. <term><parameter>stop</parameter></term>
  78. <listitem><para>The service is stopped.</para></listitem>
  79. </varlistentry>
  80. <varlistentry>
  81. <term><parameter>restart</parameter></term>
  82. <listitem><para>The service is stopped and then started again.</para></listitem>
  83. </varlistentry>
  84. <varlistentry>
  85. <term><parameter>reload</parameter></term>
  86. <listitem><para>The configuration of the service is updated.
  87. This is used after the configuration file of a service was modified, when
  88. the service does not need to be restarted.</para></listitem>
  89. </varlistentry>
  90. <varlistentry>
  91. <term><parameter>status</parameter></term>
  92. <listitem><para>Tells if the service is running and with which PIDs.</para></listitem>
  93. </varlistentry>
  94. </variablelist>
  95. <para>Feel free to modify the way the boot process works (after all,
  96. it is your own LFS system). The files given here are an example of how
  97. it can be done.</para>
  98. </sect1>