...
exit 0
sudo cp rc.local /etc/rc.local
sudo cp rc.local.init.d /etc/init.d/rc.local
sudo chown root /etc/rc.local
sudo chmod 755 /etc/rc.local
sudo update-rc.d rc.local defaults
sudo /etc/init.d/rc.local start
sudo systemctl status rc-local.service
head -n1 /etc/rc.local
#!/bin/sh -e
53
In my case none of the instructions were a perfect solution. If you were as unlucky as me, try this detailed one
- Put all your executing code in a separate text file with an arbitrary name such as foo.sh and save it in an arbitrary place.
- Add
as first line of your code.#!/bin/sh - Try executing your foo.sh by
to check there are no errors at all.sudo foo.sh - Provide your /etc/rc.local script with full path and name of your created script after the sh command
sh '/path/to/your/script/foo.sh' - Remember to put the above line before the last line of code
at the end of the /etc/rc.local script.exit 0 - Check first line of /etc/rc.local to be
#!/bin/sh -e - Make your /etc/rc.local executable in case it is not already executable by
sudo chown root /etc/rc.local sudo chmod 755 /etc/rc.local - Check everything works fine by executing
sudo /etc/init.d/rc.local start - Test restart your system.
28
On newer Ubuntu versions
Check if the Compatibility service is loaded with
systemd is used and /etc/rc.local is not loaded always by default.Check if the Compatibility service is loaded with
systemctl status rc-local.service