To enable an rc.local shell script on a systemd-based Linux system during boot, you can follow these steps:
- Create a file named “rc-local.service” in the “/etc/systemd/system” directory.
- Open the file in your text editor and paste the following content:
[Unit]
Description=/etc/rc.local compatibility
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
- Make the file executable by running the command “sudo chmod +x /etc/systemd/system/rc-local.service”
- Create a file named “/etc/rc.local” and add the commands you want to be executed on startup. Make sure the file is executable by running the command “sudo chmod +x /etc/rc.local”
- Enable the rc-local service by running the command “sudo systemctl enable rc-local”
- Start the service by running the command “sudo systemctl start rc-local”
- Verify the status of the service by running the command “sudo systemctl status rc-local”
The script defined in the “/etc/rc.local” should now be executed during the boot process, after all other services are started.