Adding/Enabling rc.local in Debian 9 Stretch & 10 Buster

On recent releases of debian rc.local is deprecated, ideally you should create a system service for whatever it is you want to do but i’ve always used rc.local for odd one line commands. Running the commands below will re-add the rc.local functionality

****RUN AS ROOT OR PREFIX WITH SUDO****

COPY AND PASTE EACH BLOCK OF CODE IE NOT LINE BY LINE

Create service file

echo '[Unit]
Description=/etc/rc.local
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' > /etc/systemd/system/rc-local.service

Create rc.local file

echo '#!/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' > /etc/rc.local

Set file permissions
chmod +x /etc/rc.local

Enable rc.local service so it works at boot time
systemctl enable rc-local

Start the service
systemctl start rc-local

Check service stats
systemctl status rc-local

● rc-local.service – /etc/rc.local Loaded: loaded (/etc/systemd/system/rc-local.service; enabled; vendor preset: enabled) Drop-In: /lib/systemd/system/rc-local.service.d └─debian.conf Active: active (exited) since Mon 2021-08-23 09:17:15 BST; 4s ago Process: 6426 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
Aug 23 09:17:15 VIG690M systemd[1]: Starting /etc/rc.local… Aug 23 09:17:15 VIG690M systemd[1]: Started /etc/rc.local.

You may also like

Leave a Reply

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