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.
# Things to run in every runlevel.
# Trap CTRL-ALT-DELETE
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
# Run xdm in runlevel 5
# xdm is now a separate service
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 http://docs.kde.org/en/3.1/kdeadmin/ksysv/what-is-sysv-init.html )
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: