Notes for Week 5

  1. The startup process on our distribution of linux uses "sysvinit". It has been modified to permit operation from CD-ROM, as well as to log all console output. In sysvinit, the "runlevel" defines which daemons and services are operating on the system at any point in time. A default runlevel is specified in /etc/inittab, and runlevels may be switched using the telinit command.

    There are seven runlevels numbered 0 through 6, five of which have fairly well-defined uses:

    • runlevel 0, for shutdown
    • runlevel 1, for single user mode (typically used for repair or backup)
    • runlevel 3, the default
    • runlevel 5, often used to run X for a graphical login interface
    • runlevel 6, for rebooting

    On our system, runlevels 3 through 5 are identical and runlevel 2 does not include networking or gpm.

    The services which are run for each runlevel are specified in directories /etc/rc.d/rc#.d/, where "#" is the runlevel. The "files" in the runlevel directory are symbolic links to scripts in /etc/rc.d/init.d. The names are of the form "Snndaemon" or "Knndaemon", where S means start this daemon in this runlevel, and K means kill this daemon before starting this runlevel, and nn is a number used to order the kills and starts. When a runlevel is started, the kill scripts are run in alphabetical order, and then the start scripts are run, also in alphabetical order.

    When booting, init first runs the scripts in /etc/rc.d/rcsysinit.d. For our system, these:

    • mount /proc, the RAM disks (if booting from the CD-ROM) and /var;
    • start syslogd and klogd;
    • activate the swap partition(s) listed in /etc/fstab;
    • run e2fsck as necessary;
    • mount any remaining filesystems as specified by fstab;
    • set the system clock from the hardware clock;
    • perform interactive configuration if booting from the CD-ROM (or if certain configuration files do not exist);
    • bring up the loopback interface (an internal network interface with IP address 127.0.0.1, used for many purposes in the kernel).

    init then runs the scripts for the specific runlevel as described above. For instance, in runlevel 3, they:

    • bring up external network interfaces (ie., eth0);
    • initialize the random number generator (the only thing done in runlevel 1);
    • start ntpd, sshd, fcron, gpm and lpr.

    The above init strategy makes it particularly easy to restart services: one simply re-runs the script. For example, to change the IP address, the system administrator need only modify the correct configuration files and run "/etc/rc.d/init.d/network restart". Rebooting should never be necessary, except if a different kernel needs to be run, an extremely rare kernel panic occurs, or a power failure occurs.

  2. inittab is usually not modified except to change the default runlevel or to specify how "Ctrl-Alt-Del" is processed, what happens when power failure and power restored signals are received from a UPS (Uninterruptible Power Supply) and how many virtual consoles are started.
  3. At shutdown, the daemons are stopped in essentially the reverse order in which they were started. After the external network interfaces are brought down, signals are sent to all remaining processes: first the TERM signal, then the KILL signal. Swap partitions are deactivated, filesystems are unmounted (except /var if you are running from CD-ROM, so that it can be saved before rebooting). Finally, the loopback interface is brought down and the system rebooted or shutdown, depending on the runlevel.
  4. There is a great deal of variation in startup between various linux distributions, not to mention other UNIX flavors. This is natural, since the character of a running system is largely dictated by what happens at boot time: modifying the startup scripts is an important way for the distribution designer, as well as the system administrator, to control the behavior of the system.

    System administrators often put all of their local modifications in a single script, which is usually run just before init starts the agetty processes. To do this, one could create the script /etc/rc.d/init.d/local and then link it to the appropriate run level directories using, for instance, "ln -s /etc/rc.d/init.d/local /etc/rc.d/rc3.d/S99local". If you really want lpr to be started before the local script, simply rename its link to S98lprng using the mv command.

  5. UNIX uses a number of text files for system configuration purposes, almost all of which reside in /etc (or a subdirectory thereof).
    Windows uses the "registry" to hold configuration information, but it is nearly impossible to modify it in a "safe" way other than through control panels which do much to hide the workings of the system from the curious. Registry failure is generally a catastrophic event, while text file failure only affects the particular file involved.

    When booting from the CD-ROM, our system interactively configured the following files:

    • /etc/hosts - a list of IP addresses and host names which your computer knows about; this is a static set of bindings which will not require DNS (Domain Name Service) lookups when accessed; your host's name and IP address should be in here; you can also add aliases for host names here; minimal contents are:
      (your host's IP address) (your host's full domain name) (your host's alias)
      127.0.0.1 localhost
    • /etc/resolv.conf - a list of the DNS Servers for your domain (these translate Internet names into IP addresses); minimal contents are:
      nameserver (your DNS server's IP address)
    • /etc/sysconfig/network - global information about networking on your computer; minimal contents (for a PC with a single ethernet interface) are:
      HOSTNAME=(your host's full domain name)
      GATEWAY=(your gateway's IP address)
      GATEWAY_IF=eth0
      Notice that the contents of this file (as well as the one following and many other configuration files in a UNIX environment) resemble shell commands used to set environment variables; that is exactly what they are (they are included in startup scripts at run time);
    • /etc/sysconfig/network-devices/ifconfig.eth0 - information particular to your network interface card; each NIC has its own file (ifconfig.eth1, ifconfig.eth2, etc.); minimal contents are:
      SERVICE=static
      IP=(the IP address for eth0)
      NETMASK=(the network mask for eth0)
      BROADCAST=(the broadcast address for eth0)
      ONBOOT=yes
    • /etc/printcap - this file contains spool directories and printer parameters for printers controlled by lpd; its configuration can be somewhat tricky, and we will learn more about it in week 7.
  6. /etc/fstab was created by the install2hd script, and you have already added an entry to it for the swap partition; an additional useful entry might be:
    /dev/flash/media/flashvfatnoauto,user00
    The option "user" indicates that an ordinary user (not root) can mount disks on the device (see mount options). In order to make use of this, you will want to create the directory /media/flash, and link /dev/flash to /dev/sdb1 with "ln -s /dev/sdb1 /dev/flash". By using a symbolic link in fstab instead of a specific device, changes in hardware configuration will not require another change in fstab; simply delete the old /dev/flash link and make a new one as appropriate.
    If you routinely use more than one flash drive, you may want to handle this a little differently. The best approach is to run udev, which dynamically creates and destroys device files as needed. Since we aren't running udev in the lab yet, another approach is to make a series of fstab entries, mount points and links as above, linking /dev/flash2 to /dev/sdc1, etc.
  7. Other configuration files which were set up during the design of the CD-ROM:

    • /etc/bashrc - system-wide default bash initialization file; an alias for su and a custom command prompt were added;
    • /etc/issue - banner displayed by agetty;
    • /etc/login.defs - configuration for the login package; changes were made for logging, mail, /etc/issue and default PATH;
    • /etc/man.conf - controls how man finds man pages; a path for Java man pages was added, and some paths were modified;
    • /etc/profile - system-wide bash profile configuration; some unnecessary functions were removed;
    • /etc/syslog.conf - used to control logging and provides for a great deal of flexibility; one interesting use is to maintain a duplicate log on another system for greater fault tolerance and security;
    • /etc/profile.d/X.sh - some path changes were made to accomodate Xorg;
    • /etc/profile.d/extrapaths.sh - path specification was simplified;
    • /etc/X11/xinit/xinitrc - simplified to start WindowMaker.
    In addition, the xconfig script you ran in week 1 created /etc/X11/xorg.conf.

  8. EXERCISES for Week 5:

    1. Use telinit to change to single user mode. Examine your path, the working directory and the processes currently running.
    2. Change the startup order in runlevel 4 for fcron and sshd. telinit to runlevel 4.
    3. Create a local startup script as described above, and use it to display a welcome banner (in plain text, of course). Test it by teliniting to runlevel 3.
    4. Make the change suggested above to fstab. Use "mount /media/flash" to test it.


©2005, Kenneth R. Koehler. All Rights Reserved. This document may be freely reproduced provided that this copyright notice is included.

Please send comments or suggestions to the author.