Before you can use your computer, you must start up the operating system. Starting the operating system is referred to as booting. When the system has been booted, the devices, applications, and services on your computer are available to be used.
Because UNIX is a powerful multitasking and multiuser operating system, many processes are set in motion when you start it up. First, UNIX runs system initialization processes to do things such as set the system clock from hardware, configure devices,
and build a new UNIX kernel (if necessary). Then the system begins running processes associated with the particular initialization state (or init state) assigned to your system.
When the UnixWare version of the UNIX system is delivered, the default run state for your system is state 3. This state makes your UNIX system available for multiuser use in a networked environment (including file sharing). What this means is that all
file systems are connected (mounted) on your system, daemon processes are started to let users log in, and processes to handle incoming and outgoing networking traffic are started.
You can achieve different levels of activity and access to your system by setting it to boot to other states or by changing system states while your system is running. These states range from the full network/multiuser state (state 3) to
single-user/limited access states (states 1 and 2).
This chapter describes the processing that occurs when you start up and shut down your UNIX system. It also describes how you can change your system to different system states while it is running. Examples in this chapter are based on the UnixWare
version of UNIX, as implemented on an IBM PC or compatible (that is, Intel 386 technology).
When you turn on a computer that has the UNIX system installed, starting up UNIX is managed by a process called init. The init process sets many processes in motion, based on the initialization state defined in the /etc/inittab file.
This section describes what happens when you start up the UnixWare 1.1 version of the UNIX system on your personal computer, as it is delivered from Novell, Inc.
The init process starts up and checks the /etc/inittab file. The first thing init does is run processes that are marked in the inittab file as sysinit processes. sysinit processes are those that make sure the system is set up properly.
init finds the following sysinit lines in the /etc/inittab file:
cr::sysinit:/sbin/ckroot >/dev/sysmsg 2>&1 ck::sysinit:/sbin/setclk >/dev/sysmsg 2>&1 mm::sysinit:/etc/conf/bin/idmodreg >/dev/sysmsg 2>&1 ldmd::sysinit:/etc/conf/bin/idmodload >/dev/sysmsg 2>&1 ap::sysinit:/sbin/autopush f /etc/ap/chan.ap bchk::sysinit:/sbin/bcheckrc </dev/console >/dev/sysmsg 2>&1 bu::sysinit:/etc/conf/bin/idrebuild reboot </dev/console >/dev/sysmsg 2>&1 ia::sysinit:/sbin/creatiadb </dev/console >/dev/sysmsg 2>&1
Here's a quick rundown of what the system initialization (sysinit) processes do when you start the system:
Once system initialization functions are set up, init checks the initdefault entry in the inittab to determine the run level that the system is supposed to start up in. It finds the following initdefault line:
is:3:initdefault:
This tells init to start up UNIX in run level, or system state, 3. System state 3 is defined as the remote file-sharing state. With that information stored away, init proceeds to run all commands set in the /etc/inittab file that are designated as
belonging to run state 3. Here is a list:
r2:23:wait:/sbin/rc2 1> /dev/sysmsg 2>&1 </dev/console r3:3:wait:/sbin/rc3 1> /dev/sysmsg 2>&1 </dev/console li:23:wait:/usr/bin/ln /dev/systty /dev/syscon >/dev/null 2>&1\ [cc]sc:234:respawn:/usr/lib/saf/sac t 300 co:12345:respawn:/usr/lib/saf/ttymon g v p "Console Login: " \ [cc]d /dev/console l console d2:23:wait:/sbin/dinit 1> /dev/sysmsg 2>&1 </dev/console co:12345:once:/usr/bin/mapchan f /usr/lib/mapchan/88591.dk \ [cc]console
The r2 and r3 lines set the most processes in action. The r2 line runs the /etc/rc2 command, which in turn starts up all scripts contained in the /etc/rc2.d directory that begin with the letter S. These include the following:
S01MOUNTFSYS S02mse S18setuname S50merge S75rpc S01tzsetclk S05RMTMPFILES S21perf S55merge S02PRESERVE S11uname S27nuc S69inet S15mkdtab S42els S73snmp
You can list these files to see what they do. On the whole, however, the scripts start networking and other addon features. For example, S27nuc starts NetWare connectivity, S69inet starts TCP/IP, and S50merge starts DOS merge features.
The processes specific to state 3, file-sharing state, are started by the /etc/rc3 command. This command runs all scripts in the /etc/rc3.d directory that begin with the letter S. The file-sharing state was originally created to start the remote file
sharing (RFS) application. RFS has since been overshadowed by its more popular counterpart network file system (NFS). So the /etc/rc3.d directory is usually empty unless you have purchased the NFS addon software.
When the system is operational, you will see the login screen or a console login prompt:
Console Login:
To get an idea of what's happening on a running UNIX system, the following list describes some of the processes that are running. (You can list the active processes by typing ps ef from the shell.)
If you have logged and started up the graphical interface, you will see other processes as well. For example, the X process is the X windowing system server, and Desktop Manager (dtm) manages the windows and icons on your desktop.
If you are running UNIX on a PC, it is possible to have several different operating systems installed on different partitions of your hard disk.
When you install UnixWare, you are allowed to create several partitions and are asked which partitions you want to use for UnixWare and which you want to use for other operating systems. Other operating systems can be DOS, OS/2, or NT. Once you have
partitioned the disk and installed the operating systems, you can manage which system you boot from (that is, which is the active partition) with the fdisk utility.
Versions of the fdisk command are available in DOS, UNIX, and other operating systems. To run fdisk, open a shell, type su (followed by the root password, when requested), and type /usr/sbin/fdisk. You'll see the following:
Total disk size is 683 cylinders (202.8 MB) Cylinders Approx Partition Status Type Start End Length % MB\ [ic:cc]========= ====== =========== ===== === ====== === ====== 1 pre5.0DOS 0 101 102 15 30.3 2 Active UNIX System 103 681 579 85 171.9 SELECT ONE OF THE FOLLOWING: 0. Overwrite system master boot code 1. Create a partition 2. Change Active (Boot from) partition 3. Delete a partition 4. Update (Update disk configuration and exit) 5. Exit (Exit without updating disk configuration) Enter Selection:
This example shows the partitions for two operating systems (DOS and UnixWare) on a 202.8 MB hard disk. UNIX is the active operating system and consumes 85 percent of the hard disk (171.9 MB). DOS is on the first partition, consuming 15 percent, or 30.3
MB, of the hard disk.
To change the active partition from UNIX to DOS in the example, enter 2, then 1, then 4. The next time you reboot your system, DOS will start.
The early UNIX systems ran on minicomputers and mainframes. The concept of system states grew from the need to have different levels of activity occurring on the system, depending on whether the system was in full use, undergoing system maintenance, or
transitioning between those states.
An administrator could start up a large computing system in single-user mode, with no networking running or terminals logged in (other than the console terminal). In this way, the administrator could debug any problems with the system before being
bombarded with requests from the outside world.
Over the years, some system states have become outdated. If you're the only UNIX user on a PC, you will rarely need to use any system states other than those that bring the system up and bring it down.
The following list describes the UNIX system states:
Other initialization states include the following:
You can set initdefault to run levels 1, s, S, 2, or 3. You will almost always set the run level to level 2 or 3 on a small system. Other states are states that you change to on a running system. To change system states, you can use the init command.
The /etc/inittab file contains the processes that are started when init brings up the system or changes to another state. Some of the entries in inittab are daemons (processes that run continuously in the background) and others, such as the /etc/rc2
entry, are used to start up other processes for particular run states.
Each entry in the inittab file consists of the following fouritem, colonseparated field:
idtag:runstate:action:process
The idtag is any tag (from one to four characters) that identifies the entry. The runstate is the system state in which this entry should be run. You can have several system states assigned to an entry.
The action is a keyword that corresponds to one of the following: respawn (if the process goes away, start it again), wait (wait for the process to finish before continuing to the next process), once (run the process once, wait for it to finish,
then don't start it again), boot (run the process the first time you go into a multiuser state, without waiting for it to finish), bootwait (run the process the first time you go into a multiuser state, waiting for it to finish before proceeding), and
sysinit (run the process when the system first comes up). There is one initdefault action in the inittab file to indicate the state that the system starts in.
The process is the command that is actually run when the criteria in the first two fields are met (that is, the correct runstate and action).
The following is an example of an inittab entry:
co:12345:respawn:ttymon g v p "Console Login: " d \ [cc]/dev/console l console
Here the entry is tagged co. The entry is run in system states 1, 2, 3, 4, and 5. If the process dies, it is started again (respawn). The actual process runs in the ttymon command (terminal monitor), which gives you the ability to log in from the system
console.
Applications that have daemon processes (that is, processes that must run continuously for the application to process properly), or that require that something be initialized when the system starts, often have scripts in a run state directory to do
these functions. There are different directories for each of the run states you could change to.
The following is a list of the run state directories:
A startup script is a command that is run when you start the system, shut down the system, or change to a different run state. If you list a startup script, using cat or pg, you will see that it is a series of shell commands that are run when the script
is executed with either a start or stop option.
When an application adds a startup script to UNIX, it adds that script to the /etc/init.d directory. It then links that script to one or more directories to filenames that begin with either the letter S (for start) or the letter K (for kill).
Startup scripts are run when you go into a new run state. When you enter a run state relating to one of the directories described in the section "Run State Directories," the rc? command runs all startup scripts in that directory that
begin with the letters S and K. It runs the S scripts with the start option and K scripts with the stop option, in the ASCII order.
Now that you are completely confused, look at the example in the next section. It steps you through how a particular startup script, for the mouse manager, is installed, started, and stopped.
When you install the UnixWare version of UNIX, a shell script for starting and stopping the process that manages your mouse on the graphical user interface is installed as the /etc/init.d/mse file. Also, this file is linked to two other files:
/etc/rc2.d/S02mse and /etc/rc0.d/K02mse.
That script contains the following:
case "$1" in 'start') /usr/lib/mousemgr & ;; 'stop') pid='/usr/bin/ps e | /usr/bin/grep mousemgr |\ [cc]/usr/bin/sed e 's/^ *//' e 's/ .*//'' if [ "${pid}" != "" ] then /usr/bin/kill ${pid} fi ;; *) echo "Usage: /etc/init.d/mse { start | stop }" ;; esac
When you boot your system, the init process checks the /etc/inittab file for entries that match the default run state (initdefault), which is usually run state 3. It finds the r2 entry, among others, which runs the /sbin/rc2 command and which checks all
scripts in the /etc/rc2.d directory. Next, it runs all files that begin with K with the stop option and all that begin with S with the start option. So, for example, the S02mse script is run as this:
S02mse start
Notice from the listing of the script that the start option causes the /usr/lib/mousemgr command to be run. From this point on, the mousemgr runs continuously until you change system states again.
When you shut down the system (that is, change to a shutdown state), init goes through the same process for state 0 as it did for state 3. This time it runs the r0 entry, which runs the /etc/rc0 command, which check scripts in the /etc/rc0.d directory.
All the scripts in this directory begin with K, to kill processes that were started in other states. The mouse script, K02mse, is run, but this time with the stop option, as follows:
K02mse stop
As you can see from the script shown above, the stop option finds the running mouse process, determines its process ID, and kills it. After all other startup processes are stopped, the system can shut down.
While your UNIX system is running, you can change the system state or the level of activity using the init or the telinit commands. If you are shutting down the system or moving to a lower state (especially one that will kick users off your system) you
can use the shutdown command.
The init command is the easiest way of changing system states. To use init, you simply type init followed by a system state letter or number (from a shell in which you have root permission). For example, the command
init 2
could be used to change your system from state 3 to state 2, effectively turning off file-sharing features. You could also change to user configurable states, such as state 4, a, b, or c. Or you can change to q or Q to simply reread the /etc/inittab
file.
The telinit command is simply a link to the init command. The telinit command was created for users who might be afraid to use a command as potentially drastic as the init command to simply reread the /etc/inittab file. So telinit was recommended for
rechecking the /etc/inittab file and running any new commands (telinit Q). In reality, however, you can use init and telinit interchangeably.
Instead of using the init or telinit commands, UnixWare offers more friendly ways to shut down your system.
There are several ways to shut down your UnixWare system: double-clicking the Shutdown icon from the graphical user interface, using shutdown from the command line, or by simply turning off your computer. The merits of each are discussed in the
following sections.
If you are using the GUI and you have ownership permissions to do system shutdown, you can stop your system using the Shutdown icon. To use the Shutdown icon, simply doubleclick on the Shutdown icon in the UnixWare Desktop window. When you see a
Shutdown confirmation window, click on Shutdown. The graphical interface closes and the system shuts down.
The shutdown command can be used instead of the init command to move to lower system states, in particular shutdown (0) and reboot (6) states. The init command can be a bit abrupt if you are working with a multiuser system. When you enter init 0, the
system simply goes down. The shutdown command lets you warn users and give them a grace period to log off.
The following is an example of the shutdown command (used as the root user from a shell):
# cd / # shutdown y g60 i0
The y option lets you skip the shutdown confirmation question. The g60 assigns a 60 second grace period to users in which they can log off before the system comes down. The i0 assigns the init state to state 0 (shutdown state).
Once you run the command, all users logged in to the system are warned about the impending system shutdown. They have the length of the grace period to close whatever work they are doing before the system comes down.
Because UnixWare uses a hardened file system, vfxs from Veritas, you can turn off your computer without losing data. As a rule, however, it is safer to do an orderly shutdown with either the shutdown command or the Shutdown icon.
Those who have used UNIX systems for years often feel uncomfortable simply turning off their computers with UNIX running. In the old days, the next time you booted your UNIX system after turning it off you would have to wait for a massive file system
check to take place. This would often take a half hour or more, occasionally resulting in some data loss.
Even though this author has never lost any data when turning off UnixWare, it does take a little longer the next time the system is booted. On the whole, it is best to close your applications and do an orderly shutdown.
Here are a few tips relating to starting and shutting down your system:
When you start up UNIX, a complex set of processes is run. These processes initialize the system, connect system resources, and allow access by multiple users and networks.
As a UNIX system administrator, you can change the state of your system to do administrative tasks or to limit access to the system. You can also modify the processes that are run when you change system states.
When you are done using your UNIX system for the moment, UNIX can be shut down in several ways. With the latest releases of UNIX, an orderly shutdown (with the shutdown or init commands) is no longer necessary. Hardened file systems let you just turn
off your computer with little risk of losing data.