init 6 vs reboot vs shutdown -r: Deep Dive into Linux System Restart Commands


2 views

While these commands all result in a system restart, their execution paths differ significantly:

# init 6 execution path
1. Executes all kill scripts (K* scripts in /etc/rc.d/)
2. Unmounts filesystems 
3. Performs hardware reboot

# reboot execution path  
1. Sends SIGTERM to processes
2. Immediately unmounts filesystems
3. Hardware reboot

The key distinction lies in how services are terminated:

# init 6 behavior (graceful)
for service in $(ls /etc/rc.d/rc*.d/K*); do
    $service stop
done

# reboot behavior (aggressive)
pkill -TERM -P 1  # Sends SIGTERM to all processes

Both commands sync filesystems, but with different timing:

# init 6 sequence
sync
umount -a
reboot

# reboot sequence
sync
reboot -f  # Force unmount during reboot

When you should prefer each method:

# Use init 6 when:
- Running critical databases (MySQL, PostgreSQL)
- Need clean service shutdown
- Using networked filesystems (NFS)

# Use reboot when:
- System is unresponsive
- Need immediate restart
- Troubleshooting boot issues

On modern systems with systemd, the differences are less pronounced but still exist:

# Systemd equivalents
systemctl reboot      # Similar to reboot
systemctl isolate reboot.target  # Closer to init 6

A safe reboot wrapper script example:

#!/bin/bash
# Safe reboot script
if [[ $1 == "--force" ]]; then
    /sbin/reboot
else
    echo "Performing graceful reboot..."
    /sbin/init 6
fi

In Red Hat Enterprise Linux (RHEL) and its derivatives like CentOS, system reboots can be initiated through multiple commands, each with distinct behavioral characteristics:

# Common reboot commands
shutdown -r now
reboot
init 6

The fundamental distinction lies in how these commands handle the shutdown sequence:

  • init 6: Triggers the full System V init sequence, executing all runlevel transition scripts (including kill scripts in /etc/rc.d/rc*.d/)
  • reboot: Bypasses most of the init system, directly unmounting filesystems and restarting
  • shutdown -r: Similar to init 6 but with more configurable options

With systemd adoption, the behavior has become more standardized:

# Modern equivalents with systemd
systemctl reboot      # Similar to traditional reboot
systemctl isolate runlevel6.target  # Closer to init 6

You can observe the differences by checking the shutdown sequence:

# Monitor the shutdown process
journalctl -f

# Or check the last shutdown
last -x | grep shutdown

Recommendations based on use cases:

Command When to Use
init 6 When you need proper service shutdown sequence
reboot For quick reboots when services are stateless
shutdown -r For scheduled reboots with warnings

The binary implementations differ significantly:

# Check which binary gets executed
which reboot
which init
which shutdown

On most systems, reboot is a symlink to /usr/bin/systemctl while init remains as SysV compatibility.