Skip to the content.

Documentation

https://www.raspberrypi.com/documentation/

Determine which Pi model you have from the command line

cat /sys/firmware/devicetree/base/model: Example: Raspberry Pi 4 Model B Rev 1.1
cat /proc/device-tree/model: Example: Raspberry Pi 3 Model B Plus Rev 1.3
pinout: Gives a visual representation of the Raspberry Pi Pins but also, gives the model number and revision. cat /proc/cpuinfo: Gives CPU Info. You can then check some of the information again https://elinux.org/RPi_Hardware

No lshw

seems Raspberry Pi OS doesn’t have lshw installed

Differences between RaspberryPi OS Editions

https://forums.raspberrypi.com/viewtopic.php?t=339721

Automount

Raspberry Pi OS Lite does not automount removable media unlike the full edition.

From https://pimylifeup.com/raspberry-pi-mount-usb-drive/

“It’s important to know that Raspberry Pi OS lite currently does not automatically mount your drives. So you will need to either set it up manually or install the software package to have it automatically mount.”

Solutions:

udiskie may need a polkit config

For udiskie to run as pi, you may need to follow these polkit instructions

See also External Storage - Official Raspberry Pi Documentation

Packages for common file system support

NTFS: sudo apt install ntfs-3g
See NTFS on the Raspberry Pi for more details. (note site has too many ads)

exFAT:
sudo apt install exfat-fuse
sudo apt install exfat-utils
See exFAT on the Raspberry Pi for more details. (note site has too many ads)

Raspberry Pi Imager

Raspberry Pi Imager Custom Settings

Pre-defined os settings:

On RPiOS it is at: ~/.config/Raspberry Pi/Imager.conf On windows it might be in the registry at: HKCU\Software\Raspberry Pi\Imager

From https://forums.raspberrypi.com/viewtopic.php?t=339566

Code references to where its generated:

Raspberry Pi bootloader changes

If you want to change your boot order or the bootloader you need to use Raspberry Pi Imager. See Update the bootloader

For bootloader confiuguration changes see Update the bootloader configuraiton

sudo rpi-eeprom-update will show you the current and available versions, and the current policy. You may need to reconfigure it to see latest using instructions Update the bootloader configuraiton

ls -la /usr/lib/firmware/raspberrypi/bootloader-2711/default: Show default firmware versions already available on current Pi.
ls -la /usr/lib/firmware/raspberrypi/bootloader-2711/latest/: Show latest version of firwmare downloaded.
less /usr/lib/firmware/raspberrypi/bootloader-2711/release-notes.md: Release notes of versions.

On First Boot after new image

flowchart LR
 subgraph firstboot["firstboot"]
    direction LR
        /boot/firmware/cmdline.txt@{ label: "Modify /boot/firmware/cmdline.txt` so firstboot doesn't run again." }
        /usr/lib/raspberrypi-sys-mods/firstboot["/usr/lib/raspberrypi-sys-mods/firstboot"]
        main["call main function"]
        generate-ssh-keys["Generate SSH Keys by mounting the root partition and then running /usr/lib/raspberrypi-sys-mods/regenerate_ssh_host_keys"]
        apply_custom["apply_custom /boot/firmware/custom.toml"]
        /boot/firmware/custom.toml["If /boot/firmware/custom.toml is found, call apply_custom function, telling it to use /boot/firmware/custom.toml"]
        /usr/lib/raspberrypi-sys-mods/init_config@{ label: "If it doesn't fail run /usr/lib/raspberrypi-sys-mods/init_config /boot/firmware/custom.toml" }
        python3_-c_import_toml@{ label: "python3 -c 'import toml'" }
        Fix_Partuuid["Fix_Partuuid"]
        Reboot["Reboot"]
  end
 subgraph firstrun["firstrun"]
    direction LR
        /boot/firstrun.sh["/boot/firstrun.sh"]
        kerneloption["systemd.run="]
  end
    bootloader["bootloader"] --> cmdline.txt["cmdline.txt"]
    cmdline.txt --> /usr/lib/raspberrypi-sys-mods/firstboot & kerneloption
    /usr/lib/raspberrypi-sys-mods/firstboot --> /boot/firmware/cmdline.txt & main & generate-ssh-keys & /boot/firmware/custom.toml & Fix_Partuuid & Reboot
    /boot/firmware/custom.toml --> apply_custom
    apply_custom --> python3_-c_import_toml
    python3_-c_import_toml --> /usr/lib/raspberrypi-sys-mods/init_config
    /usr/lib/raspberrypi-sys-mods/init_config --> TBA["TBA"]
    kerneloption --> /boot/firstrun.sh
    /boot/firstrun.sh --> TBA

    /boot/firmware/cmdline.txt@{ shape: rect}
    /usr/lib/raspberrypi-sys-mods/init_config@{ shape: rect}
    python3_-c_import_toml@{ shape: rect}
    click /boot/firmware/cmdline.txt "#firstboot"
    click /usr/lib/raspberrypi-sys-mods/firstboot "https://github.com/RPi-Distro/raspberrypi-sys-mods/blob/bookworm/usr/lib/raspberrypi-sys-mods/firstboot"
    click main "https://github.com/RPi-Distro/raspberrypi-sys-mods/blob/93ab67567a088b6adbb0a8ec9d09655af52c14e4/usr/lib/raspberrypi-sys-mods/firstboot#L80"
    click generate-ssh-keys "https://github.com/RPi-Distro/raspberrypi-sys-mods/blob/bookworm/usr/lib/raspberrypi-sys-mods/regenerate_ssh_host_keys"
    click /usr/lib/raspberrypi-sys-mods/init_config "https://github.com/RPi-Distro/raspberrypi-sys-mods/blob/93ab67567a088b6adbb0a8ec9d09655af52c14e4/usr/lib/raspberrypi-sys-mods/firstboot#L65"
    click /boot/firstrun.sh "#raspberry-pi-imager-custom-settings"
    click kerneloption "https://www.freedesktop.org/software/systemd/man/latest/kernel-command-line.html#systemd.run="
    click bootloader "#raspberry-pi-bootloader-changes"
    click cmdline.txt "#cmdlinetxt"

After Raspberry Pi Imager is complete but before first boot, the cmdline.txt file has something like this in 2022:

console=serial0,115200 console=tty1 root=PARTUUID=067e19d7-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet init=/usr/lib/raspi-config/init_resize.sh

The /usr/lib/raspi-config/init_resize.sh runs on first run and at the end modifies cmdline.txt so it doesn’t run again. From: https://gijs-de-jong.nl/posts/raspberry-pi-file-system-resize-on-first-boot/, specifically: https://gijs-de-jong.nl/posts/raspberry-pi-file-system-resize-on-first-boot/#:~:text=How%20the%20automatic%20file%20system%20expansion%20is%20implemented

Here is one from 2025 with Bookworm:

console=serial0,115200 console=tty1 root=PARTUUID=067e19d7-02 rootfstype=ext4 fsck.repair=yes rootwait quiet init=/usr/lib/raspberrypi-sys-mods/firstboot cfg80211.ieee80211_regdom=US systemd.run=/boot/firstrun.sh systemd.run_success_action=reboot systemd.unit=kernel-command-line.target

WIP

The below first run order list is still very much a Work In Progress

So the order for bookworm seems to be:

  1. https://github.com/RPi-Distro/raspberrypi-sys-mods/blob/bookworm/usr/lib/raspberrypi-sys-mods/firstboot
    1. Modify /boot/firmware/cmdline.txt so firstboot doesn’t run again.
    2. call the main function
    3. Generate SSH Keys by mounting the root partition and then running /usr/lib/raspberrypi-sys-mods/regenerate_ssh_host_keys
    4. If /boot/firmware/custom.toml is found, call apply_custom function, telling it to use /boot/firmware/custom.toml
      1. Run python3 -c "import toml"
      2. If it doesn’t fail run /usr/lib/raspberrypi-sys-mods/init_config supplying the toml firle as an argument.
        1. TBA
    5. Fix PartUUID
    6. Reboot if there is no failure reason determined.
  2. systemd.run=/boot/firstrun.sh:
    1. systemd.run is a kernel option for systemd. see system.run in kernel-command-line. They are options for systemd-run-generator man page
    2. /boot/firstrun.sh: this is dynamically created by the Raspberry Pi Imager depending on the configration you set (see Raspberry Pi Imager Custom Settings). See below for First Run Github links

firstrun.sh generation links from github:

Setting a static IP on a Pi using Bookworm

Use a DHCP Reservation

Crappy but seems official: https://www.raspberrypi.com/documentation/computers/configuration.html#assign-a-static-ip-address

Network Manager

https://networkmanager.dev/docs/api/latest/nmcli.html
https://networkmanager.dev/docs/api/latest/nmcli.html#:~:text=Examples,-This%20section%20presents
https://networkmanager.dev/docs/api/latest/nmcli-examples.html

sudo nmcli c show
nmcli con show
# sudo nmcli con mod "Your Connection Name" ipv4.addresses "192.168.1.100/24" ipv4.gateway "192.168.1.1" ipv4.dns "8.8.8.8" ipv4.method manual
sudo nmcli con mod "Wired connection 1" ipv4.addresses 192.168.1.22/24 ipv4.gateway 192.168.1.1 ipv4.dns 192.168.1.1 ipv4.method manual
sudo nmcli con mod "Wired connection 1" -ipv4.address "192.168.1.100/24"
nmcli device wifi list
nmcli device wifi connect "$SSID" password "$PASSWORD"
nmcli --ask device wifi connect "$SSID"
sudo systemctl restart NetworkManager

Using NMCLI as a hotspot:
From https://www.raspberrypi.com/documentation/computers/configuration.html#host-a-wireless-network-from-your-raspberry-pi

# enable hotspot
sudo nmcli device wifi hotspot ssid <example-network-name> password <example-password>

# disable hotspot
## To disable the hotspot network and resume use of your Pi as a wireless client, run the following command:
sudo nmcli device disconnect wlan0

## After disabling the network, run the following command to reconnect to another Wi-Fi network:
sudo nmcli device up wlan0

/etc/network/interfaces

iface eth0 inet static
address 192.168.1.100        # Your desired static IP address
netmask 255.255.255.0        # Your subnet mask
gateway 192.168.1.1          # Your gateway (router) IP address
dns-nameservers 8.8.8.8      # DNS server(s) - You can add multiple servers

Also consider setting up configs in source /etc/network/interfaces.d/*

full-upgrade

From: https://www.raspberrypi.com/documentation/computers/os.html#manage-software-packages-with-apt

Tip

Unlike Debian, Raspberry Pi OS is under continual development. As a result, package dependencies sometimes change, so you should always use full-upgrade instead of the standard upgrade.

full-update commands:

sudo apt update # -y
sudo apt full-upgrade # -y

Firmware Upgrade

Warning

Pre-release versions of software are not guaranteed to work. Do not use rpi-update on any system unless recommended to do so by a Raspberry Pi engineer. It could leave your system unreliable or broken. Do not use rpi-update as part of any regular update process.

Uses apt package: raspi3-firmware

https://www.raspberrypi.com/documentation/computers/os.html#rpi-update

rpi-update downloads the latest pre-release version of the Linux kernel, its matching modules, device tree files, and the latest versions of the VideoCore firmware. It then installs these files into an existing Raspberry Pi OS install.

sudo rpi-update
sudo reboot

White paper on firmware updates: https://pip.raspberrypi.com/categories/685-whitepapers-app-notes/documents/RP-003476-WP/Updating-Pi-firmware.pdf

Downgrade firmware to the last stable release

raspi-config non-interactive

https://www.raspberrypi.com/documentation/computers/configuration.html#raspi-config-cli

Read only SD Card

https://core-electronics.com.au/guides/read-only-raspberry-pi/

To Enable:

  1. sudo raspi-config
  2. Select Performance Options
  3. Select Overlay File System
  4. When prompted “Would you like the overlay file system to be enabled?” select ‘Yes’
  5. wait while /boot/initrd is generated
  6. Press Ok for overlay
  7. When prompted “Would you like the boot partition to be write protected” select Yes
  8. Select ok when advised “the boot partition is read only”

To Revert back:

  1. sudo raspi-config
  2. Select Performance Options
  3. Select Overlay File System
  4. When prompted “Would you like the overlay file system to be enabled?” select ‘No’
  5. Press Ok when advised the overlay file system is disabled
  6. You will then be advised that the current partition is read only and you need to reboot
  7. Then go to disable it again.
  8. This time you will be asked “would you like the boot partition to be write protected?” Select ‘No’
  9. Press ok. You may have to reboot again

Script I found to do this while googing: https://github.com/ghollingworth/overlayfs/blob/master/overctl and also https://yagrebu.net/unix/rpi-overlay.md#:~:text=Finishing%20Touches-,Read%2DOnly%20/boot,-The%20/boot%20filesystem

config.txt

RaspberryPi BIOS Settings

For bookworm onwards its located in: /boot/firmware/config.txt
Before bookworm it was in /boot/config.txt

https://www.raspberrypi.com/documentation/computers/config_txt.html#what-is-config-txt

https://elinux.org/RPiconfig

Note that if you want to change your boot order or the bootloader you need to use Raspberry Pi Imager. See Raspberry Pi Imager.

cmdline.txt

The Linux kernel accepts a collection of command line parameters during boot. On the Raspberry Pi, this command line is defined in a file in the boot partition, called cmdline.txt. You can edit this text file with any text editor.

For bookworm onwards its located in: /boot/firmware/cmdline.txt
Before bookworm it was in /boot/cmdline.txt

https://www.raspberrypi.com/documentation/computers/configuration.html#kernel-command-line-cmdline-txt
https://elinux.org/RPi_cmdline.txt
https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html - lots of them

Controlling a Raspberry Pi Fan

Checking settings

cat /sys/class/hwmon/hwmon0/pwm1
cat /sys/class/thermal/thermal_zone0/trip_point_0_temp
cat /sys/class/thermal/thermal_zone0/trip_point_1_temp

Modifying RPM Config

from: https://github.com/raspberrypi/linux/issues/2715#issuecomment-769405042

  1. SSH into your pi
  2. Navigate to the boot directory by using the command: cd /boot
  3. Open the config.txt file in nano by using the command: sudo nano config.txt
  4. Use the down arrow to go to the bottom of this file.
  5. Add these 5 lines changing the temp to whatever you prefer. Noting 65 Degrees Celsius = 65000. In addition, the fan has 4 speeds this just sets at what temperatures the fan speed changes. I wanted it to be super silent so my temperature targets are very aggressive. Running a Unifi controller for 5 months with occasional 40 degree Celsius days with no issues so far.
# PoE Hat Fan Speeds
dtparam=poe_fan_temp0=65000
dtparam=poe_fan_temp1=70000
dtparam=poe_fan_temp2=75000
dtparam=poe_fan_temp3=80000
  1. Press ‘Control+X’ on your keyboard to exit
  2. Press ‘Y’ on your keyboard to agree to overwriting the file
  3. Press ‘Enter’ to confirm
  4. This will close the nano text editor
  5. reboot your pi using the command
  6. sudo reboot
  7. The fan should work with your new settings now

vcgencmd

vcgencmd measure_temp: Get temp of Pi
vcgencmd get_config <command>: show config.txt settings. see https://www.raspberrypi.com/documentation/computers/config_txt.html#what-is-config-txt

vcgencmd commands: show other vcgencmd commands

More info:

vclog

From https://www.raspberrypi.com/documentation/computers/os.html#vclog

vclog displays log messages from the VideoCore GPU from Linux running on the Arm. It needs to be run as root.
sudo vclog --msg: prints out the message log
sudo vclog --assert: prints out the assertion log.

rfkill

rfkill --output ID,TYPE
rfkill block all
rfkill unblock wlan
rfkill block bluetooth uwb wimax wwan gps fm nfc

Pairing a Bluetooth Keyboard

When the taskbar pairing icon isn’t working:

sudo bluetoothctla

agent on
default agent
scan on
# Find the device you are looking for
scan off
trust <<INSERT MAC ADDRESS OF DEVICE>>
connect <<INSERT MAC ADDRESS OF DEVICE>>
# If its a keyboard it should come back with 6 digits to type into the keyboard. Type them and press enter

from: http://wiki.sunfounder.cc/index.php?title=Connecting_Raspberry_Pi_with_the_Bluetooth_keyboard#:~:text=Switch%20on%20the%20keyboard%20and,%5Bbluetooth%5D%23%20scan%20off

Some extra Commands inside bluetoothctl to help:
remove <<INSERT MAC ADDRESS OF DEVICE>>: removes device from list. This should be tried before all others. Ideally either before or after trust
pair <<INSERT MAC ADDRESS OF DEVICE>>: shouldn’t be needed for keyboard and mouse but may be.
info <<INSERT MAC ADDRESS OF DEVICE>>: show info about the device.
power off: turn the bluetooth controlled off (this isn’t rfkill)

More commends: https://manpages.debian.org/unstable/bluez/bluetoothctl.1.en.html

Sound

alsactl: advanced controls for ALSA soundcard driver. https://linux.die.net/man/1/alsactl:

aplay -l: List all soundcards and digital audio devices via ALSA. https://linux.die.net/man/1/aplay
aplay -L: List all PCMs defined
aplay -D plughw:CARD=UACDemoV10 /usr/share/sounds/alsa/Front_Center.wav: play this sound on this PCM device alsamixer: Interactive TUI mixer for setting volume levels. https://linux.die.net/man/1/alsamixer
amixer: cmdline mixer for ALSA. https://linux.die.net/man/1/amixer:

sudo speaker-test -c2 -D <devicename>: test the speakers. May need sudo. https://linux.die.net/man/1/speaker-test

~/.asoundrc file syntax: https://www.alsa-project.org/wiki/Asoundrc

ls /proc/asound/cards
ls /proc/asound/card2

XScreensaver and xset

Man page for xscreensaver-command

Activate now: xscreensaver-command -activate
Deactivate now: xscreensaver-command -deactivate

Man page for xset

Force monitor to turn off with: xset dpms force off

No Remote

xset dpms force off command doesn’t seem to work over ssh whereas the xscreensaver-command above does

Tools

Raspberry Pi SD Card Image Manager
Pi-Gen: Tool used to create the official Raspberry Pi OS images (can also create custom images)

Misc References

Embedded Linux Wiki
STICKY: Using fstab A Beginner’s Guide
Raspberry Pi Pinout Guide - interactive reference to the Raspberry Pi GPIO pins, and a guide to the Raspberry Pi’s GPIO interfaces - also see the pinout command.
RPi GPIO Python Module Info
Official Documentation