usage.xml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <sect1 id="ch07-usage">
  2. <title>How does the booting process with these scripts work?</title>
  3. <para>
  4. Linux uses a special booting facility named SysVinit. It's based on a
  5. concept of <emphasis>runlevels</emphasis>. It can be widely different
  6. from one system to another, so don't assume that because things
  7. worked in &lt;insert distro name&gt; they should work like that in LFS
  8. too. LFS has it's own way of doing things, but it respects generally
  9. accepted standards.
  10. </para>
  11. <para>
  12. SysVinit (which we'll call <emphasis>init</emphasis> from now on) works
  13. using a runlevels scheme. There are 7 (from 0 to 6) runlevels
  14. (actually, there are more runlevels but they are for special cases and
  15. generally not used. Read the init man page for those details), and each
  16. one of those corresponds to the things you want your computer to do when
  17. it starts up. The default runlevel is 3. Here are the descriptions of the
  18. different runlevels as they are often implemented:
  19. </para>
  20. <literallayout>
  21. 0: halt the computer
  22. 1: single-user mode
  23. 2: multi-user mode without networking
  24. 3: multi-user mode with networking
  25. 4: reserved for customization, otherwise does the same as 3
  26. 5: same as 4, it is usually used for GUI login (like X's xdm or KDE's kdm)
  27. 6: reboot the computer
  28. </literallayout>
  29. <para>
  30. The command used to change runlevels is <userinput>init
  31. &lt;runlevel&gt;</userinput> where &lt;runlevel&gt; is
  32. the target runlevel. For example, to reboot the computer, you'd issue
  33. the init 6 command. The reboot command is just an alias, as is the halt
  34. command an alias to init 0.
  35. </para>
  36. <para>
  37. The /etc/init.d/rcS script is run at every startup of the computer,
  38. before any runlevel is executed and runs the scripts listed in
  39. /etc/rcS.d
  40. </para>
  41. <para>
  42. There are a number of directories under /etc that look like like rc?.d
  43. where ? is the number of the runlevel and rcS.d. Take a look at one of
  44. them (after you finish this chapter that is, right now there's nothing
  45. there yet). There are a number of symbolic links. Some begin with an K,
  46. the others begin with an S, and all of them have three numbers following
  47. the 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 scripts
  49. are run, from 000 to 999; the lower the number the sooner it gets
  50. executed. When init switches to another runlevel, the appropriate
  51. services get killed and others get started.
  52. </para>
  53. <para>
  54. The real scripts are in /etc/init.d. They do all the work, and the
  55. symlinks all point to them. You'll note that killing links and starting
  56. links point to the same script in /etc/init.d. That's because the scripts
  57. can be called with different parameters like start, stop, restart, reload,
  58. status. When a K link is encountered, the appropriate script is run with
  59. the stop argument. When a S link is encountered, the appropriate script
  60. is run with the start argument.
  61. </para>
  62. <para>
  63. These are descriptions of what the arguments make the scripts do:
  64. </para>
  65. <itemizedlist>
  66. <listitem><para>
  67. <emphasis>start</emphasis>: The service is started.
  68. </para></listitem>
  69. <listitem><para>
  70. <emphasis>stop</emphasis>: The service is stopped.
  71. </para></listitem>
  72. <listitem><para>
  73. <emphasis>restart</emphasis>: The service is stopped and then started again.
  74. </para></listitem>
  75. <listitem><para>
  76. <emphasis>reload</emphasis>: The configuration of the service is updated.
  77. Use this after you have modified the configuration file of a service, when
  78. you don't need/want to restart the service.
  79. </para></listitem>
  80. <listitem><para>
  81. <emphasis>status</emphasis>: Tells you if the service is running and with
  82. which PID's.
  83. </para></listitem>
  84. </itemizedlist>
  85. <para>
  86. Feel free to modify the way the boot process works (after all it's your
  87. LFS system, not ours). The files here are just an example of how you
  88. can do it in a nice way (well what we consider nice anyway. You may
  89. hate it).
  90. </para>
  91. </sect1>