These classnotes are depreciated. As of 2005, I no longer teach the classes. Notes will remain online for legacy purposes

UNIX02/The Init Process

Classnotes | UNIX02 | RecentChanges | Preferences

No diff available--this is the first major revision. (no other diffs)

init comes first

init is one of those programs that are absolutely essential to the operation of a Linux system, but that you still can mostly ignore. A good Linux distribution will come with a configuration for init that will work for most systems, and on these systems there is nothing you need to do about init. Usually, you only need to worry about init if you hook up serial terminals, dial-in (not dial-out) modems, add new services, or if you want to change the default run level.

When the kernel has started itself (has been loaded into memory, has started running, and has initialised all device drivers and data structures and such), it finishes its own part of the boot process by starting a user level program, init. Thus, init is always the first process (its process number is always 1).

The kernel looks for init in a few locations that have been historically used for it, but the proper location for it (on a Linux system) is /sbin/init. If the kernel can't find init, it tries to run /bin/sh, and if that also fails, the startup of the system fails.

When init starts, it finishes the boot process by doing a number of administrative tasks, such as checking filesystems, cleaning up /tmp, starting various services, and starting a getty for each terminal and virtual console where users should be able to log in.

init starts system services

When init runs, it follows the /etc/inittab configuration file. On our systems, this file should look like this:
 # Default runlevel. The runlevels used by RHS are:
 #   0 - halt (Do NOT set initdefault to this)
 #   1 - Single user mode
 #   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
 #   3 - Full multiuser mode
 #   4 - unused
 #   5 - X11
 #   6 - reboot (Do NOT set initdefault to this)

 # System initialization.

 0:0:wait:/etc/rc.d/rc 0
 1:1:wait:/etc/rc.d/rc 1
 2:2:wait:/etc/rc.d/rc 2
 3:3:wait:/etc/rc.d/rc 3
 4:4:wait:/etc/rc.d/rc 4
 5:5:wait:/etc/rc.d/rc 5
 6:6:wait:/etc/rc.d/rc 6
 # Things to run in every runlevel.

 ca::ctrlaltdel:/sbin/shutdown -t3 -r now

 # When our UPS tells us power has failed, assume we have a few minutes
 # of power left.  Schedule a shutdown for 2 minutes from now.
 # This does, of course, assume you have powerd installed and your
 # UPS connected and working correctly.
 pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"

 # If power was restored before the shutdown kicked in, cancel it.
 pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"

 # Run gettys in standard runlevels
 l1:2345:respawn:/sbin/mingetty tty1
 l2:2345:respawn:/sbin/mingetty tty2
 l3:2345:respawn:/sbin/mingetty tty3
 l4:2345:respawn:/sbin/mingetty tty4
 l5:2345:respawn:/sbin/mingetty tty5
 l6:2345:respawn:/sbin/mingetty tty6

 # Run xdm in runlevel 5
 # xdm is now a separate service
 x:5:respawn:/etc/X11/prefdm -nodaemon

But what is 'mingetty'? Well, 'mingetty' is a replacement for 'getty' which is a classic UNIX service. From the getty man page:

It is the second process in the series, (init-getty-login-shell) that ultimately connects a user with the UNIX system. It can only be executed by the super-user; that is, a process with the user-ID of root. Initially getty prints the contents of /etc/issue (if it exists).

From this file, we see that init runs scripts located in /etc/rc#.d (where # is based upon the run-level). Looking into the rc3.d directory, we see links to initialization scripts locatted in /etc/rc.d/init.d. These links dictate which services run, and in what order during boot. These files in this directory structure is what is commonly refered to as System V (see this )

  • Your initialization scripts are not gauranteed to be in /etc/rc.d/init.d! On some Linux distributions and on some other UNIXes these may be elsewhere in the /etc directory tree. For example, Debian has them in /etc/inid.d.

To add new services to the boot up process, on many UNIX systems you will have to go in and add symbolic links in the proper directories by hand. However, under Red Hat (and many other Linux's), we have a command called chkconfig. chkconfig's usage is as follows:

       chkconfig --list [name]
       chkconfig --add name
       chkconfig --del name
       chkconfig [--level levels] name <on|off|reset>
       chkconfig [--level levels] name

To add a new services which is listed in /etc/rc.d/init.d to the multiuser runlevel, all we must to is use 'chkconfig --add'. For example, if the service we were running was called 'foonly', we would issue the following command:

 # chkconfig --add foonly

If we wanted foonly to run during runlevels 3-5, we would issue:

 # chkconfig --level 345 foonly on

Classnotes | UNIX02 | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited April 26, 2003 3:01 am (diff)
(C) Copyright 2003 Samuel Hart
Creative Commons License
This work is licensed under a Creative Commons License.