Using systemd
Introduction
This section provides a guide on configuring and using systemd, the advanced system, and the service manager on the target.
systemd is a robust system and service manager that efficiently manages dependencies between system services by classifying tasks into units and targets. It initiates units and targets automatically during boot or in response to requests from the user or system.
Features
systemd is almost compatible with most modern features; other notable features include:
- Reduces boot times through parallel startup procedures
- Improves dependency management
- Supports dynamic configuration
- Provides effective resource management and service monitoring
Prerequisites
Starting with Linux4SAM 2023.10, we provide and support systemd.
Advanced Features
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 in .service). Various management tasks to control systemd services can be performed using the systemctl command.
Basic Service Management
For instance, to start an egtdemo.service immediately:
To stop egtdemo.service service:
Similarly, to restart egtdemo.service service:
Enable or Disable Units
Generally, most systemd unit files are not started by default at boot unless it is required, to enable an egtdemo.service to be started automatically on boot:
To disable the started egtdemo.service on boot:
To check if a service is enabled or not:
To check the status of a specific service, including whether it is running or not:
The following is an example of a status log:
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
For example, to obtain every unit file that systemd has listed as active:
To list every unit file that systemd has loaded, though that is listed as not active:
Log Information
All of the system's journal entries are gathered and managed by the journald systemd component. This is basically a log of information from applications and the kernel.
To see all log entries:
To see journal entries from the current boot, add the -b flag:
To see only kernel messages, such as those that are typically represented by dmesg, you can use the -k flag:
Also, we can limit it to the current boot by appending the -b flag:
Managing Network Configurations Using systemd
Default network configuration files are available at /etc/systemd/network (or) /lib/systemd/network directory.
For Instance, a typical WLAN interface configuration sample is given:
[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, you can see it is configured by default to Dynamic Host Configuration Protocol (DHCP) and dynamically assigns Internet Protocol (IP).
Wired Network Configuration
To modify DHCP to a static IP configuration for wired interfaces, you can create or edit /etc/systemd/network/10-eth.network file with the following contents:
[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 a static IP, reload or restart systemd-networkd using the following command:
or
Wireless Network Configuration
To modify DHCP to a static IP configuration for wireless interfaces, you can create or edit /etc/systemd/network/systemd/20-wlan.network file with the following contents:
[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 a static IP, simply reload or restart systemd-networkd using the following command:
or
After this, you can observe the static IP assigned to the corresponding interface accordingly as furnished in the following 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)
Related Topics
Boards
- SAMA5D29 Curiosity
- SAM9X75 Curiosity
- SAM9X60 Curiosity
- SAMA7G5-EK
- SAMA5D2-ICP
- SAM9X60-EK
- SAMA5D27-WLSOM1
- SAMA5D27-SOM1
Components
Summary
This article provided a comprehensive guide to configuring and using systemd, the advanced system and service manager now set as the default in Linux4SAM releases from 2023.10 onward. systemd’s key features include improved boot times, dynamic configuration, and effective resource management, along with practical instructions for managing services, viewing logs, and configuring network interfaces. The guide also detailed how to enable, disable, and monitor services, as well as how to set up both DHCP and static IP configurations for wired and wireless networks.