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:

  1. Create the /etc/rc.local file (if it doesn’t already exist) and make it executable

    sudo touch /etc/rc.local sudo chmod +x /etc/rc.local

  2. 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 before exit 0.
  3. Create a SystemD service for rc-local:

    sudo nano /etc/systemd/system/rc-local.service

  4. 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

  5. Reload SystemD and enable the service:

    sudo systemctl daemon-reload sudo systemctl enable rc-local

  6. Start the rc-local service:

    sudo systemctl start rc-local

  7. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *