telinit

2024-07-20

What is telinit?

telinit is a command-line utility used to change the system’s runlevel. Runlevels represent different operational states of a Linux system. Each runlevel corresponds to a specific set of services and processes that are started or stopped. Historically, runlevels were numbered 0 to 6, each with a distinct purpose:

Using telinit

The basic syntax of telinit is straightforward:

telinit <runlevel>

Replace <runlevel> with the desired runlevel number (0-6).

Example 1: Switching to single-user mode:

To switch to single-user mode (runlevel 1), execute:

sudo telinit 1

This command will stop most services and leave only essential ones running, providing a minimal environment accessible only to the root user. Note that the sudo command is necessary because changing the runlevel requires root privileges.

Example 2: Rebooting the system:

To reboot the system (equivalent to runlevel 6), use:

sudo telinit 6

This command initiates a system reboot.

Example 3: Switching to multi-user mode:

To go back to the standard multi-user mode (runlevel 3), you would execute:

sudo telinit 3

Important Considerations

telinit vs. systemctl

While telinit manipulates runlevels, systemctl focuses on managing individual system services (units). systemctl provides far more flexibility and is the preferred method for managing services in modern Linux systems. For example, to start a service named network-online.target using systemctl:

sudo systemctl start network-online.target

To stop it:

sudo systemctl stop network-online.target

This highlights the more specific and targeted approach offered by systemctl. While telinit changes the entire system state, systemctl allows for precise control over individual services. Understanding both commands provides a detailed view of Linux system management, covering both legacy and current practices.