Skip to content

Raspberry Pi Notes

chris edited this page Apr 5, 2023 · 71 revisions

Contents

SD card Setup

  1. Download the Raspbian distro from the downloads page.
  2. Use Etcher to burn the .img to the SD card.

SD card Setup OpenSSH

  1. Place an empty file named ssh on the smaller boot partition after using Etcher to write the OS to the SD card. see for more info.
touch /path/to/boot/volume/boot/ssh

OpenSHH superuser login

To permit or allow superuser login for ssh

vim /etc/ssh/sshd_config

Add the below line to the above mentioned file

PermitRootLogin yes

First Login

The default user for Raspbian is pi and the password is raspberry.

If there is no keyboard present, the pi can be directly connected to the router via ethernet, and a virtual keyboard can be installed if SSH has been enabled.

Initial $USER setup

After logging into the pi, a .bash_profile can be setup to add aliases that should work with the default bash shell on the pi. The .bash_profile should be initialized via UART and SSH.

Optinal Remove unneeded programs

To remove the wolfram-engine and libreoffice components from a Raspbian install

sudo apt-get remove --purge wolfram-engine libreoffice* nuscratch

IMHO both packages are bloat for a basic Raspbian install and are things I will never use.

Working with Raspbian

working with raspbian / installing fish-shell from git source

working with raspbian / installing neovim from git source

Upgrading Raspbian > Going from Stretch to Buster

To upgrade Raspbian from stretch to buster

  • Edit the below to files, and change the word stretch to buster and run the following commands credit
/etc/apt/sources.list
/etc/apt/sources.list.d/raspi.list
sudo apt update
sudo apt dist-upgrade

To get a temperature reading of the CPU, GPU and RAM on a Raspberry Pi running Raspbian.

vcgencmd measure_temp

Mounting filesystems with non-root user

Traditionally mounting filesystems on a *nix/BSD system has been reserved for the root user for security reasons. That said, a few options to allow non-root users to mount filesystems ie. a removable SD card or USB thumb drive / disk are available.

  • setup entries in /etc/fstab
  • setup fuse filesystem in userspace to allow users to mount personal / custom filesystems on a per user basis without compromising the initial integrity of the system.

To install fuse on a Debian based distro ie. Raspbian

sudo apt update; sudo apt install fuse3

❗️ Unfortunately there isn't a fuse driver that supports writing to hfs{+} filesystems.

Benchmarking on a Raspberry Pi running Raspbian

  1. Install sysbench via apt
sudo apt-get install sysbench
  1. To run the CPU benchmark
- sysbench --test=cpu --cpu-max-prime=20000 --num-threads=4 run
+ sysbench cpu --cpu-max-prime=20000 --threads=4 run  

Working with DTV turners on a Raspberry Pi

As of January 12, 2019 I own a WinTV-dualHD DTV turner with a USB interface made by hauppauge Hauppauge provide a suite of utilities for Microsoft Windows 7 and 10 for watching over the air digital TV and along with recording TV and measure signal strength. Unfortunately, as of January 12, 2019 there appears to be little to no support for macOS, that said, there does seem to be support for GNU+Linux distrobutions.

Working with TigerVNC Server & Client

To setup a TigerVNC Server on Raspbian

  1. Install TigerVNC
sudo apt-get update
sudo apt-get install tigervnc-common tigervnc-standalone-server tigervnc-viewr

To start a TigerVNC on Raspbian

vncserver -interface 192.168.[ο£ΏΓΌΓ₯Γ ].[ο£ΏΓΌΒΆΓ‘]

To connect to a TigerVNC server from macOS over SSH

  1. Create a ssh tunnel to the TigerVNC port
ssh -NTf -L 5901:localhost:5901 [unix_user]@[vnc_server_ip_or_hostname.local]
  1. Launch the VNC client on macOS
vncviewer vnc_server_ip:[PORT]

Gaming on a Raspberry Pi

search terms retro, gaming, raspi, raspberry pi, raspberrypi, emulation station, emulationstation, emulator

EmulationStation

  • β€šΓΉΓ³Γ”βˆΓ¨ EmulationStation may not be able to run from within an existing X Server session, and may require being launched from a non X based terminal.

  • RetroPie maintains an updated fork of EmulationStation hosted on GitHub.

RetroPie

  • RetroPie can be manually installed to coexist with an existing install of Raspbian. See for instructions on setting up RetroPie on Raspbian.

Working with a Playstation 4 Controller

To put a Playstation 4 controller, ie. model CUH-2CT2U into Bluetooth pairing mode

Press and hold the Playstationβ€šΓ‘Β’Γ”βˆΓ¨ button and the SHARE button on the controller simultaneously until a blue light starts flashing

Change the hostname of a Raspberry Pi

  1. Edit /etc/hosts
  • change the entry with 127.0.1.1 [mr-fancy-42-hostname]
  1. Edit /etc/hostname
  • change raspberrypi to [mr-fancy-42-hostname]

An alternative way to change the hostname on a Raspberry Pi running Raspbian is to use raspi-config

sudo raspi-config

Hostnames can not contain underscores _

Working with networking and Raspbian Stretch

Running Raspbian based off of Debian Stretch, the below file should be edited for working with network settings.

/etc/dhcpcd.conf

The above mentioned file can be used to setup static IP's for both the ethernet and wireless interfaces for a Pi.

If running an older version of Raspbian, ie. Wheezy then edit the below file

/etc/network/interfaces

To restart the entire networking stack or just the DHCP portion

sudo systemctl restart networking
sudo systemctl restart dhcpcd

For more info about networking on Raspbian see and

Update date and TZ on a Raspberry Pi running Raspbian

If the Raspberry Pi is connected to active internet connection

sudo raspi-config
  1. Select the Country and then a timezone within the country under the localization settings.

Connecting to a UART interface on a Raspberry Pi running Raspbian from macOS

πŸ’‘ If issues arise with connections / terminations using the seed studio, or you forget which wire go where, remember the underside of the bus pirate has the pins labeled on the PCB as described in the image below.

Make sure the below line is in the config.txt

enable_uart=1

Edit the /boot/cmdline.txt and add or change

console=serial0,115200 console=tty1

To see kernel boot messages through the console, ie. a verbose boot sequence when booting the pi, remove quiet from /boot/cmdline.txt

  • asciinema > connecting to a Raspberry Pi using a Bus Pirate and screen.

Raspberry Pi GPIO UART Pins

raspi-gpio-uart-pins

The UART interface on a Raspberry Pi needs be enabled first before being able to use it as a serial console. The interface can be enabled using raspi-config

If a properly configured FTDI board is connected to a macOS system, and jumper wires are connected to the correct GPIO pins of the Raspberry Pi, then a serial connection can be established using screen

To connect to a Raspberry Pi UART using screen on macOS

screen /dev/tty.usbserial-[SERIAL_NUMBER] 115200

If properly connected one should be presented with a login prompt.

Working with screen

To detach from a screen session

control+a then d

To kill a screen session

control+a then k

To attach to a dettached screen session

screen -r

Resizing partitions on a SD card running Raspbian

This is extremely useful when building custom Linux kernels for Raspbian

The default Raspbian Stretch image has a 50MB boot partition, which inadequate for building custom Linux kernels for Raspbian.

Disclaimer resizing the boot partition is a total pain the ass, that said, here is my shitty explanations on to get it done.

  1. After setting up Raspbian on an microSD card the default size for the boot partition is 50MB

This guide will attempt to explain on how to resize the root and boot partitions for Raspbian Stretch.

  1. Start Raspbian on a Raspberry Pi of some sort then edit the following two files.
/boot/cmdline.txt
/etc/fstab

/etc/fstab can not be accessed from the root partition on macOS out of the box, ie. macOS will need to have support for ext partitions. That said, macOS does support writing to ext* file systems.

  1. Change /etc/cmdline.txt entry from root=PARTUUID=[HASH]-02 to
root=/dev/mmcblk0p2

A default Raspbian install stores the root partition on the second partition of the uSD card.

  1. Change /etc/fstab PARTUUID entries to reflect the /dev/mmcblk0p[1-2] entries

❗️ When specifying block devices for fstab entries make sure to REMOVE the PARTUUID at the beginning of the entry using a block ID.

  1. After the saves have been made, attempt to boot the Raspbian system on a Pi to make sure the changes are working properly, ie. the Pi can boot.

Update August 2019

  • backup the boot partition before resizing / shrinking the root partition.

The default boot partition of a Raspbian install is formatted with a FAT32 filesystem.

Simply copy the contents of the files somewhere safe

cp -ivr /Volumes/boot/* /path/to/backup-of-raspbian-boot-vol/

After the boot partition has been backed up, delete the partition, then resize the root partition to the desired size.

❗️ A MacBook with an SD card can be used in conjunction with VirtualBox to boot a GParted ISO and mount the uSD card to delete the boot partition and resize the root partition. see for more details on accessing the SD card port of a MacBook Pro from within a Virtual Machine.

  1. Resize the root partition to the desired size.

Personally I changed the default boot partition from 50MB to 1GB

  1. Shrink the root partition using GParted

  2. Mount the boot partition

mount /dev/sd[X]1 /path/to/some/mount/point
  1. Copy the contents of the boot partiton to a place on the local file sytem.
cp -riv /path/to/backed/up/boot-volume/* /path/to/uSD/new/boot/volume

The above steps can be peformed on a Raspberry Pi itself if two uSD cards and a uSD card reader is present. Also GParted can be launched with X11 forwarding if need be.

Raspberry Pi Soft-blocking

To get a list of soft-blocked devices on a Raspberry Pi

sudo rfkill list

To unblock all soft-blocked radio devices

sudo rfkill unblock all

To soft-block a radio, ie. Bluetooth or Wi-Fi on a Raspberry Pi

sudo iwconfig wlan0 txpower off

Disable Bluetooth on Raspbian

To permananetly disable bluetooth and internal wifi radios on Raspbian

  1. Edit /etc/modprobe.d/raspi-blacklist.conf
  2. Add the below lines to the file.
blacklist btbcm
blacklist hci_uart

blacklist brcmfmac
blacklist brcmutil

Raspberry Pi wireless networking

If adding an additional access point to connect to ie. connecting to a new router and using raspi-config then wpa will need to be restarted.

wpa_cli -i wlan0 reconfigure

mDNS Raspbian Support

Raspbian based off of Debian Stretch 9.9 should come with mDNS support of the box, but if the hostname is changed, then more than likely the pi will need to be rebooted. mDNS support and manually be added to Raspbian

sudo apt update
sudo apt install avahi-daemon
echo "setup hostname using `rasp-config`"

To bring up a wireless interface on Raspbian Linux

sudo ifconfig wlan0 up

To bring down a wireless interface on Raspbian

sudo ifconfig wlan0 down

Building a cross compile toolchain for Raspbian on macOS

A sparse bundle disk image label can be renamed, but the image must first be mounted.

hdiutil attach /path/to/my.sparseimage
diskutil rename old_label new_label
hdiutil detach new_label

Then the sparseimage can be mounted or attached using the new label name.

xtools TODO

  • continue working on steps to get a xtools toolchain built for Raspbian on macOS

Build a Cross-Compile Toolchain for Raspi using docker

Useful Links for building a Cross-Compile toolchain

Setting up an additional apt source

dirmngr will need to be installed first before apt-key can add a new key to the keyring.

sudo apt-get install dirmngr

To install an additional key from a server

sudo apt-key adv --keyserver hkp://keyserver.mr-fancy.com:80 --recv-keys 4242424242424242

Example

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 379CE192D401AB61

Using Raspberry Pi as a DVR

Software

Tvheadend Installation

To install the bintray version Tvheadend on Raspbian stretch running on a Raspberry Pi

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 379CE192D401AB61
sudo apt-get install dirmngr
echo "deb https://dl.bintray.com/tvheadend/deb DISTRO REPO-COMPONENT" | sudo tee /etc/apt/sources.list.d/tvheadend.list
sudo apt-get update
sudo apt-get install tvheadend

For more info on installing a binary version of Tvheadend see

Tvheadend Post Installation

To access the tvheadend server and configure the app

http://localhost:9981

or

http://hostname-of-raspi.local:9981

Using Raspberry Pi as a router

Working with pihole

tags
  • #pihole #raspberry pi #raspberrypi #web #webinterface #admin #interface

To access the pihole web admin interface

http://IP_ADDRESS_OF_RASPBERRYPI/admin

Example

https://10.0.1.42/admin

Hardware

For my particular use case I purchased a TP-Link Archer T9UH AC 1900 Wireless USB adapter with a hardware revision of 1, ie. US/1.0

  • Chipset Realtek 8814AU

Various tp-link products can have different hardware revisisions see

There is an official tp-link Linux dirver that can be found here however I was unable to get it to build for Raspbian running a 4.19.x-v7+ kernel.

To get the above mentioned hardware working with a semi modern Linux kernel checkout the following GitHub repo

https://github.com/aircrack-ng/rtl8812au

The README in the repo contains instructions to build for both a Raspberry Pi 3b and 3b+

❗️ Modern versions of the driver have been having issues with the Archer wireless card(s) and until a fix is applied to the driver, it is suggested to checkout from

https://github.com/aircrack-ng/rtl8812au/commit/0eda114fda2b66682deff77b1259c0aa6d2e6206

See this issue #327

❗️ The driver currently also requires being built using a 32bit toolchain as a 32bit kernel module even for rpi 3b+ and rpi 4.

Useful Links

Working with ext filesystems on macOS

To enable read & write support ext filesystems in macOS

The above GitHub repo provides a rather lengthy install process for setting up ext fuse support on macOS; because of the lengthy setup procedure, I have forked the project and wrote a build script for macOS High Sierra.

To mount an ext file system with the newly built tools

sudo fuse-ext2 /path/to/block/device/partition /path/to/mount/point -o rw+,allow_other,uid=[USER_ID],gid=[GROUP_ID]

Ex

sudo fuse-ext2 /dev/disk2s2 ~/mnt/ext-fs -o rw+,allow_other,uid=501,gid=20

The above command will mount the ext file system stored on the SD card for a typical Raspbian install on macOS with a standard user. To find the user ID for a particular user on macOS

id [USERNAME]

Now the filesystem should be available for reading and writing ✧*q٩(ΛŠα—œΛ‹*)و✧*q

To umount the filesystem

sudo unmount ~/mnt/ext4

To list the available ext filesystems on macOS

diskutil list

To unmount the previously mounted filesystem

umount /Users/capin/mnt/ext4

Firefox on Raspbian

Installing firefox quantum

echo "deb http://ppa.launchpad.net/ubuntu-mozilla-security/ppa/ubuntu trusty main" | sudo tee /etc/apt/sources.list.d/firefox.list
echo "deb-src http://ppa.launchpad.net/ubuntu-mozilla-security/ppa/ubuntu trusty main" | sudo tee /etc/apt/sources.list.d/firefox-source.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A6DCF7707EBC211F
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 9BDB3D89CE49EC21
sudo apt update && sudo apt install firefox

raspbian apt-get

If apt-get update errors out

rm /var/lib/apt/lists/* -vf
apt-get update

To get a detailed package description about an apt package

sudo apt-get show [PACKAGE_NAME]

Raspbian apt-get setup

These steps are optional but help free up some space on the root partition

sudo apt-get remove --purge wolfram-engine
sudo apt-get clean
sudo apt-get autoremove
sudo apt-get remove --purge libreoffice*
sudo apt-get clean
sudo apt-get autoremove

Raspbian OpenSSH X11 Forwarding

🚨 Certain apps will require being run as root, ie. gparted or elese the below message will be displayed. From my emperical evidence gparted will not run when logging in as pi and then running su - to get be superuser. That said, logging in as root via ssh allows running of gparted as root.

To troubleshoot a Gtk-WARNING **: cannot open display: localhost:10.0

export DISPLAY='IP:0.0'

may not fix the above issue, but see

VNC Server Setup

To setup a VNC server see

VNC Server Setup Gotchas

If a physical USB keyboard is not present install

apt-get install matchbox-keyboard

The matchbox-keyboard can be started from the GUI,

Menu >> Accessories >> Keyboard

Mounting a Network File Share

To mount a NFS Network File Share using smbclient

smbclient //[IP_ADDRESS_OF_NFS]/Data -U WORKGROUP

The stock smbclient setup on Raspbian has higher security settings than those setup on an Apple Time Capsule. That said, the below settings can be added to /etc/samba/smb.conf

[global]

echo "{$USER} added settings"
echo "Experimental settings"
client use spnego = no
client ntlmv2 auth = yes

The above command can be used to a network share setup in an Apple Time Capsule and should prompt for a password if one is setup for the network share.

The above command will mount a NFS share using Samba ie. the smbclient that is located on a host with a mount of of /Data.

Troubleshooting smbclient

To troubleshoot a smbclient connection

smbclient -L [SERVER_IP] -U [USERNAME] -d 256

Mounting a network share using CIFS

To mount a Common Internet File System (CIFS) in Linux, ie. Raspbian via a CLI

sudo mount -t cifs \
//[IP_ADDRESS_OF_NFS]/[MNT_POINT] \
/path/to/local/mnt \
-o rw,uid=1000,gid=1000 \
-o iocharset=utf8,sec=ntlm,vers=1.0

Useful Links

Useful Links Kodi

Kodi Articles

TODOs

  • Q what is the difference between arm32v6 & arm32v7, ie. what did v7 add to the arm instruction set.
Clone this wiki locally