Open In App

init command in Linux with examples

Last Updated : 10 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

The init process is the parent of all processes in Linux, identified by the process ID (PID) of 1. It is the first process that starts when a computer boots up and continues to run until the system shuts down. The term init stands for “initialization,” and its primary role is to create and manage processes based on instructions from configuration scripts, specifically those stored in the ‘/etc/inittab‘ file. As the last step of the kernel boot sequence, ‘init’ is crucial for the initialization and overall functioning of the system.

Role of the ‘init’ Command

The ‘init’ command initializes the system by executing scripts that set up the operating environment. These scripts, known as “init scripts” or “rc scripts” (short for run command scripts), are used in both Linux and UNIX systems to start and stop services and perform various other tasks during system initialization.

The configuration file ‘/etc/inittab’ is used to control the behavior of the init process, defining which processes to start at specific runlevels and other system startup settings.

Syntax:

init [OPTIONS...] {COMMAND}

This syntax allows you to specify options and commands to control the system’s initialization process, including changing runlevels, rebooting, or shutting down the system.

Run Levels in Linux

Run Levels is the state of init where a group of processes is defined to start at the startup of OS. The process spawned by init for each of this run levels are defined in the file /etc/inittab. Each runlevel has a certain number of services stopped or started. Conventionally seven runlevel exist numbers from zero to six.

Standard Run Levels for Red Hat Based Distribution:

Runlevel

Mode Action
0 Halt Shuts down system
1 Single-User Mode

Does not configure network interfaces, start daemons, 

or allow non-root logins

2 Multi-User Mode Does not configure network interfaces or start daemons.
3 Multi-User Mode with Networking Starts the system normally.
4 Undefined Not used/User-definable
5 X11 As runlevel 3 + display manager(X)
6 Reboot Reboots the system

Detailed Explanation of Runlevels

  • Runlevel 0: Halt
    This runlevel stops all processes and shuts down the system. It is used when powering off the machine safely. 
  • Runlevel 1: Single-User Mode
    In this mode, the system boots into a single-user environment, usually for maintenance tasks. Networking is disabled, and only the root user can log in.
  • Runlevel 2: Multi-User Mode
    This runlevel supports multiple users but does not start networking services or daemons. It is often used for specific server setups that do not require network access.
  • Runlevel 3: Multi-User Mode with Networking
    Runlevel 3 is a fully operational state, supporting multiple users with all network services and daemons running. This is a common default runlevel for servers.
  • Runlevel 4: Undefined/User-Definable
    Runlevel 4 is generally unused by default but is available for custom user configurations. Administrators can define this runlevel to suit specific needs.
  • Runlevel 5: X11 (Graphical Interface)
    Similar to runlevel 3, but with the addition of the graphical display manager (X Window System). This runlevel is typically used for desktop systems.
  • Runlevel 6: Reboot
    Runlevel 6 restarts the system by rebooting. It is used when you need to restart all services or reinitialize the system completely.

Conclusion

The ‘init’ process is a fundamental component of the Linux operating system, responsible for initializing the system, managing services, and controlling the overall boot process. Through runlevels, it offers a structured way to manage system states, allowing administrators to customize which services run at various stages of the system’s lifecycle. Understanding and utilizing ‘init’ effectively can significantly enhance system performance, security, and reliability, making it an indispensable tool for Linux system administration.

init command in Linux – FAQs

What is the init process in Linux?

The ‘init’ process is the first process that starts when a Linux system boots up. It initializes the system, manages services, and controls the overall boot process, running until the system is shut down.

Why is the init process important?

‘init’ is crucial because it starts and manages all other processes on the system. It sets up the operating environment and ensures that necessary services and processes are running according to system requirements.

What are runlevels in Linux?

Runlevels are predefined states of the Linux system that define which services and processes are started or stopped. Each runlevel has a specific configuration, ranging from shutting down the system to full multi-user operation with a graphical interface.

How does init use runlevels?

The ‘init’ process uses runlevels to determine the state of the system and manage which services should be running. It reads the configuration from the ‘/etc/inittab’ file to decide which processes to start at each runlevel.

What are the standard runlevels in Red Hat-based distributions?

The standard runlevels are:

  • 0: Halt (Shuts down the system)
  • 1: Single-User Mode (Maintenance mode without networking)
  • 2: Multi-User Mode (No networking)
  • 3: Multi-User Mode with Networking
  • 4: Undefined/User-Definable
  • 5: X11 (Multi-User Mode with GUI)
  • 6: Reboot

    Next Article

    Similar Reads

    three90RightbarBannerImg