Linux › Section F · How user space starts › Topic F.4

System V runlevels and init

Before systemd, most Linux systems booted with System V init: numbered runlevels, a configuration file called inittab and directories of start and stop scripts. It is legacy now, but you will still meet it on old servers, embedded devices and in a lot of documentation.

Why study a legacy init

System V init (SysV init) takes its name from AT&T's Unix System V. It was the usual Linux init for many years, until the major distributions moved to systemd in about 2011 to 2015, as "Introduction to init" described. You may still find it on Red Hat Enterprise Linux 5 and older (version 6 ran the same scripts under Upstart), Debian 7 and older, on Devuan, a Debian derivative built without systemd, and in embedded systems such as routers. Its ideas also explain many current conventions: the scripts in /etc/init.d, the service command, and the names multi-user and single-user mode. Treat everything in this topic as legacy knowledge, useful for maintenance and for reading older material.

Runlevels

A runlevel is a numbered state of the whole machine, defined by which services run. There are seven, 0 to 6. Runlevel 0 halts the system, 1 is single-user mode for maintenance, and 6 reboots. Levels 2 to 5 are multi-user states whose meaning varies by distribution. On Red Hat systems, 3 meant full multi-user operation with networking on a text console and 5 added a graphical login, while 4 was unused. Debian used 2 as its default and configured 2 to 5 identically unless the administrator changed them. The commands who -r and runlevel show the current runlevel; runlevel prints the previous and current levels, such as N 3, where N means there was no previous one.

/etc/inittab

SysV init reads /etc/inittab when it starts. Each line has four fields separated by colons: an identifier, the runlevels it applies to, an action, and a command. The line id:3:initdefault: sets the default runlevel to 3; it has no command. Common actions are sysinit, run once at boot before any runlevel; wait, run once on entering the listed runlevels while init waits for it to finish; respawn, restarted whenever it exits; and ctrlaltdel, run when someone presses Ctrl+Alt+Del at the console. Lines whose first character is # are comments. The inittab(5) manual page lists every action.

Worked example: reading inittab lines

Read three lines from a Debian-style file. 1. id:2:initdefault: has identifier id, runlevel 2 and action initdefault, so the machine boots to runlevel 2. 2. l2:2:wait:/etc/init.d/rc 2 applies only in runlevel 2. The wait action runs the rc script with the argument 2 and waits until it has started every service for that level. 3. 2:23:respawn:/sbin/getty 38400 tty2 applies in runlevels 2 and 3. It runs a getty login prompt on the second virtual console, /dev/tty2, at 38400 baud, and respawn starts a fresh prompt each time a user logs out and the old one exits. 4. Check: each line has exactly four fields, even when the command field is empty.

rc scripts and the link farm

The rc script does most of the work. For runlevel N it looks in a directory called rcN.d: /etc/rcN.d on Debian, /etc/rc.d/rcN.d on Red Hat. Each entry is a symbolic link to a real script in the init.d directory, such as S55sshd pointing to ../init.d/sshd. A name beginning with S means run the script with the argument start; K (kill) means run it with stop. The two digits set the order, because rc processes the names in sorted order, running the K links before the S links. Using links lets one script serve every runlevel. This large web of symbolic links is often called a link farm. Names that start with neither S nor K are ignored.

Worked example: a runlevel 3 boot

On a Red Hat style server, ls /etc/rc.d/rc3.d shows K20nfs, S10network, S55sshd, S90crond and S99local. 1. Entering runlevel 3, rc first runs the K link: /etc/rc.d/init.d/nfs stop, so the NFS server does not run at this level. 2. It then runs the S links in order: network start, sshd start, crond start, and finally S99local, which points to the rc.local script for local additions. 3. The two-digit numbers matter because names are compared character by character. A link called S9foo would sort after S10bar, since the character 9 comes after 1; that is why the numbers are padded to 00 to 99. 4. Check: SSH starts after networking because 55 is greater than 10, and nothing would order it otherwise.

Managing services and runlevels

To control a service by hand, run its script directly, as in /etc/init.d/cron restart, or use the wrapper service cron restart. Rather than editing links yourself, use the distribution's tool: update-rc.d on Debian (update-rc.d foo defaults adds the standard links, update-rc.d foo disable turns them into K links) and chkconfig on Red Hat (chkconfig --list, or chkconfig --level 35 httpd on). To change the running system, telinit 3 switches to runlevel 3, telinit 1 enters single-user mode, and telinit q tells init to reread inittab after you edit it. Changing runlevel stops every service not wanted at the new level, so warn logged-in users first.

run-parts

A small helper from this era is still widely used: run-parts runs every executable file in a directory, one after another, in the lexical order of their names. Debian's daily cron jobs in /etc/cron.daily are run this way. Debian's version has a notable rule: by default a file name may contain only letters, digits, underscores and hyphens, so a script named backup.sh is silently skipped. Its --test option prints the names that would run without running them, which is the quickest way to check. Fedora ships a much simpler run-parts. Either way, its only job is to run the programs in one directory in a predictable order.

SysV compatibility in systemd

For years systemd could run old init scripts: a generator read /etc/init.d and wrapped each script in a service unit, so systemctl could start it and show its status, and units such as runlevel3.target were aliases for the matching targets (runlevel 0 for poweroff.target, 1 for rescue.target, 2 to 4 for multi-user.target, 5 for graphical.target and 6 for reboot.target). That support is being removed. systemd 258, released in September 2025, dropped the runlevel concept and the telinit and runlevel commands, and systemd 260, released in March 2026, removed support for SysV service scripts entirely. Distributions with older systemd releases still include the compatibility layer, but new software should always ship native unit files.

Common mistakes to avoid

First, assuming runlevels mean the same everywhere: 3 and 5 follow the Red Hat convention, while Debian treated 2 to 5 alike. Second, deleting an rcN.d link to disable a service; use update-rc.d or chkconfig so the change can be reversed cleanly. Third, editing inittab and forgetting telinit q, so init keeps the old settings. Fourth, switching runlevel on a remote server without checking that networking and SSH remain at the new level. Fifth, naming a run-parts script with a dot, which Debian's run-parts ignores. Sixth, expecting telinit, the runlevel command or init scripts to work on a recent systemd release.

Key takeaways

System V init is legacy, but it shaped many current conventions. Runlevels 0 to 6 name system states: 0 halt, 1 single-user, 6 reboot, and 2 to 5 multi-user variants that differ between distributions. /etc/inittab lines have four fields, identifier:runlevels:action:command, with actions such as initdefault, sysinit, wait and respawn. The rc script runs the K links and then the S links in rcN.d, in sorted order; the links point to scripts in init.d. Use service, update-rc.d or chkconfig, and telinit to change runlevel. run-parts runs a directory's programs in lexical order. systemd 258 removed runlevels and 260 removed SysV script support.

Flashcards

Flashcard

Runlevel

A numbered system state, 0 to 6, in System V init

Defined by which services run.

Test your understanding

Question 1 of 5

What does the inittab line 3:23:respawn:/sbin/getty 38400 tty3 do?

Question 2 of 5

Entering runlevel 3, rc finds K20nfs, S10network and S55sshd in rc3.d. In what order are they run?

Question 3 of 5

A Debian administrator puts an executable script called rotate.sh in /etc/cron.daily, but it never runs. What is the most likely cause?

Question 4 of 5

On a SysV init system you have just edited /etc/inittab. How do you make init use the changes without rebooting?

Question 5 of 5

Which statement about SysV support in current systemd is correct?

← Previous topicNext topic →