Using systemd


Introduction

This section provides a guide on configuring and using systemd, the advanced system, and the service manager on target.

  • Systemd is a robust system and service manager that efficiently manages dependencies between system services by classifying tasks into units and targets.
  • Systemd initiates units and targets automatically during boot or in response to requests from the user or the system.

Note: Starting from Linux4SAM-2023.10 release traditional SysVinit is replaced with systemd as default.

Features

Systemd is almost compatible with most modern features, other notable features includes:

  • Reduces boot times through parallel startup procedures.
  • Improves dependency management.
  • Supports dynamic configuration.
  • Provides effective resource management and service monitoring.

Prerequisites

Pointing hand Starting with Linux4SAM-2023.10, we provide and support systemd.

Advanced features

Pointing hand From Linux4SAM-2023.10, Buildroot employs systemd version 252, while the Yocto Project utilizes systemd version 250 with the additional version label of 250.5+.

Unit management with systemd

  • Systemd uses a "unit" as the fundamental object that it controls and operates upon. Though there are many different kinds of units, "services" are the most prevalent kind (represented by a unit file ending as .service).
  • One can perform various management tasks to control systemd services using the systemctl command.

Basic service management

Pointing hand For instance, To start an egtdemo.service immediately: 
 systemctl start egtdemo.service 
Pointing hand To stop egtdemo.service service: 
 systemctl stop egtdemo.service
Pointing hand Similarly, To restart egtdemo.service service: 
 systemctl restart egtdemo.service

Enable or Disable units

Pointing hand Generally, most systemd unit files are not started by default at boot unless it is required, to enable a egtdemo.service to be started automatically on boot: 
 systemctl enable egtdemo.service
Pointing hand To disable started egtdemo.service on boot:
 systemctl disable egtdemo.service
Pointing hand To check if a service is enabled or not:
 systemctl is-enabled egtdemo.service
Pointing hand To check the status of a specific service including, whether it is running or not: 
 systemctl status egtdemo.service
One can see status logs like below,
 root@sam9x60-curiosity-sd:~# systemctl status egtdemo.service
* egtdemo.service - EGT Application Launcher Service
     Loaded: loaded (8;;file://sam9x60-curiosity-sd/lib/systemd/system/egtdemo.service/lib/systemd/system/egtdemo.service8;;; enabled; vendor preset: enabled)8;;
     Active: active (running) since Fri 2022-04-29 05:41:01 UTC; 57min ago
   Main PID: 205 (egt-launcher)
      Tasks: 2 (limit: 257)
     Memory: 26.6M
     CGroup: /system.slice/egtdemo.service
             `- 205 egt-launcher /opt/applications/resources /usr/share/egt

System state Information

Pointing hand For example, to obtain every unit file that systemd has listed as "active":
 systemctl list-units
Pointing hand To list every unit file that systemd has loaded though that is listed as "not active":
 systemctl list-units --all

Log Information

  • All of the system's journal entries are gathered and managed by the journald systemd component. This is basically a log information from applications and the kernel.

Pointing hand To see all log entries,  

 journalctl 
Pointing hand To see journal entries from the current boot, add the -b flag: 
 journalctl -b 
Pointing hand To see only kernel messages, such as those that are typically represented by dmesg, you can use the -k flag: 
 journalctl -k 
Pointing hand Also we can limit it to current boot by appending the -b flag: 
 journalctl -k -b 

Managing network configurations using systemd

  • Default network configuration files are available at /etc/systemd/network (or) /lib/systemd/network directory. 

Note: Files in /etc/systemd/network have a higher priority than the ones in /lib/systemd/network. 

For Instance, a typical wlan interface configuration sample is given below,  

 [Match] 
Name=wlan* 

[Network] 
DHCP=yes 
#Address=192.168.8.2 
#Netmask=255.255.255.0 
#Network=192.168.8.0 
#Gateway=192.168.8.1 

Here, one can see by-default it is configured to DHCP and dynamically assigns IP. 

Wired network configuration

  • To modify DHCP to static IP configuration for wired interfaces one can create (or) edit /etc/systemd/network/10-eth.network file with the contents below, 
[Match] 
Name=eth* 

[Network] 
#DHCP=yes 
Address=192.168.7.2 
Netmask=255.255.255.0 
Network=192.168.7.0 
Gateway=192.168.7.1 
  • Once the configuration is updated for static IP, simply reload (or) restart systemd-networkd using below command 
 systemctl reload systemd-networkd  
or
 systemctl restart systemd-networkd  

Wireless network configuration

  • To modify DHCP to static IP configuration for wireless interfaces one can create or edit /etc/systemd/network/systemd/20-wlan.network file with the contents below,  
[Match] 
Name=wlan* 

[Network] 
#DHCP=yes 
Address=192.168.8.2 
Netmask=255.255.255.0 
Network=192.168.8.0 
Gateway=192.168.8.1 
  • Once the configuration is updated for static IP, simply reload or restart systemd-networkd using below command 

 systemctl reload systemd-networkd
or
 systemctl restart systemd-networkd 
After this one can observe static IP assigned to corresponding interface accordingly as furnished in below logs,


root@sam9x60-curiosity-sd:~# ifconfig 

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500 
        inet 192.168.7.2  netmask 255.255.255.0  broadcast 192.168.7.255 
        inet6 fe80::691:62ff:fef2:8912  prefixlen 64  scopeid 0x20<link> 
        ether 04:91:62:f2:89:12  txqueuelen 1000  (Ethernet) 

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500 
        inet 192.168.8.2  netmask 255.255.255.0  broadcast 192.168.8.255 
        inet6 fe80::628a:10ff:fed8:9418  prefixlen 64  scopeid 0x20<link> 
        ether 60:8a:10:d8:94:18  txqueuelen 1000  (Ethernet) 

Note: The default static IP configuration given here is just a sample, one can modify it according to their recommended need.