During the system boot sequence in Ubuntu, encountering the red diagnostic error [FAILED] Failed to start Apply Kernel Variables (unit systemd-sysctl.service) indicates that the Linux kernel configuration daemon was unable to apply low-level operating system parameters defined in your sysctl configuration directories. Because sysctl governs security flags, network socket buffers, memory swapping tendencies, and process limits, service failures can leave your server operating with unhardened or misconfigured networking. Resolving this issue involves diagnosing syntax errors and removing obsolete kernel keys.
Identify the Faulting Sysctl Directive via Systemd Journalctl
The systemd-sysctl service parses configuration files sequentially from /etc/sysctl.conf, /etc/sysctl.d/, and /usr/lib/sysctl.d/. The systemd journal records the exact configuration key that caused the parser to fail.
- Open a terminal session or connect via root console.
- Query the service status and recent error log:
systemctl status systemd-sysctl.service - Examine the diagnostic lines. To see all failures across the recent boot, execute:
journalctl -u systemd-sysctl.service -b --no-pager - Look for lines marked Couldn’t write ‘[value]’ to ‘[key]’: No such file or directory or Permission denied. Note the exact file and variable reported (e.g.
net.ipv4.tcp_tw_recycleorvm.nr_hugepages).
Test Sysctl Configuration Manually to Pinpoint Syntax Errors
Executing systemd-sysctl directly in your terminal allows you to test fixes and review individual configuration lines in real time.
- Run the sysctl application binary directly with administrative privileges:
sudo /lib/systemd/systemd-sysctl - Observe the output. Any invalid line will return an explicit error string indicating which configuration file contains the malformed parameter.
- Common culprits include deprecated kernel parameters that were permanently removed in newer Linux kernel versions (such as
net.ipv4.tcp_tw_recycle, which was removed in Linux kernel 4.12+).
Edit and Remove Obsolete Directives in /etc/sysctl.d/
Once you know which configuration key is invalid, opening the respective configuration snippet allows you to comment out or delete the obsolete entry.
- Check the configuration files in
/etc/sysctl.d/:ls -la /etc/sysctl.d/ - Open the file containing the problematic variable (e.g.
sudo nano /etc/sysctl.d/99-custom.conforsudo nano /etc/sysctl.conf). - Locate the failing directive and place a
#character at the beginning of the line to comment it out safely. - Save the file by pressing Ctrl + O and Enter, then exit with Ctrl + X.
- Re-run
sudo /lib/systemd/systemd-sysctlto confirm that all remaining directives apply with zero warnings.
Verify Kernel Module Dependencies for Network Parameters
Certain sysctl variables (such as net.bridge.bridge-nf-call-iptables used in Docker/Kubernetes) require specific kernel modules to be loaded before the sysctl key becomes accessible in /proc/sys/.
- If the error mentions net.bridge keys, load the bridge network filter module:
sudo modprobe br_netfilter - To make the module load automatically at boot, append it to
/etc/modules-load.d/modules.conf:echo "br_netfilter" | sudo tee -a /etc/modules-load.d/modules.conf - Restart the service:
sudo systemctl restart systemd-sysctl.service - Verify that
systemctl is-active systemd-sysctlreturns active.