Image

Knowledge base → Adding the rc.local file in recent Debian versions

[Virtual servers]
Date of publication: 08.09.2022

To quickly add a script or command to the startup of the operating system in older versions of Debian, the /etc/rc.local file was used; in recent versions, this file no longer works. Sometimes you need to quickly add some command to the startup of the operating system. To enable this functionality, do the following:

1. Let's create a service file:

#vi /etc/systemd/system/rc-local.service

[Unit]

Description=/etc/rc.local ConditionPathExists=/etc/rc.local

[Service]

Type=idle ExecStart=/etc/rc.local start TimeoutSec=0 StandardOutput=tty RemainAfterExit=yes

[Install]

WantedBy=multi-user.target

2. Let's create the file /etc/rc.local

vi /etc/rc.local

#!/bin/sh -e

# # rc.local ## This script is executed at the end of each multiuser runlevel.

# Make sure that the script will "exit 0" on success or any other

# value on error.

#

# In order to enable or disable this script just change the execution

# bits.

#

# By default this script does nothing.

exit 0

3. Assign execution rights:

chmod +x /etc/rc.local

4. Let's add a service to autostart:

systemctl enable rc-local

5. We start the service:

systemctl start rc-local

6. Let's check the status:

systemctl status rc-local

Now you can add the necessary commands or scripts to the /etc/rc.local file before the exit 0 line.





No Comments Yet