Skip to content

Instantly share code, notes, and snippets.

@nickscript0
Last active May 16, 2022 00:20
Show Gist options
  • Save nickscript0/38f3467821fae004e7541dfac7aa2fec to your computer and use it in GitHub Desktop.
Save nickscript0/38f3467821fae004e7541dfac7aa2fec to your computer and use it in GitHub Desktop.
Raspberry Pi 3 - Initial Setup with Raspbian

Initial Raspberry Pi 3 Setup with Raspbian

Flash Raspbian and connect to network via ethernet

  1. Download the latest Lite version from https://www.raspberrypi.org/software/operating-systems/
  2. Use the "balenaEtcher" app (https://www.balena.io/etcher/) to flash the iso to a microSD card
  3. Copy a blank file named ssh to the boot partition (the root folder of the microSD card)
  4. Power up the Raspberry PI, find it's IP in your router's connected devices, and ssh pi@<ip> (password: raspberry)

Initial Hardware and Raspbian configuration

  1. sudo raspi-config
  2. System Options > Change user password
  3. System Options > Change hostname
  4. Localisation Options > Set Timezone
  5. Advanced options > Expand Filesystem

Update OS, Disable WiFi and Bluetooth (assuming Ethernet only connection)

  1. Update OS
    sudo apt-get update
    sudo apt-get clean # Was necessary to resolve hanging on "waiting for headers"
    sudo apt-get upgrade
    sudo apt-get dist-upgrade
    
  2. [Optional] If apt-get install is hanging on waiting for headers switch your repo to this one
    # Modify /etc/apt/sources.list as follows
    deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi
    #deb http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi
    
  3. Disable Wifi and Bluetooth (https://raspberrypi.stackexchange.com/a/62522)
    # Add the following lines to /boot/config.txt
    dtoverlay=pi3-disable-wifi
    dtoverlay=pi3-disable-bt
    
    1. Disable systemd service that initializes Bluetooth Modems connected by UART.
      sudo systemctl disable hciuart
      

Install Plex Server

In a nutshell

echo deb https://downloads.plex.tv/repo/deb public main | sudo tee /etc/apt/sources.list.d/plexmediaserver.list
curl https://downloads.plex.tv/plex-keys/PlexSign.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install plexmediaserver

From https://support.plex.tv/articles/235974187-enable-repository-updating-for-supported-linux-server-distributions/

More Docs

More official docs: https://forums.plex.tv/t/read-me-first-about-server-armv7-and-armv8-ubuntu-debian/226567.

Extend the life of your SD Card

Put /var/log in a RAM folder (that is only written to disk daily)

# From https://github.com/azlux/log2ram#install
echo "deb [signed-by=/usr/share/keyrings/azlux-archive-keyring.gpg] http://packages.azlux.fr/debian/ bullseye main" | sudo tee /etc/apt/sources.list.d/azlux.list
sudo wget -O /usr/share/keyrings/azlux-archive-keyring.gpg  https://azlux.fr/repo.gpg
sudo apt update
sudo apt install log2ram

Increase the ext4 journaling from default 5s to 6h

Update /etc/fstab as follows and reboot

# Reduce ext4 journaling to every 6h (21600s) by adding commit=21600 to /etc/fstab to the root filesystem
PARTUUID=600410ff-02  /               ext4    defaults,noatime,commit=21600  0       1

Monitor disk usage

# Run iotop package and monitor for which processes are writing over time
sudo apt install iotop
sudo iotop -aok

# jbd2/mmc.. are from ext4 journaling and should only be seen every 10min now

Network Shared folder to MacOS (netatalk)

sudo apt-get install netatalk
# Optional add the line: /mnt "Mount"
# at the bottom of sudo nano /etc/netatalk/AppleVolumes.default
# then 
sudo /etc/init.d/netatalk restart

Maintenance

Update to latest packages

sudo apt update

# Optional list packages that have updates
sudo apt list --upgradable

# This is the most complete command to keep things up to date but will remove packages
# as needed to upgrade (unlike apt upgrade), so must carefully review the planned removed packages.
sudo apt full-upgrade

# To retrieve disk space: also 1. cleanup unused packages, 2. cleanup apt cache
sudo apt autoremove && sudo apt clean

Update to latest firmware

# They have warnings saying not to do this unless necessary, lots of sites still recommend it
sudo rpi-update

Utilities

Nice ARM docker cli speedtest

# https://hub.docker.com/r/marcomontel/rpi-speedtest-cli
docker run -e PYTHONHTTPSVERIFY=0 --rm marcomontel/rpi-speedtest-cli

Managing a Pi Connected to WiFi and Ethernet on different networks

# Check whether wifi or ethernet is used. Whatever is the top of this list
route -n

# Stop the ethernet interface until reboot (to force it to use wlan0)
sudo ifconfig eth0 down

# Make the wlan0 (wifi) interface higher priority than eth0
# Add the following to /etc/dhcpcd.conf, as eth0 is metric 202, the lower the metric the higher the priority
interface wlan0
metric 100

Raspberry Pi Commands

Built-in commands here: https://www.raspberrypi.org/documentation/raspbian/applications/

# Check temperature (VideoCore GPU Temperature)
/opt/vc/bin/vcgencmd measure_temp

# GPU Memory
/opt/vc/bin/vcdbg reloc stats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment