- Documentation
- Determine which Pi model you have from the command line
- Differences between RaspberryPi OS Editions
- Raspberry Pi Imager
- On First Boot after new image
- Setting a static IP on a Pi using Bookworm
- full-upgrade
- Firmware Upgrade
- raspi-config non-interactive
- Read only SD Card
- config.txt
- cmdline.txt
- Controlling a Raspberry Pi Fan
- vcgencmd
- vclog
- rfkill
- Pairing a Bluetooth Keyboard
- Sound
- XScreensaver and xset
- Tools
- Misc References
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, manually started as a deamon: https://github.com/coldfix/udiskie
udiskie may need a polkit config
For udiskie to run as pi, you may need to follow these polkit instructions
- udev rules: https://blog.jasonantman.com/2009/11/running-a-script-on-usb-drive-insertion/
- autofs (maybe - can’t quickly find solid answer on if it automounts?)
- fstab (note if storage is not attached at raspberrypi bootup, it add an extra 90 seconds to timeout): Automatically mount a storage device - Raspberry Pi Documentation
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:
- https://github.com/raspberrypi/rpi-imager/blob/qml/src/downloadthread.cpp
- https://github.com/raspberrypi/rpi-imager/blob/qml/src/OptionsPopup.qml
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:
-
https://github.com/RPi-Distro/raspberrypi-sys-mods/blob/bookworm/usr/lib/raspberrypi-sys-mods/firstboot
Modify /boot/firmware/cmdline.txt
so firstboot doesn’t run again.- call the main function
- Generate SSH Keys by mounting the root partition and then running /usr/lib/raspberrypi-sys-mods/regenerate_ssh_host_keys
- If
/boot/firmware/custom.toml
is found, call apply_custom function, telling it to use/boot/firmware/custom.toml
- Run
python3 -c "import toml"
- If it doesn’t fail run
/usr/lib/raspberrypi-sys-mods/init_config
supplying the toml firle as an argument.- TBA
- Run
- Fix PartUUID
- Reboot if there is no failure reason determined.
-
systemd.run=/boot/firstrun.sh
:-
systemd.run
is a kernel option for systemd. see system.run in kernel-command-line. They are options for systemd-run-generator man page -
/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:
- https://github.com/raspberrypi/rpi-imager/blob/qml/src/downloadthread.cpp
- https://github.com/raspberrypi/rpi-imager/blob/qml/src/OptionsPopup.qml
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:
sudo raspi-config
- Select Performance Options
- Select Overlay File System
- When prompted “Would you like the overlay file system to be enabled?” select ‘Yes’
- wait while /boot/initrd is generated
- Press Ok for overlay
- When prompted “Would you like the boot partition to be write protected” select Yes
- Select ok when advised “the boot partition is read only”
To Revert back:
sudo raspi-config
- Select Performance Options
- Select Overlay File System
- When prompted “Would you like the overlay file system to be enabled?” select ‘No’
- Press Ok when advised the overlay file system is disabled
- You will then be advised that the current partition is read only and you need to reboot
- Then go to disable it again.
- This time you will be asked “would you like the boot partition to be write protected?” Select ‘No’
- 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
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
- SSH into your pi
- Navigate to the boot directory by using the command:
cd /boot
- Open the config.txt file in nano by using the command:
sudo nano config.txt
- Use the down arrow to go to the bottom of this file.
- 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
- Press ‘Control+X’ on your keyboard to exit
- Press ‘Y’ on your keyboard to agree to overwriting the file
- Press ‘Enter’ to confirm
- This will close the nano text editor
- reboot your pi using the command
- sudo reboot
- 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 get_config <config>
- lists a specific config value. E.g. vcgencmd get_config arm_freq -
vcgencmd get_config int
- lists all the integer config options that are set (non-zero) -
vcgencmd get_config str
- lists all the string config options that are set (non-null)
vcgencmd commands
: show other vcgencmd commands
More info:
- https://www.raspberrypi.com/documentation/computers/os.html#vcgencmd
- https://github.com/raspberrypi/documentation/blob/bd97e2f9aaf9f41ae36e6c8b54083ae6573d9d28/raspbian/applications/vcgencmd.md
- https://github.com/raspberrypi/documentation/blob/bd97e2f9aaf9f41ae36e6c8b54083ae6573d9d28/raspbian/applications/vcdbg.md
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
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:
-
sudo alsactl store
: stores current settings in/var/lib/alsa/asound.state
alsactl --file ~/.config/asound.state store
alsactl --file ~/.config/asound.state restore
- More commands from: https://askubuntu.com/questions/50067/how-to-save-alsamixer-settings
sudo alsamixer
- do not exit alsamixer
- in a new terminal
sudo alsactl store
sudo alsactl dump-state
sudo alsactl dump-cfg
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:
-
amixer -c <CARDNAME> info
: show the info about a mixer device for CARDNAME. CARDNAME can be a friendly name like HDMI or a USB Speaker device name, or a card number. -
amixer -c <CARDNAME> scontrols
: Show me the simple controls for CARDNAME. -
amixer -c <CARDNAME> scontents
: show me the simple controls and some more details about them for CARDNAME -
amixer -c <CARDNAME> get <SCONTROL>
: get the current simple control value (get
is an aliassget
) -
amixer -c <CARDNAME> set <SCONTROL> <PARAMETER>
: set the current simple control parameter. (set
is an alias ofsset
):Sets the simple mixer control contents. The parameter can be the volume either as a percentage from 0% to 100% with % suffix, a dB gain with dB suffix (like -12.5dB), or an exact hardware value. The dB gain can be used only for the mixer elements with available dB information. When plus(+) or minus(-) letter is appended after volume value, the volume is incremented or decremented from the current value, respectively.
The parameters cap, nocap, mute, unmute, toggle are used to change capture (recording) and muting for the group specified.
The optional modifiers can be put as extra parameters to specify the stream direction or channels to apply. The modifiers playback and capture specify the stream, and the modifiers front, rear, center, woofer are used to specify channels to be changed.
A simple mixer control must be specified. Only one device can be controlled at a time.
-
amixer -c <CARDNAME> controls
: show me the controls for CARDNAME. This will show you the numid’s you can use for this card. -
amixer -c <CARDNAME> contents
: show me the controls and some more details about them for CARDNAME. This will show you the numids for this card and their values and how they work. -
amixer -c <CARDNAME> cget <CONTROL>
: get the current control value -
amixer -c <CARDNAME> cset <CONTROL> <PARAMETER>
: set the current control parameterExamples from man page:
amixer -c 1 sset Line,0 80%,40% unmute cap
: will set the second soundcard’s left line input volume to 80% and right line input to 40%, unmute it, and select it as a source for capture (recording).
amixer -c 1 -- sset Master playback -20dB
: will set the master volume of the second card to -20dB. If the master has multiple channels, all channels are set to the same value.
amixer -c 1 set PCM 2dB+
: will increase the PCM volume of the second card with 2dB. When both playback and capture volumes exist, this is applied to both volumes.
amixer -c 2 cset iface=MIXER,name='Line Playback Volume",index=1 40%
: will set the third soundcard’s second line playback volume(s) to 40%
amixer -c 2 cset numid=34 40%
: will set the 34th soundcard element to 40%My examples:
aplay -l # get list of hardware to find name amixer -c CARDNAME info # get info on card # Simple Controls amixer -c CARDNAME scontrols # show the ALL the simple controls on the card amixer -c CARDNAME scontents # show the current simple contents of ALL simple controls on the card amixer -c CARDNAME sget <CONTROLNAME> # simple get the simple content of an indivudal simple control specified amixer -c CARDNAME sset <CONTROLNAME> <PARAMETER> # simple set the individual simple control specified with parameter. examples: amixer -c CARDNAME sget PCM amixer -c CARDNAME sset PCM mute # mute PCM control amixer -c CARDNAME sset PCM 75% # set PCM Control to 75% amixer -c CARDNAME sset PCM unmute playback 50% # Unmute PCM, and set playback volume on PCM to 50% # Full Controls amixer -c CARDNAME controls # show the ALL the full controls on the card amixer -c CARDNAME contents # show the current full contents of ALL full controls on the card amixer -c CARDNAME cget <CONTROLNAME> # regular get the full content of the full control specified amixer -c CARDNAME cset <CONTROLNAME> <PARAMETER> # regular set the full control specified with parameter. examples: amixer -c CARDNAME cget numid=1 amixer -c CARDNAME cget numid=2 amixer -c CARDNAME sset numid=1 mute # mute PCM control amixer -c CARDNAME sset numid=2 75%,30% # set left pcm volume to 75% and right PCM volume to 30%
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
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