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 /etc/inittab: Set (modify) The System Default Runlevel

The /etc/inittab file is a configuration file in older Linux systems that is used by the init process (System V-style init) to define the default runlevel and control how processes are spawned at boot time. However, it is essential to note that many modern Linux distributions, such as those using systemd, have deprecated the use of /etc/inittab and replaced it with more advanced initialization systems. This tutorial will focus on older Linux systems that still use the /etc/inittab file.

Here's a tutorial on the /etc/inittab file:

  1. Structure of /etc/inittab file:

    The /etc/inittab file consists of multiple lines, each with the following format:

    id:runlevels:action:process
    
    • id: A unique identifier for the entry (usually 1-4 characters)
    • runlevels: A list of runlevels (0-6, S or s) to which the entry applies
    • action: The action to be taken when the entry is processed
    • process: The command to be executed when the action is performed

    For example:

    l2:2:wait:/sbin/login
    
  2. Read the /etc/inittab file:

    Use the cat or less command to read the /etc/inittab file:

    cat /etc/inittab
    

    or

    less /etc/inittab
    
  3. Common Actions:

    • initdefault: Sets the default runlevel for the system
    • sysinit: Executes the specified process early in the boot process, usually for system initialization tasks
    • wait: Executes the specified process and waits for its completion before proceeding to the next entry
    • respawn: Executes the specified process and restarts it when it terminates
    • once: Executes the specified process once, without respawning it
  4. Edit the /etc/inittab file:

    To modify the /etc/inittab file, open it with your preferred text editor as the root user:

    sudo nano /etc/inittab
    

    or

    sudo vim /etc/inittab
    

    Make the desired changes, save the file, and exit the editor.

  5. Apply changes to the /etc/inittab file:

    To apply the changes made to the /etc/inittab file without rebooting, use the telinit command to notify the init process to re-examine the /etc/inittab file:

    sudo telinit q
    

By understanding the purpose and configuration of the /etc/inittab file, you can manage the init process in older Linux systems that still rely on System V-style init. Remember that modern Linux distributions have replaced /etc/inittab with other mechanisms like systemd, so this tutorial may not be applicable to the latest systems.

  1. How to set default runlevel in Linux /etc/inittab: The /etc/inittab file in Linux defines the default runlevel. To set the default runlevel:

    Open /etc/inittab in a text editor and locate the line with initdefault. Change the runlevel parameter to the desired runlevel, for example:

    id:3:initdefault:
    

    This sets the default runlevel to 3.

  2. Viewing and editing inittab file in Linux: To view and edit the /etc/inittab file:

    cat /etc/inittab
    

    To edit:

    sudo nano /etc/inittab
    
  3. Setting initdefault parameter in /etc/inittab: Set the initdefault parameter to the desired runlevel. For example, to set runlevel 5 as the default:

    id:5:initdefault:
    
  4. Switching between runlevels using /etc/inittab: To switch between runlevels, use commands like telinit. For example, to switch to runlevel 3:

    sudo telinit 3