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>

Boot loader

  • Part of SystemD
  • Only EFI boot
  1. Verify if system is in UEFI mode by confirming presence of
    • efivar --list or ls /sys/firmware/efi/efivars.
  2. Mount the boot ESP drive
  3. bootctl install
    • Creates the EFI and loader directories.

Example of boot as the install directory:

/boot/
+-- EFI/
+-- loader/
|   +-- entries/
|   |   +-- archlinux.conf
|   |   +-- archlinux-fallback.conf
|   +-- keys/
|   +-- entries.srel
|   +-- loader.conf
|   +-- random-seed
+-- initramfs-linux.img
+-- initramfs-linux.img
+-- initramfs-linux-fallback.img
+-- vmlinuz-linux

Installing when arch-chroot

A work around is to install the boot loader from the non-chroot environment:

bootctl --esp-path=/mnt/boot install
arch-chroot /mnt
bootctl install

Note # If ESP path is mounted to a sub-directory then entry conf had problem finding the initramfs and vmlinuz.

  • /boot/esp as mount point
  • Next time, try ../vmlinuz-linux

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>

AP

Example configuration:

[Match]
Name=device_ap
WLANInterfaceType=ap

[Link]
RequiredForOnline=routable

[Network]
ConfigureWithoutCarrier=false

DHCPServer=true

IPv4Forwarding=true

Address=192.168.2.2/24

[DHCPServer]
ServerAddress=192.168.2.2/24

PoolOffset=2
PoolSize=20
EmitDNS=yes
DNS=1.1.1.1 4.4.4.4 8.8.8.8 ...

Debug, error, troubleshooting

Connected to AP but no Internet access

The device is connected to the AP and responds to ping. From the device:

  • ping an IP address if it fails then the problem is routing, NAT or firewall
  • ping a domain name if it fails then the problem is DNS

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

Clean DHCP server leases

  • /var/lib/systemd/network/dhcp-server-lease/<device name>

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

/etc/systemd/timesyncd.conf

systemctl status systemd-timesyncd systemctl start/restart systemd-timesyncd

timedatectl show-timesync --all

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 storage device

  • When the storage device in inserted then auto-mount it
  • When removing the device then auto-unmount it

Two methods:

x-systemd.automount

When accessing the mount point and the device is not available then content of the mount point is accessed, usually an empty directory, i.e. no error is raised.

For example, in fstab:

UUID=<UUID>  /<MOUNT-POINT> ext4  rw,noatime,discard,noauto,x-systemd.automount  0 1

In order for the change to take effect:

  • sudo systemctl daemon-reload
  • sudo systemctl restart remote-fs.target
  • sudo systemctl restart local-fs.target

unit.mount, unit.automount

When accessing the mount point and the device is not available then an error is raised.

On login, logout

  1. Create a unit file in /etc/systemd/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** ⚠️