Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux init Command

Linux init Command

Linux Command Reference Linux Command Reference


What is the init command

init is one of the most important processes in Linux. It is the first user-level process created by the kernel after system startup (PID=1), responsible for starting and managing all other processes in the system.

Key characteristics


Basic syntax of the init command



init [运行级别]

Runlevel description

Linux systems define 7 standard runlevels:

Runlevel Description Typical use
0 Shutdown System halted state
1 Single-user mode System maintenance / root privileges
2 Multi-user mode (no NFS) Basic multi-user mode
3 Full multi-user mode Standard command-line interface
4 Keep User-defined
5 Graphical interface mode Multi-user mode with GUI
6 Reboot System reboot

Practical applications of the init command

1. Check the current runlevel

Example

who

-r

or

runlevel

2. Switch runlevels

Example

init

3

 

Switch to multi-user command-line mode

init

5

 

Switch to graphical interface mode

init

0

 

Shutdown

init

6

 

Reboot the system

3. Emergency handling

Example

init

1

 

Enter single-user maintenance mode (requires root privileges)


Evolution of init in modern Linux systems

1. System V init

Traditional initialization system using the /etc/inittab configuration file

Example

Typical inittab entry example

id:

3

:initdefault:  

Default runlevel

si::sysinit:

/

etc

/

rc.d

/

rc.sysinit  

System initialization script

2. Upstart (used in early Ubuntu versions)

Event-driven init system

3. systemd (modern mainstream distributions)

Example

systemctl isolate multi-user.target  

Equivalent to init 3

systemctl isolate graphical.target  

Equivalent to init 5


Practical Exercise

Exercise 1: Runlevel switching experiment

Switch from the graphical interface to command-line mode



init 3

Observe service changes, then switch back to the graphical interface



init 5

Exercise 2: Experiencing system maintenance mode

Enter single-user mode



init 1

Perform a file system check



fsck /dev/sda1


Notes

  1. Permission requirements: The init command usually requires root privileges
  2. Use with Caution: Directly using init 0 or init 6 may cause loss of unsaved data
  3. System differences: Different distributions may have different init implementations
  4. Service impact: Switching runlevels stops/starts related services

Frequently Asked Questions

Q: Why doesn't my system have an /etc/inittab file?
A: Systems using systemd no longer need inittab; the configuration method has changed

Q: How do I set the default runlevel?
For systemd systems:



systemctl set-default multi-user.target  # 相当于运行级别3

Q: What is the difference between the init and shutdown commands?
Both ultimately shut down the system, but shutdown provides more options (such as delayed shutdown, broadcast notifications, etc.)

Linux Command Reference Linux Command Reference