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