How to enable /etc/rc.local with SystemD on Ubuntu 20.04
To enable /etc/rc.local
with SystemD on Ubuntu 20.04, which does not include it by default, you can follow these steps:
- Create the
/etc/rc.local
file (if it doesn’t already exist) and make it executablesudo touch /etc/rc.local sudo chmod +x /etc/rc.local
- Add a shebang and
exit 0
to the file. Open/etc/rc.local
with a text editor and add the following content:#!/bin/bash
# Your startup commands here
exit 0
Any commands you want to run on startup can be added beforeexit 0
. - Create a SystemD service for
rc-local
:sudo nano /etc/systemd/system/rc-local.service
- Add the following configuration to the service file:
[Unit] Description=/etc/rc.local Compatibility ConditionPathExists=/etc/rc.local
[Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 StandardOutput=tty RemainAfterExit=yes SysVStartPriority=99
[Install] WantedBy=multi-user.target
- Reload SystemD and enable the service:
sudo systemctl daemon-reload sudo systemctl enable rc-local
- Start the
rc-local
service:sudo systemctl start rc-local
- Check if it’s running:
sudo systemctl status rc-local
If everything is set up correctly, /etc/rc.local
will now run on startup as a SystemD service on Ubuntu 20.04.