Operations 19 min read

Mastering /etc/init.d Scripts: A Deep Dive into Embedded Linux Service Management

This guide explains the role of the /etc/init.d directory in embedded Linux, walks through common startup scripts such as rcS, rcK, and service-specific files, and provides detailed code examples and command‑line options to help developers understand, customize, and troubleshoot system initialization and shutdown processes.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Mastering /etc/init.d Scripts: A Deep Dive into Embedded Linux Service Management

In embedded Linux development, understanding the system boot and service management mechanism is essential; the /etc/init.d directory contains shell scripts that control the lifecycle of daemons during startup and shutdown.

rcS and rcK scripts

The rcS script runs first at boot, iterating over all files matching S??* in numerical order and executing each with a start argument. It distinguishes .sh scripts (sourced for speed) from other executables (forked as subprocesses). The rcK script performs the reverse order during shutdown, passing a stop argument.

Service scripts

Each service script follows a similar pattern: a shebang line, optional comments, a case statement handling start, stop, restart / reload, and a usage fallback. Examples include:

S01logging : starts and stops syslogd and klogd using start-stop-daemon with appropriate flags.

S10udev : initializes the udev daemon, creates necessary device nodes, and handles start / stop actions with udevadm commands.

S13portmap : launches the RPC portmap service, creates a lock file, and provides start/stop/restart handling.

S20urandom : saves and restores the random seed from /dev/urandom during boot and shutdown, checking for read‑only filesystems.

S30dbus : starts the D‑Bus system message bus, creates required directories, and manages the daemon with start-stop-daemon.

S40network : brings up or down all network interfaces using /sbin/ifup -a and /sbin/ifdown -a.

S50dropbear and S50sshd : start and stop SSH daemons, handling key generation and lock files.

S50telnet : controls the telnet daemon via start-stop-daemon.

S70vsftpd : manages the vsftpd FTP server with simple start/stop commands.

S80mount‑opt : mounts a UBIFS filesystem on /opt, with fallback steps to format and create the volume if the initial mount fails.

S81web.sh : launches a custom web service in the background.

S90start_userapp.sh : configures network interfaces, disables RTC clock output, and optionally runs a user‑provided script from an SD card.

socketcand : provides a daemon for CAN bus access, with standard init‑info headers and start/stop handling.

Common command‑line utilities

The scripts frequently use start-stop-daemon (options -S / -K, -b, -q, -p, -x, etc.) to manage background processes, as well as utilities like udevadm, dbus-daemon, ifup/ifdown, and various mount commands.

Conclusion

Mastering the /etc/init.d scripts gives developers fine‑grained control over service startup and shutdown in resource‑constrained embedded devices. Although modern systems are moving toward systemd, the traditional init.d approach remains vital for many existing and low‑resource projects.

LinuxshellembeddedService Managementstartup scriptsinit.d
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.