System Services - /etc/inittab
- 0
- Add a Comment
- No Related Post
System Services - /etc/inittab
We’re finishing up the first month of Penguin Shell this week. It seems like a good time to dig deep into the heart of Linux. If today’s GnomeCORE seems a bit tough, don’t despair. Read it, understand it as best you can, and save whatever you learn for later use. These are some critical items for understanding the operation of Linux, whether you’re a new user or an old-timer.
Some definitions and a quick catch-up are in order before we discuss the /etc/inittab file. On Friday, we described the init process as the mother of all Linux processes. init starts new processes and restarts some programs when they exit. init executes a number of programs and scripts when your system boots. Further, init evaluates the system’s runlevel and executes scripts and/or programs based on that evaluation. Runlevels are a way to determine the currently loaded state of your computer, with each runlevel labelled by a number. For example, runlevel 1 might be defined as executing only the most basic scripts to start your system. Runlevel 2 might include all the basics plus networking support. Runlevel 3 might be everything but X Window. You get the idea. The runlevel specifies the current system state.
/etc/inittab determines for init both the runlevels and the actions to take in the event that the system enters a runlevel. The following is a snippet from the /etc/inittab file from my newly-installed Slackware system. As in today’s GnomeTWEAK, pay attention to the comments (denoted with #). They tell you what you need to know about the code that follows.
# These are the default runlevels in Slackware:
# 0 = halt
# 1 = single user mode
# 2 = unused (but configured the same as runlevel 3)
# 3 = multiuser mode (default Slackware runlevel)
# 4 = X11 with KDM/GDM/XDM (session managers)
# 5 = unused (but configured the same as runlevel 3)
# 6 = reboot# Default runlevel. (Do not set to 0 or 6)
id:3:initdefault:# System initialization (runs when system boots).
si:S:sysinit:/etc/rc.d/rc.S# Script to run when going single user (runlevel 1).
su:1S:wait:/etc/rc.d/rc.K# Script to run when going multi user.
rc:2345:wait:/etc/rc.d/rc.M# What to do at the “Three Finger Salute”.
ca::ctrlaltdel:/sbin/shutdown -t5 -rf now# Runlevel 0 halts the system.
l0:0:wait:/etc/rc.d/rc.0# Runlevel 6 reboots the system.
l6:6:wait:/etc/rc.d/rc.6# What to do when power fails (shutdown to single user).
pf::powerfail:/sbin/shutdown -f +5 “THE POWER IS FAILING”# If power is back before shutdown, cancel the running shutdown.
pg:0123456:powerokwait:/sbin/shutdown -c “THE POWER IS BACK”# If power comes back in single user mode, return to multi user mode.
ps:S:powerokwait:/sbin/init 3# The getties in multi user mode on consoles an serial lines.
c1:1235:respawn:/sbin/agetty 38400 tty1 linux
c2:1235:respawn:/sbin/agetty 38400 tty2 linux
c3:1235:respawn:/sbin/agetty 38400 tty3 linux
c4:1235:respawn:/sbin/agetty 38400 tty4 linux
c5:1235:respawn:/sbin/agetty 38400 tty5 linux
c6:12345:respawn:/sbin/agetty 38400 tty6 linux# End of /etc/inittab
Each entry has 4 critical components. In order, they’re a unique id, the runlevel(s) at which the process is invoked, an action, and a process to execute when the runlevel is reached. Let’s take just one of these entries as an example:
# What to do at the “Three Finger Salute”.
ca::ctrlaltdel:/sbin/shutdown -t5 -rf now
In this case, ca is the id, the process can be invoked at all runlevels (blank between the colons), ctrlaltdel is the action, and /sbin/shutdown -t5 -rf now is the process that init will invoke. In other words, the “Three Finger Salute” shuts down the system. The init system gets virtually all its instruction from this file. If it’s not defined here, init won’t carry it out.
OK. Cooldown period. Breathe. Breathe. Tomorrow we’ll look at two daemon services, inetd and xinetd.
Now, don’t those newfound Linux muscles feel taut?
