Linux Tutorial

Linux File/Directory Management

Linux Packaging And Compression

Vim Text Editor

Linux Text Processing

Linux Software Installation

Linux User/User Group Management

Linux Permission Management

Linux Filesystem Management

Linux Advanced Filesystem Management

Linux System Management

Linux Backup and Recovery

Linux System Service Management

Linux System Log Management

Linux Boot Management

LAMP/LNMP Environment

SELinux Management

Linux /sbin/init Initializes The System Environment

/sbin/init is the first process that runs when a Linux system boots, making it the parent of all other processes. As the system's initialization process, its primary responsibility is to set up the system environment and manage background services. In this tutorial, we'll discuss the /sbin/init process, its role, and its relationship with various init systems such as SysV init, Upstart, and systemd.

  • Overview of /sbin/init:

The /sbin/init process is spawned by the kernel as the first user-space process during the boot sequence. It initializes the system environment by performing tasks such as mounting filesystems, starting system services, and launching background daemons. After setting up the environment, /sbin/init manages the system by supervising services and maintaining runlevels or targets.

  • Different init systems:

Various init systems have been developed over the years to handle system initialization and management, including SysV init, Upstart, and systemd. While each init system has a different implementation, they all symlink to /sbin/init for compatibility, ensuring that they're started as the first user-space process.

  • SysV init: The traditional System V-style init system organizes system services into runlevels, with each runlevel representing a specific system state (e.g., single-user mode, multi-user mode, or graphical mode). The /etc/inittab file defines the default runlevel and associated scripts located in /etc/init.d/ and /etc/rc.d/ directories.

  • Upstart: Designed as a replacement for SysV init, Upstart is an event-based init system that can handle dynamic changes in the system state, such as hardware events and service dependencies. It uses the /etc/init/ directory to store configuration files for each service in the Upstart format.

  • systemd: The most widely used init system today, systemd is a modern init system that provides advanced features, such as parallel service startup, service dependency management, and integrated logging. It uses the /etc/systemd/system/ directory to store unit files for each service and target, which is the equivalent of runlevels in SysV init.

  • How to identify the init system:

To identify which init system your Linux distribution is using, you can check the target of the /sbin/init symlink:

ls -l /sbin/init

The output will indicate the symlink target, which will reveal the init system being used. For example, if the target is /lib/systemd/systemd, then the init system is systemd.

  • Working with init systems:

Depending on the init system used by your Linux distribution, you will need to use different commands and configuration files to manage services and system states. Here are some examples:

  • SysV init:

    • Change the default runlevel: Edit the /etc/inittab file and modify the id field (e.g., id:3:initdefault:).
    • Start/stop a service: sudo service <service_name> start|stop|restart|status
  • Upstart:

    • Start/stop a service: sudo start|stop|restart|status <service_name>
  • systemd:

    • Set the default target: sudo systemctl set-default <target_name>.target
    • Start/stop a service: sudo systemctl start|stop|restart|status <service_name>

In this tutorial, we've discussed the role of the /sbin/init process in Linux system initialization and management. We've also provided an overview of various init systems, including SysV init, Upstart, and systemd. Understanding the init system your distribution uses is crucial when configuring and managing services, as well as troubleshooting system issues.