How to enable rc.local shell script on systemd while booting Linux system

To enable an rc.local shell script on a systemd-based Linux system during boot, you can follow these steps:

  1. Create a file named “rc-local.service” in the “/etc/systemd/system” directory.
  2. 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

  1. Make the file executable by running the command “sudo chmod +x /etc/systemd/system/rc-local.service”
  2. 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”
  3. Enable the rc-local service by running the command “sudo systemctl enable rc-local”
  4. Start the service by running the command “sudo systemctl start rc-local”
  5. 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.

Leave a Comment