Troubleshooting: Init System Failures
Troubleshooting: Init System Failures
When Process ID 1 fails during boot, the operating system halts or hangs indefinitely. Because userspace logging daemons have not started yet, troubleshooting init failures requires specific diagnostic techniques.
Diagnostic 1: The Direct Shell Bypass (init=/bin/sh)
If PID 1 crashes, refuses to start, or locks you out with an unconfigured root password, reboot the machine and append the following parameter to the kernel command line in your bootloader:
init=/bin/sh
This bypasses systemd, OpenRC, and /sbin/init entirely. The Linux kernel mounts the root filesystem (often read-only) and immediately spawns a root /bin/sh shell.
Once in the shell:
# Remount the root filesystem read-write:
# mount -o remount,rw /
# Verify executable permissions and dynamic linking on the real init:
# ldd /sbin/init
# /sbin/init --versionDiagnostic 2: Diagnosing systemd Boot Freezes
If systemd hangs during boot: 1. Enable Systemd Debug Logging: Add to the kernel command line: text systemd.log_level=debug systemd.log_target=kmsg systemd.debug_shell=1 - systemd.debug_shell=1: Spawns a root shell on tty9 (Ctrl+Alt+F9) automatically, allowing you to log in even if the graphical login manager freezes. 2. Inspect Slow Units: Once booted, analyze boot bottlenecks using: ```bash $ systemd-analyze Startup finished in 1.203s (kernel) + 2.140s (userspace) = 3.343s
$ systemd-analyze blame | head -n 10 3. **Generate a Dependency Chart:** Visualize cyclic dependencies or long activation paths:bash $ systemd-analyze plot > boot-timeline.svg ```
Diagnostic 3: OpenRC Dependency Loops
In OpenRC, if two services depend on each other (e.g., service A needs B, and service B needs A), OpenRC will detect a cyclic dependency in its Directed Acyclic Graph (DAG) and abort:
* rc: Service 'sshd' has a dependency loop with 'network'
Remedy: 1. Boot into single-user mode: add single or init=/bin/sh to kernel parameters. 2. Check the dependency trees of both services in /etc/init.d/. 3. Change one of the hard need statements to a soft use or after directive.