Skip to content

Instantly share code, notes, and snippets.

@joanroig
Last active May 25, 2021 20:26
Show Gist options
  • Save joanroig/1574f8a29297ddcc06a223507aa2c37e to your computer and use it in GitHub Desktop.
Save joanroig/1574f8a29297ddcc06a223507aa2c37e to your computer and use it in GitHub Desktop.
Raspberry Pi 24/7 setup
@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@lxterminal -e /home/pi/startup.sh
@xscreensaver -no-splash
@point-rpi
#!/bin/bash
mkdir -p /home/pi/.config/lxsession/LXDE-pi/
cp autostart /home/pi/.config/lxsession/LXDE-pi/
cp startup.sh /home/pi/
chmod +x /home/pi/startup.sh

Raspberry Pi 24/7 setup

Easy steps to recreate a reliable Raspberry Pi running 24/7 which:

  • Will be able to restart tasks after a power outage
  • Periodically saves backups of selected folders in Google Drive
  • Can be easily restored after a SD card failiure
  • Can be accessed remotely

Preparing the SD card

Format the SD card using the Raspberry Pi Imager from https://www.raspberrypi.org/software/ and the raspbian image from https://www.raspberrypi.org/downloads/raspbian/ If you restore a prepared system, you probably don't need to follow next steps.

Updating Raspbian OS and setting it up

  • Raspbian will ask you for another password, so set it.
  • It will ask you for the country, timezone, WiFi, etc. so set them all. Recommended language is EN and recommended country is US for compatibility reasons.

Disable bluetooth if you're on Raspberry Pi 3 and you'll not use it. Then, go to Preferences > Raspberry Pi Configuration:

  • In System, change the resolution to match the resolution of yout monitor and disable overscan (it will prevent resolution problems when the raspberry restarts while the monitor is turned off).
  • In System, enable wait for network.
  • In Interfaces, enable SSH.

Click on the CPU graphic on top right, and then click "Add / Remove panels". Add your desired information about the system, I personally add:

  • Temperature Monitor
  • Resource Monitors (for RAM usage, select Preferences > Display RAM usage)

Raspbian will try to automatically update itself during the setup, if you need to update it manually launch those commands:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get clean

Remote access

For remote access within the same network, activate the VNC interface in Preferences > Raspberry Pi Configuration:

  • In Interfaces, enable VNC.

For remote access outside the same network, install AnyDesk:

Disable power led permanently (the red led is not really necessary and produces too much light)

Disable the power and status leds guide

Edit the config and add the code block:

sudo nano /boot/config.txt

# Disable the PWR LED.
dtparam=pwr_led_trigger=none
dtparam=pwr_led_activelow=off

Improve SD lifespan

Relocate directories to RAM

To relocate highly used directories into RAM, edit the next file and add the code block in the end:

sudo nano /etc/fstab

tmpfs /tmp tmpfs defaults,noatime,nosuid 0 0
tmpfs /var/log tmpfs defaults,noatime,nosuid,size=16m 0 0
tmpfs /var/tmp tmpfs defaults,noatime,nosuid 0 0

You can also modify the ext4 partition to reduce the writings into the SD (use your current PARTUUID!).

PARTUUID=XXXXXX-02 / ext4 defaults,noatime,commit=600 0 1

Disable Swapfile

Execute those commands:

sudo su
dphys-swapfile swapoff
dphys-swapfile uninstall
apt-get -y remove dphys-swapfile

Setting up all tools

Now you'll be able to access into Raspberry using FTP, use a program like Filezilla to transfer files like installable packages. Get the IP of the machine placing the mouse on the top-right network icon. Remember to use the user 'pi' and the password you've entered on system setup.

Auto-run LXTerminal at startup for launching scripts

Note: You can run install-autostart.sh from the SETUP folder to install the autostart automatically:

chmod +x install-autostart.sh
./install-autostart.sh

Create LXDE-pi directory and its parents, and copy the autostart file into it. Then copy the startup.sh file into the home and give it execute permission, otherwise it will fail.

mkdir -p /home/pi/.config/lxsession/LXDE-pi/
cp autostart /home/pi/.config/lxsession/LXDE-pi/
cp startup.sh /home/pi/
chmod +x /home/pi/startup.sh

The autostart file will run on system boot, and it will call startup.sh to execute whatever is inside it. Put inside it what you want to be executed (in my case I execute multiple independent terminals).

References:

https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=65607&sid=a1e7043538576960f65ae9e996dcfe29&start=25 https://www.raspberrypi.org/forums/viewtopic.php?t=277004

#!/bin/bash
x-terminal-emulator -e bash -c 'cd ~/setup/;python3.5 sendtelegram.py;exit;bash'
x-terminal-emulator -e bash -c 'cd ~/setup/;python3.5 whatever.py;bash'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment