2000-06-11
|
Back to the Basics: Solaris Default Processes and init.d Pt. II
last updated Monday, June 11, 2000
|
|
||
|
This article has been written to provide insight into a stock installation of
Solaris 8, and the services started by default. Out of the box, Solaris 8 by runs many
services. This article was written using Solaris 8, the latest
version available, and a Sparcstation 20. Most of this document will apply to
releases of Solaris prior to 8, and to both the Sparc and Intel architectures.
For documentation purposes, a full OEM install was done. Many topics discussed
will be familiar to seasoned administrators. However, this document will
benefit all parties involved in the administration and security aspects of
Solaris.
In the last article, we discussed which services are started by default, and
gave a ps -ef of our host Thebes. If you haven't read the first part or don't
recall, you can find it here.
At bootstrap time, init is the first process started. It's the parent process
of everything that will later run on the system. To touch lightly on this,
after init is started and it inherits its environment, it begins
running through the initialization scripts. These are what's known as the
"Run Command" scripts, or rc scripts. rc scripts are nothing more than
executable bourne shell scripts.
Solaris has a different directory for each run level. Each run level has a
number or letter attached to it, and a different set of scripts in it, such as
run level three (normal multiuser mode on a Solaris system), which keeps the
initialization scripts in /etc/rc3.d, to be executed when run level 3 is
entered.
Within these directories are scripts prefixed first with a letter (either K
or S) a number (which determines chronologically when they are started in the
sequence) and a name (which is usually a hint as to what they do, although
this isn't always true). The files in these directories are hard
links, which are linked to files in the master directory, /etc/init.d.
Below is a partial listing of what /etc/init.d looks like:
As you can see, our current working directory is /etc/init.d. In this
directory, we have a multitude of files, all of which are executable. These
files are the master rc scripts.
For documentation purposes, we'll also show a partial list of the scripts in
/etc/rc2.d. Here is the output:
Were more output displayed in each of the lists, you'd start to see matching
inodes in each output. This reasserts the fact that the scripts in each run
level directory are hard links to the master files in /etc/init.d.
rc scripts serve two purposes. The first one is execution of the process for
which they are responsible. The other is stopping the process(es) they start.
With rc scripts in each run level, a script prefixed with K denotes "Kill",
and S denotes "Start".
On the command line, these scripts can be executed and post-appended with a
start or stop, allowing command like execution or killing of the respective
processes. Here's a sample of source of one of these scripts, taken from
S71rpc (listed above). We're only going to show the sections pertinent to our
discussion:
As you can see, there's a subsection 'start'|'rpcstart', a subsection 'stop',
and one last subsection '*'. These sections contain the commands executed for
each argument specified with script.
Another thing we should mention here while on the topic of shell scripts is
choice of shell. As you can see, the scripts are being written with the
Bourne shell, however, not /bin/sh (actually, /usr/bin/sh. /bin is a symbolic
link to /usr/bin). The executable being used here is /sbin/sh. There's a
valid reason for this. We'll give some output below to show why.
This is the Bourne shell executable in /usr/bin/sh:
Here is the Bourne shell executable in /sbin:
As you can see here, one is dynamically linked, and one statically linked. The
reason for this is availability of libraries. When the system is
bootstrapping, and init is executing, the libraries in /usr/lib may not be
readily available, creating a situation where the shell can't execute. To
avoid this, a statically linked binary is available, and should be used for
all rc scripts.
While we're on the topic, it's also worth mentioning /sbin/sh as a login shell.
It's no coincidence that this is the default login shell for root. As
mentioned previously, if /usr/lib is not mounted, the shell will not execute
properly. This can be displayed by changing the default shell to /bin/sh and
booting into single user mode. However I don't recommend this unless you have
time to fix the problem. You've been warned. If you do so, it is at your own
risk. Changing the default shell (unless you've statically compiled a new
shell from source to replace it with) is a bad idea.
We'll review run levels as well, and talk about how the system initializes
different things at different run levels. The first thing to do is describe
the run levels (or init states...the difference is purely dogmatic).
Run level 0 is Open Boot Prom mode. This is the most basic operation level of
the machine. At run level 0, there is no kernel in memory, and it's safe to
shut down the system.
Run level s (or S, they're synonymous), is single user mode. This run level
does not allow remote logins of other users, and makes an attempt to mount all
the file systems for the performance of administrative upkeep. Few things
are running at this level.
Run level 1 is similar to run level s. Run level 1 is an administrative run
level, however, it also allows remote logins. Again, this administrative mode
makes an effort to mount all available file systems.
Run level 2 is the first multiuser mode. This run level by default runs the
standard UNIX services (telnetd, ftpd, smtp, etc).
Run level 3 is the default run level of a given Solaris system. This run
level, like 2, is a multiuser mode. The key difference between run level 2
and run level three is NFS. At run level three, all NFS shared resources are
available.
Run level 4 is not yet implemented, but is the third multiuser mode.
Run level 5 is a shutdown mode. This mode will take the system from its
present state, shut it down, and power off the system, respectively. A note,
this is not the same with Intel Solaris. This applies only to Solaris Systems
running on various Sparc-style platforms.
Run level 6 is the final mode. This run level takes the system from its
present state, shuts down the operating system, and reboots the system.
As the superuser on a system, any of these run levels can be reached at nearly
any given time. Execution on the command line of init (i.e. init 0, init 5,
etc) will take the system to the desired run level.
In this article, we built a solid understanding of the initialization of the
system. We talked about init, the location of the initialization scripts, and
how they're started. We also discussed the content of the startup scripts,
the shell used for them, an important detail about the root shell, and run
levels.
To further this understanding, in our next article, we'll look back at
what services are started on a stock install of Solaris 8, and examine the
scripts that make them run. From there, we'll talk about the necessity of
these services, their applications, and the shutting down the unnecessary ones.
To read Back to the Basics: Solaris Default Processes and init.d Pt. III, click here. |
