CentOS

How to Use Rc.local on CentOS 8

The RC stands for “run commands” and usually the rc phenomenon is practiced by system administrators to run a command at system boot. The “rc.local” is a script that contains the commands to be exercised at system startup.

In Linux, the system administrators may wish to conduct a system test before startup. In such a situation, the admin must put the relevant commands inside the rc.local file to make their execution possible at system startup.

If you are curious about using the rc-local file on CentOS 8; you are in the right place.

How to use rc.local on CentOS 8

This section provides various steps that are recommended to make use of the rc.local file on CentOS 8. Open up the CentOS 8 terminal and start following the commands.

Step 1: Check the status of “rc-local” service via the following command.

$ sudo systemctl status rc-local

The output shows that the service is inactive and dead.

At this stage if you would try to enable the rc-local service, it will not throw an error that “unit files have no install section”. For this create and rc-local file inside systemd as we did here:

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

Copy and paste the following content inside it; press “CTRL+S” and “CTRL+X” to save and exit the editor.

[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

After doing so, make the file executable as we did here.

$ sudo chmod +x /etc/rc.local

Enable and start the rc-local service with the use of commands written below.

$ sudo systemctl enable rc-local

Meanwhile, start the service and also get the status by using the following command.

$ sudo systemctl start rc-local
$ sudo systemctl status rc-local

Step 2: Access the “/etc/rc.local” file using your text editor. To do so, we made use of nano editor as shown below:

$ sudo nano /etc/rc.local

Once the file is opened; you can write commands at the end of the file (without the sudo keyword). All these commands will be executed at the startup of the PC. We have created a directory and a text file inside that directory as can be seen in the image above.

Once done, it is recommended to restart the rc.local service in the following manner.

$ sudo systemctl restart rc-local

After rebooting the system, you would observe that the required directory and the file would be created at the specified location.

Note: If you are not getting the required result then try making the following file executable.

$ sudo chmod +x /etc/rc.d/rc.local

Conclusion

The rc.local file contains commands that are supposed to be executed at system startup. This article provides a procedural guide to make use of the rc.local file on CentOS 8. The commands that may not put the machine at risk can be used at the startup. For instance, if an application service is started using an rc.local file, it would be hard to shut it down safely. Therefore, an application service or network configuration must not be carried out using the rc. local file.

About the author

Adnan Shabbir