Two ways to set the Raspberry Pi to start automatically at boot

There are two ways to set the Raspberry Pi to start automatically

1. Configure the rc.local file to set the startup items of the Raspberry Pi

Edit the /etc/rc.local file

sudo vi /etc/rc.local

Add the program to be executed before exit 0 in the file, pay attention to use the absolute path, as follows

python python /home/pi/example.py &

exit 0

Pay special attention, if the program is blocked, you must add the & symbol to run in the background, otherwise the system will not be able to start

Restart the system, it will take effect

sudo reboot

2. Create a new desktop file to set the Raspberry Pi startup items

This method is similar to the "Start" item in the "Start" menu of the Windows system, and the operation method is as follows:

Create a folder under /home/pi/.config with the name autostart

mkdir /home/pi/.config/autostart

Create a xxx.desktop file in this folder, the file name ends with .desktop, the name can be customized, and the content of the file is as follows:

[Desktop Entry]
Name=example
Comment=My Python Program
Exec=python /home/pi/example.py
Icon=/home/pi/example.png
Terminal=false
MultipleArgs=false
Type=Application
Categories=Application;Development;
StartupNotify=true

The Name, Comment, and Icon in the file represent the name, remarks, and displayed icon of the startup item, respectively. The specific values ​​can be set by yourself; Exec represents the command to call.

Restart the system, it will take effect

sudo reboot

 

Welcome to follow my WeChat public account "Big Data and Artificial Intelligence Lab" (BigdataAILab) for more information

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324522692&siteId=291194637