Starting a UNIX The major events that take place when a UNIX machine is starting are: * Hardware POST * Kernel is loaded (perhaps through a bootloader) * Hardware discovery/configuration * Core system processes spawned and if the machine is starting into full user mode: * Filesystems are checked * System startup scripts are run * Daemons for multiuser operation are started Most of the first part of these are out of our control. Occasionally, we will need to recompile a kernel to give added hardware support (new networking card, etc). The second 3 are more flexible and under our control. After the core system processes are spawned, the kernel mounts the root filesystem read-only. If it fails, you are in trouble and need to boot off of the CDROM or a floppy (on older systems you may need to boot off of tape, or a spare hard drive) to repair the root filesystem. The tool fsck(8) is used to repair and check filesystems. If it can't repair the filesystem, you are in trouble and will probably need to build a new one. The tool mkfs(8) is used to make a new filesystem. It takes a block special device as the file to build the filesystem on. In class, we will look at how to build a filesystem on a floppy drive. The procedure is the same for building one on a hard drive. mkfs clears out the contents of whatever was there before --- it will destroy data. After the root filesystem has been mounted read-only, init(8) takes over and governs the rest of the startup procedure. init can be directed by arguments to the kernel at kernel loading time. The configuration file for init is /etc/inittab. The format is described by inittab(5). In general, init's operation is divided into "run levels". A run level is an arbitrary grouping of tasks to be performed (starting a web server, etc). When entering a runlevel, init will do the following (runlevel=runlevel to enter [typically one of 0-6 or S]): for file in /etc/rc$runlevel.d/K??* do sh $file stop done for file in /etc/rc$runlevel.d/S??* do sh $file start done On our systems, init goes into run level "S" when the system is booting, then goes to the run level described by the variable "initdefault" in /etc/inittab (here it is 2). Each of the files in /etc/rc?.d are typically links (hard links on Solaris, but symlinks almost everywhere else) to files in /etc/init.d/. They are each a shell script with the following format: case "$1" in start) # things to do to start ;; stop) # things to do to stop ;; esac