usage.xml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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
  13. based on a concept of <emphasis>run-levels</emphasis>. It can be quite
  14. different from one system to another, so it cannot be assumed that
  15. because things worked in &lt;insert distro name&gt;, they should work
  16. the same in LFS too. LFS has its own way of doing things, but it
  17. respects generally accepted standards.</para>
  18. <para>SysVinit (which will be referred to as <quote>init</quote> from
  19. now on) works using a run-levels scheme. There are seven (from 0 to 6)
  20. run-levels (actually, there are more run-levels, but they are for
  21. special cases and are generally not used. The init man page describes
  22. those details), and each one of those corresponds to the actions the
  23. computer is supposed to perform when it starts up. The default
  24. run-level is 3. Here are the descriptions of the different run-levels
  25. 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. <para>The command used to change run-levels is <command>init
  34. <replaceable>[runlevel]</replaceable></command>, where
  35. <replaceable>[runlevel]</replaceable> is the target run-level. For
  36. example, to reboot the computer, a user would issue the <command>init
  37. 6</command> command. The <command>reboot</command> command is an
  38. alias for it, as is the <command>halt</command> command an alias for
  39. <command>init 0</command>.</para>
  40. <para>There are a number of directories under <filename
  41. class="directory">/etc/rc.d</filename> that look like <filename
  42. class="directory">rc?.d</filename> (where ? is the number of the
  43. run-level) and <filename class="directory">rcsysinit.d</filename>, all
  44. containing a number of symbolic links. Some begin with a
  45. <emphasis>K</emphasis>, the others begin with an
  46. <emphasis>S</emphasis>, and all of them have two numbers following the
  47. initial letter. The K means to stop (kill) a service and the S means
  48. to start a service. The numbers determine the order in which the
  49. scripts are run, from 00 to 99&mdash;the lower the number the earlier it
  50. gets executed. When init switches to another run-level, the
  51. appropriate services get killed and others get started.</para>
  52. <para>The real scripts are in <filename
  53. class="directory">/etc/rc.d/init.d</filename>. They do the actual
  54. work, and the symlinks all point to them. Killing links and starting
  55. links point to the same script in <filename
  56. class="directory">/etc/rc.d/init.d</filename>. This is because the
  57. scripts can be called with different parameters like
  58. <parameter>start</parameter>, <parameter>stop</parameter>,
  59. <parameter>restart</parameter>, <parameter>reload</parameter>, and
  60. <parameter>status</parameter>. When a K link is encountered, the
  61. appropriate script is run with the <parameter>stop</parameter>
  62. argument. When an S link is encountered, the appropriate script is run
  63. with the <parameter>start</parameter> argument.</para>
  64. <para>There is one exception to this explanation. Links that start
  65. with an <emphasis>S</emphasis> in the <filename
  66. class="directory">rc0.d</filename> and <filename
  67. class="directory">rc6.d</filename> directories will not cause anything
  68. to be started. They will be called with the parameter
  69. <parameter>stop</parameter> to stop something. The logic behind this
  70. is that when a user is going to reboot or halt the system, nothing
  71. needs to be started. The system only needs to be stopped.</para>
  72. <para>These are descriptions of what the arguments make the scripts
  73. do:</para>
  74. <variablelist>
  75. <varlistentry>
  76. <term><parameter>start</parameter></term>
  77. <listitem><para>The service is started.</para></listitem>
  78. </varlistentry>
  79. <varlistentry>
  80. <term><parameter>stop</parameter></term>
  81. <listitem><para>The service is stopped.</para></listitem>
  82. </varlistentry>
  83. <varlistentry>
  84. <term><parameter>restart</parameter></term>
  85. <listitem><para>The service is stopped and then started again.</para></listitem>
  86. </varlistentry>
  87. <varlistentry>
  88. <term><parameter>reload</parameter></term>
  89. <listitem><para>The configuration of the service is updated.
  90. This is used after the configuration file of a service was modified, when
  91. the service does not need to be restarted.</para></listitem>
  92. </varlistentry>
  93. <varlistentry>
  94. <term><parameter>status</parameter></term>
  95. <listitem><para>Tells if the service is running and with which PIDs.</para></listitem>
  96. </varlistentry>
  97. </variablelist>
  98. <para>Feel free to modify the way the boot process works (after all,
  99. it is your own LFS system). The files given here are an example of how
  100. it can be done.</para>
  101. </sect1>