During Ubuntu system boot or when restarting systemd services, users occasionally see a red failure banner stating Failed to start Apply Kernel Variables. Running systemctl status systemd-sysctl.service reveals that the service exited with an error code. This critical systemd unit is responsible for reading kernel parameters from configuration files in /etc/sysctl.conf and applying low-level operating system knobs. When an entry is malformed, references an uninstalled kernel module, or contains invalid syntax, the service fails. Repairing this ensures system stability and optimal performance.
Why Apply Kernel Variables Fails
The systemd-sysctl.service executes during early boot to write parameters into the /proc/sys/ virtual filesystem. Common failure causes include:
- Invalid Sysctl Syntax: Typographical errors, missing equal signs, or misplaced comments in
/etc/sysctl.confor drop-in files under/etc/sysctl.d/. - Parameters for Unloaded Modules: Directives referencing networking protocols (such as IPv6, bridge filtering, or IP forwarding) when the underlying kernel module has not yet been loaded.
- Deprecated Kernel Knobs: Updating to a newer Linux kernel release where older variables have been removed or renamed.
- Third-Party Application Tweaks: Database engines, VPN tools, or network optimisers injecting incompatible sysctl snippets.
Step 1: Test Sysctl Manually to Identify the Faulty Line
Running sysctl manually displays the exact line number and variable causing the error:
sudo /lib/systemd/systemd-sysctl
The command will parse all configuration files sequentially and print explicit error messages such as:
Couldn't write '1' to 'net/bridge/bridge-nf-call-iptables': No such file or directory. Note down the specific variable and configuration file reported.
Step 2: Inspect All Sysctl Configuration Sources
Kernel variables can be defined in multiple directories. Locate the offending parameter across all active configuration paths:
- List all sysctl configuration files evaluated by systemd:
sudo sysctl --system - Common paths to inspect include:
/etc/sysctl.conf/etc/sysctl.d/*.conf/run/sysctl.d/*.conf/usr/lib/sysctl.d/*.conf
- Use grep to find the exact file declaring the problem knob:
grep -rn "variable_name" /etc/sysctl.conf /etc/sysctl.d/
Step 3: Fix or Comment Out Broken Parameters
Once you identify the problematic line, open the file in a text editor with root privileges:
sudo nano /etc/sysctl.conf
Evaluate the issue:
- Missing Module: If the error involves
net.bridge.bridge-nf-call-iptables, thebr_netfilterkernel module must be loaded before sysctl runs. Addbr_netfilterto/etc/modules-load.d/modules.conf. - Deprecated Parameter: If a variable no longer exists in your current kernel version, place a hash symbol (
#) at the start of the line to comment it out safely. - Syntax Mistake: Ensure keys and values are separated by an equal sign without strange Unicode characters.
Step 4: Restart the Systemd Sysctl Service
After saving your changes, verify that the systemd service starts cleanly:
sudo systemctl restart systemd-sysctl.service
sudo systemctl status systemd-sysctl.service
The status output should now display a bright green active (exited) status with a message confirming that kernel parameters were applied successfully.
Common Problematic Sysctl Variables
| Sysctl Variable | Common Error Cause | Resolution |
|---|---|---|
| net.bridge.bridge-nf-call-iptables | br_netfilter module not loaded | Load module via /etc/modules-load.d/modules.conf |
| net.ipv4.ip_forward | Syntax typo or conflicting values | Ensure clean format: net.ipv4.ip_forward = 1 |
| vm.dirty_background_ratio | Value exceeds allowed kernel range | Adjust ratio to valid integer (e.g. 5 or 10) |
| fs.protected_fifos | Deprecated in custom/older kernels | Comment out or update kernel package |
Auditing sysctl configuration files and ensuring required kernel modules load on boot permanently resolves Apply Kernel Variables failures in Ubuntu.