Raspberry Pi#
SSD as Additional Storage#
Important
If using a SATA SSD make sure the cable/adapter has an ASMedia chipset so it will work properly with Raspberry Pi.
If you have an additional SSD you'll need to:
- Choose a partition manipulation program
- GNU Parted (
parted
) is probably already installed and ready to use from the command line. - GParted - If you have a desktop environment you can use this graphical frontend. Install with
sudo apt install gparted
.
- GNU Parted (
- Create a partition table (aka disklabel). The default partition table type is
msdos
for disks smaller than 2 Tebibytes in size (assuming a 512 byte sector size) andgpt
for disks 2 Tebibytes and larger. - Create partition(s) and file system(s).
- Find the file system's UUID.
- Create a directory for mounting the SSD.
- Set up automatic SSD mounting, mount the SSD, reboot to test.
Example with parted
:
cat /sys/block/sda/queue/optimal_io_size
# 33553920
cat /sys/block/sda/queue/minimum_io_size
# 512
cat /sys/block/sda/alignment_offset
# 0
cat /sys/block/sda/queue/physical_block_size
# 512
sudo parted
(parted) print devices # you should see your SSD e.g. /dev/sda (240GB)
(parted) select /dev/sda # whatever name your SSD device has
(parted) mklabel msdos
# Add optimal_io_size to alignment_offset and divide the result by physical_block_size.
# This number is the sector at which the partition should start. Here it ends in the last sector.
# Example:
(parted) mkpart primary ext4 65535s -1s
(parted) print list
(parted) align-check optimal 1 # or whatever number your partition has
# 1 aligned
(parted) quit
# Make the filesystem with a volume label on partition 1 (or whatever number yours has)
sudo mkfs.ext4 -L WDSSD -c /dev/sda1
# Filesystem UUID is displayed but you can also find it with:
sudo lsblk -o UUID,NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL,MODEL
mkdir wdssd
sudo chown pi:pi -R /home/pi/wdssd/
sudo chmod a+rwx /home/pi/wdssd/
sudo nano /etc/fstab
# At the end of the file that opens, add a new line containing the UUID and mounting directory
# UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /home/pi/wdssd/ ext4 defaults,auto,users,rw,nofail 0 0
Resizing a root partition#
By default the root partition will consume all the available space. If you have an SSD you may want to set up partitions appropriately for things like a Ceph cluster. You can't shrink a system partition while it's being used so we'll create our own GParted bootable USB drive. This is because the GParted Live image available for download is only for x86-based architectures like amd64. Both the Pi and Apple Silicon Macs are arm64.
-
Put a microSD card in a USB adapter and flash a Linux distribution with a desktop GUI.
Danger
Make sure you got the right device name. All data on the device will be lost.
On your laptopdiskutil list diskutil zeroDisk short /dev/disk5
################################################################### # REPLACE WITH YOUR VALUES ################################################################### IMAGE='ubuntu-22.04.3-preinstalled-desktop-arm64+raspi.img' DEVICE='/dev/disk5' ################################################################### # Unmount the card diskutil unmountDisk $DEVICE cd ~/Downloads # sudo dd if=$IMAGE of=$DEVICE bs=1m status=progress pv $IMAGE | sudo dd bs=1m of=$DEVICE
diskutil unmountDisk $DEVICE
-
After setting up your Pi with the USB bootloader (see the Boot from SSD section), connect the SSD to your Pi using a USB 3.0 port.
- Allow time for cloud-init to finish configuring your SSD and connect to it via SSH for a required
sudo reboot
. - Connect via SSH again and
sudo shutdown -h now
. - Disconnect the SSD and connect the GParted USB to a USB 3.0 port, a monitor or TV, a mouse, and a keyboard. Turn on your Pi.
- After setting up the OS, install GParted.
On your Pi
sudo apt update sudo apt upgrade sudo apt install gparted
- Connect the SSD to the other USB 3.0 port and open GParted. Hit Refresh devices if needed. Select the SSD e.g.
/dev/sdb
. - Right-click on the root ext4 partition e.g.
/dev/sdb2
(it should already be unmounted) and select and apply these operations.- Check the root partition.
- Resize it to 64 Gi (65,536 Mi) or desired size.
- Create unformatted partition in the unallocated space.
- Check the root partition again.
- Turn off the Pi. Disconnect the GParted USB, keep the SSD connected and turn it on.
Alternatively, you can use parted
to set up/resize the SSD partitions and file systems as desired. For example, leave a raw partition (no formatted filesystem) for use by a Ceph storage cluster.
- Resize the filesystem.
- If needed, shrink the partition to leave space to be used by Ceph.
Repeat for each node in your cluster.
Upgrade#
upgrade
is used to install available upgrades of all packages currently installed on the system. New packages will be installed if required to satisfy dependencies, but existing packages will never be removed. If an upgrade for a package requires the removal of an installed package the upgrade for this package isn't performed.full-upgrade
performs the function of upgrade but will remove currently installed packages if this is needed to upgrade the system as a whole.
sudo apt update # updates the package list
sudo apt full-upgrade
Authentication#
If you didn't do so during setup with cloud-init or manually, generate and add an ssh key.
# Specify the type of key to create e.g. `ed25519` or `rsa`.
ssh-keygen -t ed25519
# Add it on the remote machine (if the `-i` filename does not end in `.pub` this is added)
# Examples:
ssh-copy-id -i ~/.ssh/id_rsa pi@raspberrypi4b.local
ssh-copy-id -i ~/.ssh/id_ed25519 orangepi@orangepi3b.local
To remove password authentication:
sudo nano /etc/ssh/sshd_config
#PasswordAuthentication yes
with PasswordAuthentication no
.
Test the validity of the config file and restart the service (or reboot).
sudo sshd -t
sudo service sshd restart
sudo service sshd status
If you ever need to update the password for default users like pi
, orangepi
, ubuntu
, etc. you can use:
sudo passwd root
sudo passwd pi
Board-specific tools#
Raspberry Pi#
On Raspberry Pi OS
sudo raspi-config
# Go to Interface Options, VNC (for graphical remote access)
# Tab to the Finish option and reboot.
Orange Pi#
In Ubuntu for Orange Pi, to reach other machines by hostname you need to add an entry to the hosts file. Example:
192.168.x.x thathostname
Orange Pi has a config tool as well
sudo orangepi-config
nmcli dev wifi connect wifi_name password wifi_passwd
To set a static IP on Orange Pi see the user manual for instructions on using the nmtui
command.
Remote GUI access#
If you installed a graphical desktop
You'll need a VNC viewer on your laptop to connect to the Pi using the graphical interface.
brew install --cask vnc-viewer
Attention
Apparently, on Raspberry Pi OS pip
does not download from the Python Package Index (PyPI), it downloads from PiWheels. PiWheels wheels do not come with pygame
's dependencies that are bundled in normal releases.
Install Pygame dependencies and Pygame.
sudo apt install libvorbisenc2 libwayland-server0 libxi6 libfluidsynth2 libgbm1 libxkbcommon0 libopus0 libwayland-cursor0 libsndfile1 libwayland-client0 libportmidi0 libvorbis0a libopusfile0 libmpg123-0 libflac8 libxcursor1 libxinerama1 libasyncns0 libxrandr2 libdrm2 libpulse0 libxfixes3 libvorbisfile3 libmodplug1 libxrender1 libsdl2-2.0-0 libxxf86vm1 libwayland-egl1 libsdl2-ttf-2.0-0 libsdl2-image-2.0-0 libjack0 libsdl2-mixer-2.0-0 libinstpatch-1.0-2 libxss1 libogg0
sudo pip3 install pygame
# Check that the installation worked by running one of its demos
python3 -m pygame.examples.aliens
To set it up as a DNS server#
- Install and configure a DNS Server e.g. DNSmasq or Pi-Hole on the Pi.
- Change your router’s DNS settings to point to the Pi. Log in to your router's admin interface and look for DNS e.g. in LAN -> DHCP Server. Set the primary DNS server to the IP of your Pi and make sure it's the only DNS server. The Pi will handle upstream DNS services.
Copying files#
To copy files between the Pi and local machine
scp -r pi@raspberrypi2.local:/home/pi/Documents/ ~/Documents/pidocs
Find info about your Pi#
You can find info about the hardware like ports, pins, RAM, SoC, connectivity, etc. with:
free -h # RAM
df -h # storage space
pinout # requires `apt install python3-gpiozero`
View number of processing units and system load
nproc
uptime
CPU temperature in millidegree Celsius (one thousandth of a degree)
cat /sys/class/thermal/thermal_zone*/temp
# For CPU and GPU
sensors
# For NVMe SSD
sudo smartctl -a /dev/nvme0 | grep "Temperature:"
What model do you have?
cat /sys/firmware/devicetree/base/model ;echo
What's the connection speed of the ethernet port?
ethtool eth0
32 or 64-bit kernel?
getconf LONG_BIT
# or check machine's hardware name: armv7l is 32-bit and aarch64 is 64-bit
uname -m
See OS version
cat /etc/os-release
Architecture
If the following returns a Tag_ABI_VFP_args
tag of VFP registers
, it's an armhf
(arm
) system.
A blank output means armel
(arm/v6
).
readelf -A /proc/self/exe | grep Tag_ABI_VFP_args
hostnamectl
Troubleshooting#
If your Pi's ethernet port is capable of 1Gbps, you're using a cat5e cable or better, your router and switch support 1Gbps, and you're still only getting 100Mbps first try with another cable. A faulty cable is the most common cause of problems like this. If that doesn't work you can try disabling EEE (Energy Efficient Ethernet) although it will be reenabled at reboot. You could also try setting the speed manually.
ethtool --show-eee eth0
sudo ethtool --set-eee eth0 eee off
# set speed manually and disable autonegotiation
ethtool -s eth0 speed 1000 duplex full autoneg off
If not using cloud-init
or an imager program, enable ssh with
touch /Volumes/$VOLUME/ssh
DNS issues
cat /etc/resolv.conf
resolvectl status
If modprobe
shows 'not found' install the extra kernel modules package for your kernel release, rebuild the kernel to include the modules you need, install a newer kernel, or choose a different Linux distribution.
# Check if packages were installed
sudo cat /var/log/apt/history.log
# Check if there were any cloud-init errors
sudo cat /var/log/cloud-init.log | grep failures
sudo cat /var/log/cloud-init-output.log
Learn about electronics#
I've added some sample code from the MagPi Essentials book.
Sample code