RHEL: Linux Start Up

Posted on April 28, 2009


It is just like Windows, Linux has configuration that controls programs, which are executed during boot. But before going into the start up component, it is good to know that Linux has runlevel, the main configuration controlling how the Linux boots. The runlevel is defined in the `inittab` file:

[root@xxxxxxx /]# ls
bin   dev  home  lost+found  misc  net  proc  sbin     srv        storage10  sys       tmp  var
boot  etc  lib   media       mnt   opt  root  selinux  storage00  storage11  tftpboot  usr
[root@xxxxxxx /]# cd etc
[root@xxxxxxx etc]# pwd
[root@xxxxxxx etc]# ls -l | grep inittab
-rw-r--r--  1 root root    1716 Jan 13 17:11 inittab

The runlevel is just a portion of the `inittab` file. In this example, the initdefault is set into runlevel 5.

# 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)

Notice that each runlevel has its own corresponding start up programs that are defined in `rc` directory, for instance: the rc3.d is meant for the runlevel 3.

[root@xxxxxxx etc]# pwd
[root@xxxxxxx etc]# ls -l | grep rc
lrwxrwxrwx  1 root root      11 Jan 13 16:50 init.d -> rc.d/init.d
lrwxrwxrwx  1 root root       7 Jan 13 16:52 rc -> rc.d/rc
lrwxrwxrwx  1 root root      10 Jan 13 16:52 rc0.d -> rc.d/rc0.d
lrwxrwxrwx  1 root root      10 Jan 13 16:52 rc1.d -> rc.d/rc1.d
lrwxrwxrwx  1 root root      10 Jan 13 16:52 rc2.d -> rc.d/rc2.d
lrwxrwxrwx  1 root root      10 Jan 13 16:52 rc3.d -> rc.d/rc3.d
lrwxrwxrwx  1 root root      10 Jan 13 16:52 rc4.d -> rc.d/rc4.d
lrwxrwxrwx  1 root root      10 Jan 13 16:52 rc5.d -> rc.d/rc5.d
lrwxrwxrwx  1 root root      10 Jan 13 16:52 rc6.d -> rc.d/rc6.d
drwxr-xr-x 10 root root    4096 Apr 28 14:14 rc.d
lrwxrwxrwx  1 root root      13 Jan 13 16:52 rc.local -> rc.d/rc.local
lrwxrwxrwx  1 root root      15 Jan 13 16:52 rc.sysinit -> rc.d/rc.sysinit

The `init.d` directory contains all executables that are used to start up programs. These executables usually share the same format to allow Linux start and kill (or stop) the program. The following example is the apache httpd executable.

[root@xxxxxxx init.d]# pwd
[root@xxxxxxx init.d]# ./httpd
Usage: httpd {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}
[root@xxxxxxx init.d]#

The question is how Linux knows which start up programs it has to activate during boot. The answer is in the `rcx.d` directory. This directory contains the `Sx` and `Kx` links into executables in the `init.d` directory. For example the rc3.d (for runlevel 3) instruct Linux to run S55sshd (SSH daemon) during booting up and kill K15httpd (Apache HTTP daemon) during shutdown.

[root@xxxxxxx rc3.d]# pwd
[root@xxxxxxx rc3.d]# ls
K01dnsmasq         K15httpd       K69rpcsvcgssd      K89dund             S06cpuspeed     S13irqbalance      S25netfs   S80sendmail        S98avahi-daemon
K02avahi-dnsconfd  K20nfs         K73ypbind          K89netplugd         S08ip6tables    S13portmap         S25pcscd   S85gpm             S98haldaemon
K02NetworkManager  K24irda        K74ipmi            K89pand             S08iptables     S13setroubleshoot  S26hidd    S90crond           S99firstboot
K05conman          K25squid       K74nscd            K89rdisc            S08mcstrans     S14nfslock         S28autofs  S90xfs             S99local
K05saslauthd       K35vncserver   K74ntpd            K91capi             S09isdn         S15mdmonitor       S44acpid   S95anacron         S99smartd
K05wdaemon         K35winbind     K80kdump           K99readahead_later  S10network      S18rpcidmapd       S50hplip   S95atd
K10dc_server       K36mysqld      K85mdmpd           S02lvm2-monitor     S11auditd       S19rpcgssd         S55sshd    S95salinfo_decode
K10psacct          K50netconsole  K87multipathd      S04readahead_early  S12restorecond  S22messagebus      S56cups    S97rhnsd
K12dc_client       K50tux         K88wpa_supplicant  S05kudzu            S12syslog       S25bluetooth       S56xinetd  S97yum-updatesd

In conclusion, Linux is very well design to classify its boot into different runlevels. To automatically start up a program during Linux boot, one requires to keep the executable in the `init.d` folder and include a link into the executable in the respective runlevel.

Posted in: Technology