System V style init and systemd in practice

Slashdot it! Delicious Share on Facebook Tweet! Digg!

Inittab Configuration (init)

Note the inittab file is not currently used in Ubuntu and hasn't been used since Upstart was included in Ubuntu 9.10 – Karmic Koala. However, old installations and other distros still include the inittab, even those that have passed on to systemd.

Therefore, knowing about this file is still useful.For the record, the inittab file controls what happens whenever a system is rebooted or forced to change run levels.

This file has entries in the following form:


The first field, id , indicates the entry clearly and uniquely. You can list one or more runlevels in field 2 to which the entry should apply. When there are several runlevels, they must be entered in ascending order. See the excerpt in Listing 3 for the id ca .

The third field of the entry in /etc/inittab tells init how it should behave. You will find some of these applications in Table 2.

Table 2

Initttab Actions

Action Command Explanation
Specifying standard runlevel initdefault See also Listing 1.
After terminating the indicated process, the program will be restarted respawn For example, for interfaces, terminal windows.
During the runlevel change init Waits for the termination of the indicated process.
Assigning the meaning of the key combination Ctrl+Alt+Del ctrlaltdel shut down -h or restart (-r ) make sense
Executed only with system start, not with subsequent runlevel changes boot shutdown -r now , reboot , init 6
Executed once when indicated runlevel is reached once
When UPS is present: Process is started upon power interruption powerwait In preparation for a shutdown, sending an alert notification, etc.
When UPS is present: No waiting for process termination of the called program powerfail
When UPS is present: The UPS reports that batteries are empty, the system will be powered down powerfailnow
When UPS is present: Power supply established, waiting for process termination of the called program powerokwait

You have already seen the beginning of /etc/inittab in Listing 1. The file contains additional possibilities for interesting settings. There is an excerpt from /etc/inittab in Listing 4. At the beginning of Listing 4, you can see an instruction for init telling it to wait for the finish of the /etc/init.d/rc script for the indicated runlevel.

Listing 4

An Excerpt of inittab

01 l0:0:wait:/etc/init.d/rc 0
02 l1:1:wait:/etc/init.d/rc 1
03 l2:2:wait:/etc/init.d/rc 2
04 l3:3:wait:/etc/init.d/rc 3
05 l4:4:wait:/etc/init.d/rc 4
06 l5:5:wait:/etc/init.d/rc 5
07 l6:6:wait:/etc/init.d/rc 6
08 # Normally not reached, but fallthrough in case of emergency.
09 z6:6:respawn:/sbin/sulogin
11 # What to do when CTRL-ALT-DEL is pressed.
12 ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
14 # Action on special keypress (ALT-UpArrow).
15 #kb::kbrequest:/bin/echo "Keyboard Request--edit /etc/inittab to let this work."
17 # What to do when the power fails/returns.
18 pf::powerwait:/etc/init.d/powerfail start
19 pn::powerfailnow:/etc/init.d/powerfail now
20 po::powerokwait:/etc/init.d/powerfail stop
22 # /sbin/getty invocations for the runlevels.
23 #
24 # The "id" field MUST be the same as the last
25 # characters of the device (after "tty").
26 #
27 # Format:
28 #  <id>:<runlevels>:<action>:<process>
29 #
30 # Note that on most Debian systems tty7 is used by the X Window System,
31 # so if you want to add more getty's go ahead but skip tty7 if you run X.
32 #
33 1:2345:respawn:/sbin/getty 38400 tty1
34 2:23:respawn:/sbin/getty 38400 tty2
35 3:23:respawn:/sbin/getty 38400 tty3
36 4:23:respawn:/sbin/getty 38400 tty4
37 5:23:respawn:/sbin/getty 38400 tty5
38 6:23:respawn:/sbin/getty 38400 tty6

You can also see the instruction for what should happen when the key combination Ctrl+Alt+Del is pressed. The computer start is preset for all runlevels except 0 and 6 . The pf , pn , and po entries specify how to handle a power outage in the presence of an Uninterruptible Power Supply (UPS).

The block beginning with # Note that on most Debian ….. determines console activation. The first console, tty1 , is activated for the runlevel 1 with 5. The virtual consoles tty2 and tty6 are reserved for runlevels 2 and 3. In Debian, the graphical user interface is on tty7 . If you need more virtual consoles, and if you are working on a Debian computer, you can begin the setup of additional consoles starting with tty8 .

Runlevel and Service Administration (init)

You can find out the current and previous runlevels using the command who -r (Figure 2). The commands in Table 3 are used for a runlevel change, including shutdown and restart of a computer.

Figure 2: Determining the current and previous runlevels.

Table 3

Runlevel Change

Init Commands
0 init 0 , shutdown -h now , halt
1 init 1
2-5 init [2-5]
6 init 6 , shutdown -r now , reboot

When you use the kill -1 1 command, init reads its configuration again without restarting the computer. You can power down the system using the kill -9 1 command.

Buy this article as PDF

Express-Checkout as PDF

Pages: 1

Price $0.99
(incl. VAT)

Buy Ubuntu User

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Systemd as central control for the Linux system

    Some Linux followers see systemd as the best thing since sliced bread – for others, it's the work of the devil. However, it also has the stuff to clear out old trenches and form a unified base for Linux.

  • Innovation in the Linux environment

    Testers constantly encounter new trends in the experimental branches of Linux distributions. I look at who drives Linux forward and how the future is shaping up.

  • What is Upstart?

    Originally created for use in Ubuntu, Upstart is suitable for deployment in all Linux distributions as an alternative to the System-V init.

  • Installing and testing Nextcloud

    Leading ownCloud developers, including the project founder Frank Karlitschek, became dissatisfied with the direction of the project, so they started Nextcloud, a fork of the code and a new company. The goal is to create a better balance among the company, clients, and users. We take a look at how Nextcloud is faring.

  • Use multiple distributions at the same time with Bedrock Linux

    Bedrock transparently combines virtually any number of distributions with different architectures, package management, and init systems under a filesystem.