< Day Day Up > |
Run Levels and /etc/inittabThe scripts just covered are run when there is a change in the run level of the system. Different run levels exist because you may want to perform different tasks at different times. You may, for instance, want to repair a disk, which means you'll want to be in a lower run state. In normal operation, you may want to be in a higher run state. /etc/inittab defines the default run level of your system. The following listing shows /etc/inittab: # # inittab This file describes how the INIT process should set up # the system in a certain run-level. # # Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org> # Modified for RHS Linux by Marc Ewing and Donnie Barnes # # 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) # id:5:initdefault: # System initialization. si::sysinit:/etc/rc.d/rc.sysinit l0:0:wait:/etc/rc.d/rc 0 l1:1:wait:/etc/rc.d/rc 1 l2:2:wait:/etc/rc.d/rc 2 l3:3:wait:/etc/rc.d/rc 3 l4:4:wait:/etc/rc.d/rc 4 l5:5:wait:/etc/rc.d/rc 5 l6:6:wait:/etc/rc.d/rc 6 # Things to run in every runlevel. ud::once:/sbin/update # 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 1:2345:respawn:/sbin/mingetty tty1 2:2345:respawn:/sbin/mingetty tty2 3:2345:respawn:/sbin/mingetty tty3 4:2345:respawn:/sbin/mingetty tty4 5:2345:respawn:/sbin/mingetty tty5 6:2345:respawn:/sbin/mingetty tty6 #console definition c0:2345:respawn:/sbin/agetty ttys0 9600 vt100 # Run xdm in runlevel 5 # xdm is now a separate service x:5:respawn:/etc/X11/prefdm -nodaemon You can see early in this listing, right after the comments, that you are in run level 5 by default. If you are booting your system to run level 5, /etc/rc.d/rc will run the startup scripts present in /sbin/rc1.d through /sbin/rc5.d. I have mentioned run levels several times in this discussion. Both the startup and shutdown scripts described here, as well as the /etc/inittab file, depend on run levels. The run level descriptions are present in the /etc/inittab listing and are summarized here:
/etc/inittab is also used to define a variety of processes that will be run, and it is used by /sbin/init. The /sbin/init process ID is 1. It is the first process started on your system and it has no parent. After the kernel has been loaded into memory and initialized device drivers, data structures, and other work, it starts init. init performs many administrative tasks, such as checking file systems, and then looks at /etc/inittab to determine the run level of the system. Entries in the /etc/inittab file have the following format:
To start a getty, which is a process run on each terminal so that users can login, at run levels 2-5, you would include the following line in /etc/inittab:
This is in the /etc/inittab file, as opposed to being defined as a startup script, because the console may be killed and have to be restarted whenever it dies, even if no change has occurred in run level. respawn starts a process if it does not exist and restarts the process after it dies. This entry shows several run states, since you want the console to be activated at all times. Another example is the first line from /etc/inittab: id:5:initdefault: The default run level of the system is defined as 5. The system startup and shutdown basics described here are important. You will be starting up and shutting down your system and possibly modifying some of the files described here. Because of their importance, it is important that you take a close look at the startup and shutdown files before you begin to modify them. If you do need to modify them, I recommend making a backup of any file before you edit it. Now, look at the commands you can issue to shut down your system. |
< Day Day Up > |