# Raspberry Pi

# Installation

# Raspberry Pi Installation

## USB to Ethernet Adapter

[https://elinux.org/RPi\_USB\_Ethernet\_adapters](https://elinux.org/RPi_USB_Ethernet_adapters)

- Not the Amazon one
- TP-Link UE300 parfait ([https://www.tp-link.com/en/home-networking/usb-ethernet-adapter/ue300/v4/](https://www.tp-link.com/en/home-networking/usb-ethernet-adapter/ue300/v4/))

## Cases

For RPi 1 B : [https://www.thingiverse.com/thing:4384009](https://www.thingiverse.com/thing:4384009)

## Operating System

- Install the official installer tool `Raspberry Pi Imager`  
    Depending on the OS, find the adapted software.  
    [https://www.raspberrypi.com/software/](https://www.raspberrypi.com/software/)
- For a USB boot, follow these steps :
    
    
    - Format a SD card as FAT 32 (can be a small 256Mb partition)
    - Copy the latest `bootcode.bin` on the partition  
        [https://github.com/raspberrypi/firmware/raw/master/boot/bootcode.bin](https://github.com/raspberrypi/firmware/raw/master/boot/bootcode.bin)
        - If the RPi doesn't boot on the USB SSD disk after unplugging a USB keyboard, add a delay to the boot initialisation by creating a file named `timeout` on the same partition as *bootcode.bin*.  
            =&gt; Required with Kingston A400S and Startech SATA to USB.
- Run the installer tool and configure the future OS
    
    
    - Depending on RPI model, choose an adequate OS
        
        <table><thead><tr><th>RPI Model</th><th>Specs</th><th>OS Recommended</th><th>PSU</th></tr></thead><tbody><tr><td>RPi 1 B</td><td>700 Mhz - 256 MB</td><td>RPi OS Lite (32 bit)</td><td>&gt;= 2.5A</td></tr><tr><td>RPi 3 B</td><td>1.2 Ghz - 1 GB</td><td>RPi OS Lite (64 bit)</td><td>&gt;= 2.5A</td></tr></tbody></table>
        
        
        - To identify the model ```sh
            cat /sys/firmware/devicetree/base/model
            cat /proc/cpuinfo
            # Check RAM
            free -h
            
            ```
    - Set hostname (rpi-(dogname).local)
    - Enable SSH
        
        
        - Pub Key : Use the RaspPI one
    - Define user
        
        
        - name : rpi
        - pass : rpi
        - Set local settigns 
            - timezone: America/Montreal
            - Keyboard : ca
- SSH to board
    
    
    - Configure GPU memory to minimum  
        `sudo raspi-config nonint do_memory_split 16`
- Update the board completely
    
    ```sh
    sudo apt update
    sudo apt full-upgrade -y
    reboot
    
    ```
- Optimization

```sh
# Increase swap file
sudo dphys-swapfile swapoff
CONF_SWAPSIZE=1024 # in file /etc/dphys-swapfile
sudo dphys-swapfile setup
sudo dphys-swapfile swapon

# Disable HDMI
/usr/bin/tvservice -o
# Doesn't work with latest version which uses `DRM VC4 V3D driver`
# Modify the line of the driver to disbale HDMI :
dtoverlay=vc4-kms-v3d,nohdmi
# ref : https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README#L4571C13-L4571C13

# /boot/config.txt tweaks
# https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README

## Disable splash screen
disable_splash=1

## Disable Bluetooth
# https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README#L921
dtoverlay=disable-bt

## Disable WIFI if not used
# https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README#L938
dtoverlay=disable-wifi

## Disable HDMI
dtparam=hdmi=off
## SD card working freq (default 50MHz)
dtparam=sd_overclock=100
## Disable SD card check
dtparam=sd_poll_once=on
## Disable audio
dtparam=audio=off

# then disable services
sudo systemctl disable hciuart.service
sudo systemctl disable bluealsa.service
sudo systemctl disable bluetooth.service


```

- Install ZRAM  
    [https://github.com/novaspirit/rpi\_zram](https://github.com/novaspirit/rpi_zram)

[https://haydenjames.io/raspberry-pi-performance-add-zram-kernel-parameters/](https://haydenjames.io/raspberry-pi-performance-add-zram-kernel-parameters/)

## Overclocking

### Display frequencies

```bash
sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq # max
sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq # min
sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq # current

# Get live metrics
watch -n1 vcgencmd measure_clock arm
watch -n1 vcgencmd measure_temp

```

[https://picockpit.com/raspberry-pi/overclock-raspberry-pi/](https://picockpit.com/raspberry-pi/overclock-raspberry-pi/)  
[https://www.tomshardware.com/how-to/overclock-any-raspberry-pi](https://www.tomshardware.com/how-to/overclock-any-raspberry-pi)  
[https://www.raspberrypi.org/documentation/configuration/config-txt/overclocking.md](https://www.raspberrypi.org/documentation/configuration/config-txt/overclocking.md)

<table id="bkmrk-model-config.txt-set"><thead><tr><th>Model</th><th>config.txt settings</th></tr></thead><tbody><tr><td>Raspberry Pi 1 Model A &amp; B</td><td>arm\_freq=1000</td></tr><tr><td></td><td>core\_freq=450</td></tr><tr><td></td><td>over\_voltage=6</td></tr><tr><td></td><td>sdram\_freq=450</td></tr><tr><td>Raspberry Pi 3 &amp; Compute Module 3</td><td>arm\_freq=1300</td></tr><tr><td>source: picockpit (heatsink compatible)</td><td>core\_freq=500</td></tr><tr><td></td><td>over\_voltage=4</td></tr><tr><td></td><td>sdram\_freq=450</td></tr></tbody></table>

- Optional values to review  
    force\_turbo=1# Prevent regulation of speed down to 600Mhz when idling  
    boot\_delay=1 # Avoid sdcard corruption when force\_turbo is enabled

## Default configuration file

```bash
# Personal /boot/config.txt

# Presets RPI1 - Use at least a heatsink !!
# =======
# TYPE : ARM ; CORE ; RAM ; VOLT
# None :   700 ; 250 ; 400 ; 0
# Modest : 800 ; 250 ; 400 ; 0
# Medium : 900 ; 250 ; 450 ; 2
# High :   950 ; 250 ; 450 ; 6
# Tubro : 1000 ; 500 ; 600 ; 6

[pi1]
arm_freq=900 # CPU (default 700)
core_freq=250 # GPU (default 250) - Helps with L2 cache, better for RPI1
sdram_freq=450 # RAM (default 400)
over_voltage=2 # Overall voltage (default 0)

[pi3]
arm_freq=1200 # CPU (default 1200)
core_freq=400 # GPU (default 400) - Helps with L2 cache, better for RPI1
sdram_freq=450 # RAM (default 450)
over_voltage=0 # Overall voltage (default 0)

[all]
# Disable splash screen
disable_splash=1
# Disable serial
enable_uart=0
# Set GPU RAM to minimum (headless)
gpu_mem=16
# Give a small delay for the boot (better safe than sorry)
boot_delay=1
# Disable Bluetooth
dtoverlay=disable-bt
# Disable audio
dtparam=audio=off
# Disable HDMI
dtparam=hdmi=off
dtoverlay=vc4-kms-v3d,nohdmi
# Overclock SD Card controller in MHz - Enable this only if not booting on USB
# dtparam=sd_overclock=100 # default 50
# Disable SD Card polling once started
dtparam=sd_poll_once=on
## Disable WIFI if not used
# dtoverlay=disable-wifi


```

## More optimizations

[https://picockpit.com/raspberry-pi/raspberry-pi-zero-2-battery/](https://picockpit.com/raspberry-pi/raspberry-pi-zero-2-battery/)

## Resources

[https://feriman.com/raspberry-pi-optimization-hardware-and-software/](https://feriman.com/raspberry-pi-optimization-hardware-and-software/)  
[https://di-marco.net/blog/it/2020-04-18-tips-disabling\_bluetooth\_on\_raspberry\_pi/](https://di-marco.net/blog/it/2020-04-18-tips-disabling_bluetooth_on_raspberry_pi/)  
[https://pibenchmarks.com/latest/](https://pibenchmarks.com/latest/)

# Docker Installation

# Docker INstalltion

[https://docs.docker.com/engine/install/raspbian/#install-using-the-repository](https://docs.docker.com/engine/install/raspbian/#install-using-the-repository)

```sh
sudo su -
apt-get install ca-certificates curl gnupg

# Install Docker repository
curl -fsSL https://download.docker.com/linux/raspbian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg

echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/raspbian \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

apt-get update


# Install Docker engine
apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Check it works
docker run hello-world


```

- Configure your user into docker group

```sh
groupadd docker

```

# Tips, tricks and hacks

https://www.dzombak.com/blog/tag/raspberry-pi/