The /etc/rc.local file is a script that runs commands automatically when your system boots up. It is often used to execute custom commands or start services that you want to run without needing to manually launch them after each boot.
Key Points about /etc/rc.local:
Runs at the end of the boot process:
- It is executed after most system services have started, making it an ideal place for customizations that need to be done once the system is ready.
Custom Commands:
- You can add any command or script that you want to run automatically.
- For example, setting CPU frequencies, starting a program, or mounting drives.
File Format:
- It is a shell script. The file is interpreted line by line as shell commands.
- The last line should always be
exit 0, indicating that the script ran successfully.
Permissions:
- The script should have executable permissions, but it’s typically set up this way by default.
Example of rc.local:
Here’s what a typical /etc/rc.local file might look like:
#!/bin/bash
# This is rc.local file
# Commands to run at startup
echo "powersave" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
# Set CPU governor to powersave
# Add your custom startup commands here
# For example, to start a program: /usr/bin/myprogram &
exit 0
Why Use /etc/rc.local?
- Persistence: Any command you add to
rc.localwill run automatically on every boot, meaning you don’t need to remember to run it manually. - Simplicity: It’s easy to add custom actions during the boot process, like adjusting settings or starting background processes.
However, modern Linux distributions may not use rc.local by default, especially if they are based on systemd. But it’s still present in many cases for backward compatibility. If it’s not working on your system, or you want to use systemd for more advanced control, you can create a custom systemd service instead.
Editing /etc/rc.local:
To edit this file, you can use a text editor like nano:
sudo nano /etc/rc.local
- Add the commands you want to run during startup.
- Make sure the last line is
exit 0, as this signals the end of the script.
After editing, save and exit (CTRL+X, then Y, then ENTER).
In summary, /etc/rc.local is a way to run custom commands during system startup. You can use it for tasks like setting CPU frequencies, launching services, or any action you want to automate at boot time.