Search code examples
yoctosystemd

How to enable networking service at boot in Yocto


I have a Yocto based OS on which I have everything installed to start the network.

Nevertheless, at each boot I need to do systemctl start networking to start it. Initially the service was even masked. I found out how to unmask it but I can't find a way to start it automatically.

I don't know much about systemd but the networking.service is located in generator.late folder. From what I understood, it's generated afterward.

How can I enable it?


Solution

  • It depends if you want to enable the service only on one particular device. If yes, it is simple:

    systemctl enable networking
    

    Append the parameter --now if you also want to start the service just now.

    If you want to enable the service on all your devices (i.e. it will be automatically enabled in all your images coming from build), the best way is to extend the recipe, but please see below for other ways how to handle the network. The process is describe at NXP support for example.

    Some notes about networking.service itself: I assume that your networking.service comes from init-ifupdown recipe. If yes, is there any reason to handle network configuration using old SysV init script in system with systemd? The service is generated from SysV init script by systemd-sysv-generator. So I would suggest to try other networking services like systemd's native "systemd-networkd", "NetworkManager" or "connman". The best choice depends on type of your embedded systemd. These services are integrated with systemd much better.

    Some more information on activating or enabling the services: https://unix.stackexchange.com/questions/302261/systemd-unit-activate-vs-enable