Adding and Removing services for Yocto at runtime

Yocto uses a fairly standard Linux init system (called sysvinit) for system init for managing services. A service is a process that usually starts on boot and runs in the background.

Services exist in /etc/init.d:

root@ventana:~# ls /etc/init.d              hostapd         
alsa-state                     rpcbind
apmd                            run-postinsts
avahi-daemon                               sendsigs
bootlogd                       single               neard                     stop-bootlogd              networking      
dbus-1                    ofono                     syslog             syslog.busybox                        udev
dnsmasq                   rc                        udev-cache
dropbear                  rc.local                  umountfs
functions                 rcS             
functions.initscripts  urandom
halt                      reboot

The 'init' process (PID 1) is launched from the kernel after the root filesystem has been mounted. It processes /etc/inittab which dictates what 'runlevel' to enter on boot and what init services to kick off. The various run levels each have their own directories containing symbolic links to the services in /etc/init.d. These links are prefixed with S for startup, and K for shutdown and a numeric that determines the order they are run in. For example, a default /etc/inittab contains the following line which tells the system to start in runlevel 5:


Symbolic links for runlevel 5 exist in /etc/rc. The update-rc.d application is used to configure services:

root@ventana:~# ls /etc/rc5.d/
S01networking     S64neard
S02dbus-1         S20apmd           S20syslog         S99rc.local
S10dropbear       S20dnsmasq        S21avahi-daemon
S12rpcbind        S20hostapd        S22ofono          S99stop-bootlogd

Enabling and disabling services becomes a task of creating and removing symbolic links to the various /etc/rc*.d/ directories. This can be done for you using the update-rc.d package. Some packages may define default priorities and run levels in their init script - others do not, or you may want to override them anyway.

To remove (disable) a service that is installed aside from removing the package you could disable it with the following update-rc.d command:

root@ventana:~# update-rc.d -f hostapd remove
update-rc.d: /etc/init.d/hostapd exists during rc.d purge (continuing)
 Removing any system startup links for hostapd ...
  • Note the -f parameter above to force update-rc.d to do your bidding - this overrides any default behavior it may have if you try to do something that disagree's with the packages default configuration

To enable a service to start with priority 10 for runlevel 5 you could use the following:

root@ventana:~# update-rc.d hostapd start 10 5
action with list of runlevels not terminated by `.'
root@ventana:~# update-rc.d hostapd start 10 5 .
 Adding system startup for /etc/init.d/hostapd.

To see the init configuration for a particular service, you can use ls to inspect symlinks:

root@ventana:~# ls /etc/rc*.d/*hostapd*
  • The above shows how we have modified hostapd to start in runlevel 5 only

To get see what services will start before and after each other, look at an alphabetic listing of a particular runlevel:

root@ventana:~# ls /etc/rc5.d/
S01networking     S12rpcbind     S64neard
S02dbus-1    S20syslog         S99rc.local
S10dropbear       S20apmd           S21avahi-daemon
S10hostapd        S20dnsmasq        S22ofono          S99stop-bootlogd
  • here you can see the networking starts first (01), then dbus-1 (02) then dropbear etc

See also:

Configuring packages to start/stop services at build time

You can specify how your Yocto packages interact with sysvinit at build time.

For more info:

Last modified 12 months ago Last modified on 06/29/16 12:21:23