Certain Linux distributions that use SystemD such as Ubuntu 20.04 may not allow you to run /etc/rc.local
when the system is booting. In this tutorial we will go through how to allow /etc/rc.local during system boot on Ubuntu 20.04 Focal Fossa. As of Ubuntu 16.10 Xenial, the official distribution does not contain the /etc/rc.local file.
Requirements:
Ubuntu 20.04
VIM or a similar text editor
What will you learn?
You will learn how to enable /etc/rc.local on Ubuntu 20.04 Focal Fossa during startup
Tutorial
1. Open the Terminal on Ubuntu.
Type the following command in order to switch to the root user, you will need to type in a password when prompted:
sudo su
systemctl status rc-local

If you enable /etc/rc.local to run on system boot using the command
systemctl enable rc-local

As you may have already read, it is not possible to enable rc-local at startup using SystemD enable on Ubuntu 20.04. Therefore we have to do this another way.
We will need to manually create a SystemD service which will start at system boot.
vim /etc/systemd/system/rc-local.service
Press I to input the following text:
[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
Once you have finished press ESC and then type:
:wq!
This saves the file using the VIM editor.
Now we will need to edit the /etc/rc.local file. Issue the following command and press Enter
vim /etc/rc.local
Press I and paste in the following, this ensures that the script is bash executable, all bash scripts shoul have this at the top:
#!/bin/bash

Once you have finished press ESC and then type in order to save:
:wq!
We will now need to append permissions to make the newly created file executable. Issue the following command and press Enter.
chmod +x /etc/rc.local
After that, enable the service on system boot:
systemctl enable rc-local

Now let’s reboot the system and check if the rc-local SystemD service is working. Proceed by typing the following command and press Enter:
reboot

When your system has booted up again, issue the following commands:
sudo su systemctl status rc-local

Now rc-local is enabled on startup when using Ubuntu 20.04 Focal Fossa.
forward from:https://linuxmedium.com/how-to-enable-etc-rc-local-with-systemd-on-ubuntu-20-04/
Leave a Reply