Notes for Week 5

  1. The startup process on our distribution of linux uses "sysvinit". It has been modified to permit operation from DVD-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 DVD-ROM) and /var;
    • start udev to handle dynamic device file allocation and deallocation;
    • 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 DVD-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:

    • initialize logging and the random number generator (the only things done in runlevel 1);
    • bring up the firewall and external network interfaces (ie., eth0);
    • start ntpd, sshd (the secure shell daemon), 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 DVD-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 DVD-ROM, our distribution interactively prompted you to configure the following files (from /etc/rc.d/init.d/configure):

    • /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 are:
      HOSTNAME=(your host's full domain name)
      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/ipv4 - information particular to your network interface card; each NIC has its own directory (ifconfig.eth1, ifconfig.eth2, etc.).
      Note that systems with two or more NICs can behave oddly. Depending on timing considerations (which are not always consistent) and whether you have booted cold or warm (from power off or via a reboot command), the identity of your NICs may change! For instance, what was eth0 on a cold boot may become eth1 on a reboot, and vise versa. If this becomes a problem, it can be controlled by building the drivers as modules (see week 10) and loading them in a specific order at startup time.
      Minimal contents of the ipv4 file are:
      SERVICE=ipv4-static
      IP=(the IP address for eth0)
      PREFIX=(the number of bits in the network portion of the IP address for eth0)
      GATEWAY=(your gateway's IP address)
      BROADCAST=(the broadcast address for eth0)
      ONBOOT=yes
      This is a good place to remind you that Unix is case-sensitive!
    • /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. In addition, during week 1 you created and/or modified a number of other configuration files:

    • /etc/X11/xorg.conf
    • GNUstep/Defaults/WMState (and possibly WMRootMenu, if you modified the Xterm menu item using wprefs, WMWindowAttributes, if you modified the xclock window behavior, and WindowMaker, if you modified other global settings using wprefs)
    • .xinitrc (modified by krkfixwm)
    • .endeavour2/endeavour2.ini (if you set it up to use emacs instead of vi)
    • .mozilla/default/xxx/bookmarks.html (if you added any bookmarks, and prefs.js if you modified any Preferences)
  7. In week 2 you modified /etc/fstab. Note that the option "user" on the /media/usbstg line indicates that an ordinary user (not root) can mount disks on the device (see mount options in the man page).

    A common technique is to use symbolic links for devices for increased flexibility. For instance, you could link /dev/flash to /dev/sdb1 with "ln -s /dev/sdb1 /dev/flash" and change the /media/usbstg line's device entry from /dev/sdb1 to /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 (or in any scripts); simply delete the old /dev/flash link and make a new one as appropriate. Other common links are /dev/cdrom and /dev/dvd.

  8. In week 2 you also modified /boot/grub/menu.lst on /dev/sda5.
  9. Other configuration files which were set up during the design of the DVD-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/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.
  10. Most configuration files must end with a newline character, so that the last line of the configuration is recognized as complete. Shell scripts also benefit from an ending newline.

  11. 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 ntpd 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.


©2007, 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.