The systemd service rc-local.service always exists, and if rc.local resides and is executable, it is immediately pulled into multi-user.target. On systemd, synchronization with /etc/rc.local is provided by using a specific service called rc-local.service. While starting the Linux system, we can activate rc.local shell script functionality in systemd. Developers and Linux sysadmins have traditionally been using the shell script /etc/rc.local to call further scripts or commands once all services have been loaded. When Linux init switches to a multiuser runlevel, /etc/rc.local is usually called at the ending. However, in systemd, /etc/rc.local functionality is disabled by default. We may need to conduct a task on system startup while working on Linux systems, but maybe we do not want to go through the process of setting up sophisticated init scripts for the given task. Using /etc/rc.local
Pre-requisites
Following are the requirements that need to be fulfilled before the implementation of this article.
- Ubuntu 20.04 system installation and configuration
- Sudo user rights
- Strong internet connection
Method to enable and use /etc/rc.local on Ubuntu
To enable /etc/rc.local on Ubuntu 20.04, you have to follow all the steps described in this guide. You have to open the shell in the Ubuntu 20.04 system by either checking in the “Application” or utilizing the “Ctrl+Alt+T” shortcut key.
Initially, you have to create a file, i.e., rc.local file, in your system with the help of the following displayed command.
As we have used the keyword “sudo” in our command, we have to provide the password of the sudo user for file creation. Now we have to verify the status of the rc.local file. To verify the status, run the below-displayed command on the terminal window of your Ubuntu 20.04 system
The output will be almost the same as displayed in the above screenshot, and if you want to enable /etc/rc.local, you have to execute the flowing listed command displayed in the screenshot.
The output might come up with the same as displayed above and has some sort of error. As you will see in the aforementioned screenshot, there is no [Install] part in the unit file. As a result, Systemd is unable to enable it. First, we must create a file by running the command below.
After executing the command, the created file will be opened automatically as shown in the attached image. Initially, there will be no content in the file. You have to insert the same content that is shown in the below image.
Save the file using “Ctrl+S” and quit it using the “Ctrl+X” shortcut key. To ensure that the /etc/rc.local file is executable, perform the following command on the terminal of Ubuntu 20.04.
There will be no output displayed after the execution. Beginning with Ubuntu 16.10, the /etc/rc.local file is no longer included. The following appended command can be used to create the file.
The output will be almost the same as shown in the above-attached screenshot. Now, we have to enable service by using the below-displayed command.
The output of the command will be alike to the one displayed above. Now the time has come to start the service with the help of the following listed command.
The command will start the service effectively. You can confirm the status by the execution of the following command.
The status is now highlighted in the image as “Active“.
Conclusion
In this guide, we have covered what the /etc/rc.local file is and how and when to utilize it. We have explained to you the method to enable it and use it in Ubuntu 20.04 Linux system. We hope you found this guide to be informative for your work.
Discover more from Ubuntu-Server.com
Subscribe to get the latest posts sent to your email.