systemd - bunnyamin/bunnix GitHub Wiki

Debug

  • https://freedesktop.org/wiki/Software/systemd/Debugging/

  • journalctl -u <SERVICE>

    • -b<INTEGER> log from last boot. That is, 0 "current", 1 "previous", ... .
    • -e show logs from the last entry.
    • -f show the most recent entries and monitor output for new ones.
  • systemd-analyze verify <FILE> ensure that the service file is valid.

  • systemctl list-unit-files --type=service --state=enabled

Enable debugging log level for a service

  • systemctl edit <SERVICE>
  • Add new section [SERVICE] and define thereunder Environment=SYSTEMD_LOG_LEVEL=debug
  • Restart service systemctl restart <SERVICE>
  • Revert changes systemctl revert <SERVICE>
  • systemctl restart <SERVICE>

localectl

Control the system locale and keyboard layout settings.

  • localectl set-x11-keymap <layout>

NetworkD

  • systemd-networkd enables systemd-networkd-wait-online.service
  • Create configuration files in /etc/systemd/network/
  • Overview networkctl list
  • udevadm test-builtin net_setup_link /sys/class/net/<NAME OF INTERFACE TO TEST>
  • Create a WPA Supplicant for the wireless device.

Delete a started device (link): networkctl delete <LINK>

DHCP Server

SystemD NetworkD can handle IP forwarding instead of DHCPD

  • Start the DHCP Server DHCPServer=yes under the section [Network]
  • [DHCPServer] to configure, for example:
    • Poolsize=20

Netboot

[Match]
Name=<NETWORK INTERFACE>

[Link]
RequiredForOnline=False

[Network]
DHCP=yes
DHCPServer=true

IPForward=yes
IPMasquerade=both

Address=10.0.0.2/24

ConfigureWithoutCarrier=true

[DHCPServer]
PoolOffset=100
PoolSize=1

BootServerAddress=10.0.0.2

# 12 "Hostname"
# Hostname=
SendOption=12:string:<CLIENT HOSTNAME>

# 17 "Root Path"
SendOption=17:string:/srv/netboot

# EFI
#SendOption=67:string:netboot/x86_64-efi/core.efi
#BootFilename=/srv/netboot/grub/x86_64-efi/core.efi
BootFilename=grub/x86_64-efi/core.efi

# i386
#SendOption=67:string:netboot/grub/i396-pc/core.0
#BootFilename=netboot/grub/i396-pc/core.0
#BootFilename=/srv/tftp/netboot/grub/i396-pc/core.0

[DHCPServerStaticLease]
# Device #1
MACAddress=1a:2b:3c:4d:5e:6f
Address=10.0.0.101

#[DHCPServerStaticLease]
# Device #2
MACAddress=a1:b2:c3:d4:e5:f6
#Address=10.0.0.102

IP Forwarding

SystemD NetworkD can handle IP forwarding instead of /etc/sysctl.d/30-ipforward.conf

  • IPForward=yes under the section [Network]

Debug

Event Error Cause Remedy
Starting Network Configuration Network configuration changed, trying to establish connection Unknown Wait until the configuration is done. It is observed to take around 10-20 minutes.
networkctl Operational status is reported as degraded Invalid configuration
Starting Network Configuration Could not set hostname: Access denied Unknown Change the hostname manually with hostnamectl.
Attempting to connect Network is unreachable No gateway Under the section [Network], either add DHCP=yes or assign a static IP Address=192.168.1.9/24, Gateway=192.168.1.1, DNS 192.168.1.1.

Change MAC

Create a link configuration that lexically comes before "99". For example, 00-mac-wlv.link.

Example, match virtual devices.

  • Could not use MACAddress because "MAC address on the device already set by userspace.".
  • The #PermanentMACAddress matches the physical device, and from it all derived virtual interfaces.

Virtual Network Device

Event Error Cause Remedy
Initialization <interface>: Could not bring up interface: Name not unique on network The interface MAC address is not unique. Assign a new MAC address to interface.
Initialization WLAN interface exists, using existing without changing its parameters. The interface MAC address is not unique. Assign a new MAC address to interface.

Network interface

The order of the files for devices in /etc/systemd/network/ has not been tested. The following worked:

Routes

Address RouteMetric applies to connected route
Route   Metric deals with static route
DHCPxx  RouteMetric applies to routes learned from DHCP

WireGuard

  • Arch Linux Wiki WireGuard
  • 40-wan-vpn-wg.netdev
    • If the private key is provided in the configuration file or another file the permission of that file must be
      • chown root:systemd-network
      • chmod 0640
    • Note: changes to the content of the configuration files may require a restart of systemd-networkd instead of networkctl reload.
  • 41-wan-vpn-wg.network

WPA Supplicant

Create a configuration

  • /etc/wpa_supplicant/wpa_supplicant-wlp0s0.conf

  • /etc/wpa_supplicant/wpa_supplicant-nl80211-wlp0s0.conf

  • wpa_supplicant-<interface>.conf

  • /etc/systemd/network/10-wlp0s0.network

  • systemctl enable --now [email protected]

  • systemctl enable --now [email protected]

Debug

Event Error Cause Remedy
systemctl start ... sys-subsystem-net-devices-wlp0s0.device: Job sys-subsystem-net-devices-wlp0s0.device/start timed out.
Timed out waiting for device /sys/subsystem/net/devices/wlp0s0.
Dependency failed for WPA supplicant daemon (interface-specific version).
[email protected]: Job [email protected]/start failed with result 'dependency'.
sys-subsystem-net-devices-wlp0s0.device: Job sys-subsystem-net-devices-wlp0s0.device/start failed with result 'timeout'
Followed answer by WonderWoofy to question Managing WPA wireless with systemd-networkd ? on Arch Linux forums. The instruction # systemctl enable [email protected] seemed to have caused the problem; the .conf part. Remove .conf. That is, the name of the service has to be # systemctl enable [email protected].
systemctl start ... wpa_supplicant[14261]: nl80211: kernel reports: Match already configured

ResolveD

Even Error Cause Remedy
systemctl start resolvconf-pull-resolved start-limit-hit Unknown Edit the service file: After=network-online.target

TimesyncD

timedatectl

Display current system time.

  • # timedatectl status

Enable automatic NTP synchronization.

  • # timedatectl set-ntp true

Force NTP synchronization.

  • # systemctl restart systemd-timesyncd

Error, problem, troubleshooting

Error Cause Remedy
[FAILED] Failed to start Network Time Synchronization. Update timedatectl system time.

Unit

  • /etc/system/system/<UNIT>
  • systemd-analyze plot > overview.svg
  • systemctl reset-failed fix references to missing unit files

Auto-mount

When inserting the device, auto-mount it. When removing the device, auto-unmount it.

The distinct behavior from unit.mount, unit.automount is important. If attempting to access the mount point when the device is not mounted, the program accessing the mount point as is, for example, an empty directory.

unit.mount, unit.automount

Whether the device is inserted or not, when accessing the device, attempt to mount it. If the device is not inserted then the program attempting to access the device may return with error.

The distinct behavior from Fstab is important. If attempting to access the mount point when the device is not mounted, the program accessing the mount point will not find any valid storage, that is, not even an empty mount point.

On login, logout

  1. Create a unit file in /etc/system/user/<UNIT>
    • with ExecStart and ExecStop
    • If the execution requires root privileges then execute with =+ "full privileges". For example:
      • ExecStart=+/usr/bin/bash -c "echo 'heartbeat' > /sys/class/leds/red:power/trigger
  2. Enable the file globally systemctl --global enable <unit>

Note that the global unit file cannot have the same name as a system unit file.

List global unit files.

  • systemctl --global list-unit-files
⚠️ **GitHub.com Fallback** ⚠️