skysurfer.media

streamer build notes


strategy

So, its my second time around installing Arch Linux on a Raspberry PI and regretfully I didn’t keep any notes, so this time I’m documenting the process. The first time around there was confusion about the difference between the RPI 3B and the 3B+ which led to mismatched libraries when trying to build an exotic driver… but it worked! I was able to successfully build and install Webcamoid on a Raspberry Pi, including its custom video driver and all effects. Even recording was working. But then there were glitches and random crashes from issues with the kernel and as I kept rebuilding, reinstalling, and deleting things, I realized the main issue and simply deleted *everything* to start over. Unfortunately, this meant I lost some custom configs I wish I’d backed up. That’s the first part of the new strategy. I’ll also be able to better share the configurations and final images. But although I’m sharing this publicly, this document assumes some basic Linux knowledge and is not meant to be a tutorial, just install notes.

images

The starting point for Arch Linux on any RPI is archlinuxarm.org, but it leads to installation directions for ArmV7 with a note about aarch64 at the end. Printed on my board is Raspberry Pi v1.2 – 2015, so the right image to start with is the aarch64, not the 32-bit version. This is important, as it’s one of the only differences between the 3B and the 3B+ and its critical for video hardware acceleration. This document only covers 64-bit installation on the RPI 3B+ although the same instructions should apply to the RPI 4 and 5, and the basic install process should be the same for the 32-bit version.

starting point:
https://archlinuxarm.org/platforms/armv8/broadcom/raspberry-pi-3

use for RPI 2 or 3 (32-bit):
http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-armv7-latest.tar.gz

use for RPI 3B+ (64-bit):
http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-aarch64-latest.tar.gz

I’m starting with a 512G MicroSD card but 32G should be more than enough. 64G or larger will allow lots of room for saving video files. The streamer-base rootfs is only 3.3G installed. An external USB drive is not desirable as some tutorials recommend because the USB is really just one Bus that shares 4 ports. So, the USB should be used *only* for the webcam. Onboard video should also work just fine. For the camera, I’m using a Logitech C930e that should be able to stream 1080p and has the added benefit of a built in microphone. Any v4l compliant camera should work.

basic install

Partition the MicroSD with 2 partitions :
Only DOS MBR or Hybrid MBR will work – not GPT

/boot – must be big enough for the bootloader and kernel. Some tutorials do not recommend enough. 300M should be sufficient – I used 512M to be sure. Make this Partition Type VFAT or it won’t boot.

mkfs.vfat /dev/sdX1

/root – use the rest of the space for /root and make this Partition Type EXT4 – there is no valid reason to use a swap partition on fixed media. If its necessary for software because of a lack of memory (1G), a swap file is more appropriate.

mkfs.ext4 /dev/sdX2 -L streamer-base # or, your-label-here

There are different ways to unpack and install the image to the sdcard. I mount the formatted card’s /root partition on /mnt/root and then mkdir /root/boot and mount the /boot partition there. After mounting the partitons, I unpack the image into ~/ and ‘cp -a * /mnt/root’ — this can be done more poetically with a one-liner but making backups of an installed image is the reverse of this so versioned backups can be made the same manner. ‘cp -a /mnt/root/* ~/<new-version> — in the end, I’ll have a few prebuilt filesystems to choose from, one basic, one with build tools, and one enhanced with added binaries and such. There is no plan to make a mega image with tons of useless extras, though variations can easily be made or restored this way.

changes to boot.txt

The stock Arch Linux ARM boot.txt has problems on my Rasberry Pi and there are many similar issues reported in online forums. One is a line for getting eth0 to keep a fixed mac address, only causes an error and since I’m only using wireless, no reason for it so I’ve commented it out. Added is the line fbcon=nodefer which was necessary to avoid unpredictable conflicts with a custom font on HDMI – 4k60p is still not working, though. But the biggest change is in labeling the partitions. The stock Arch way uses EFI which *might* work on a Hybrid MBR, but since the Pi is not modern enough for a GPT partition table, the use of labels circumvents the need to identify the drive letters which can change anyway. So now, the same card which is /dev/sdX in one machine and /dev/mmc in another can be mounted the same way:

mount -L <label> <mount-point> ## instead of
mount -t <type> <device-name> <mount-point>

This can be done with the /boot partition but fat32 labels are not as reliable, so I only do this for ext4 – notes on this are included in boot.txt – this is valid in fstab, too, or UUID can also be used.

mkfs.ext4 /dev/sdX2 -L <label> ## create fresh filesystem
e2label /dev/sdX2 <label>      ## label existing partition

post install steps

The default user:pass is alarm:alarm for ArchLinuxARM.

The first thing you’ll see is an annoying blinking cursor.

printf '\033[?12l' ## does not work as it does
                   ## in some terminals, so...
su root ## default password is: root
echo 0 > /sys/class/graphics/fbcon/cursor_blink

Blinking stops.

Now to fix a condition resulting from a big screen and a small font.

# setfont -d ## doubles the consolefont size, or...
setfont /usr/share/kbd/consolefonts/solar24x32.psfu.gz

Note that these fonts are not in the default location and standard font config tools have not been installed. Several fonts are available at boot. It is possible to rebuild the kernel to use a specific font and size at the console level but this way is a flexible option that can be easily adjusted for different screens.

The RPI 3b+ requires a power supply of 2.5 amps – many power supplies are only 2.1 amps which is sufficient for most things, but can throw errors:

hwmon hwmon1: Undervotage detected!
hwmon hwmon1: Voltage normalised

Although these errors can usually be safely be ignored, they interrupt the terminal so I turn them off:

dmesg -n 1 ## disables output to stdout

I also prefer the look of an old green or amber monochrome monitor:

tput setaf 2 ## green, or...
tput setaf 3 ## amber

For color to be persistent, changing the PS1 variable is better, though. And while we’re at it, we can make the prompt simpler or fancier:

export PS1='\[\e[32m\]\u: ' ## makes prompt <user>: green
export PS1='\[\e[33m\]\u: ' ## makes prompt <user>: amber

This must be changed in /etc/bash.bashrc to be permanent for root and ~/.bashrc for the regular user. There is a lot of information about possible variables and fancy prompts elsewhere online.

Now lets make the rest into a script so I won’t have to enter all of these commands every time I boot up the RPI:

nano /etc/streamer-startup

dmesg -n 1; ## the order of these commands matters
setfont /usr/share/kbd/consolefonts/solar24x32.psfu.gz;
echo 0 > /sys/class/graphics/fbcon/cursor_blink;

# ending this script with 'exit' causes problems

Remember to make the script executable:

chmod a+x /etc/streamer-startup

And then let’s make this into a systemd service:

nano /etc/systemd/system/streamer-startup.service

[Unit]
Description=run streamer-startup script

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/etc/streamer-startup

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable streamer-startup

A reboot will now bring up a readable prompt with any personal customization. This is an unorthodox way of setting things up but avoids the use of xinit, .profile, and so on… so it’s universal with or without a graphical environment and independent from the boot partition. There are many ways to start a script on boot, but this keeps userspace changes in one place and can be easily disabled or edited.

To enable sound and video, edit config.txt:

nano /boot/config.txt

enable_uart=1
dtparam=audio=on
dtoverlay=vc4-kms-v3d
hdmi_enable_4kp60=1

update and upgrade

Ok, so now we need an internet connection to update and install the base system. The Arch Linux instructions assume you have an ethernet port to plug into but this is not the case for me since I’m doing all this on a broadband hotspot, and unfortunately the base install does not configure a wireless device by default. This is the other difference between the RPI 3B and the 3B+ — the main processor and the wireless adapter are the only two differences. These notes are only guaranteed to apply to the RPI 3B+ but the necessary changes may also be valid on other RPIs.

There are two problems with this adapter and Arch Linux. The first problem is that it remains in a down state since it isn’t recognized, easy fix.

cd /etc/systemd/system/network/
cp en.network wl.network
sed -i 's/en/wl/g' wl.network
systemctl daemon-reload
systemctl restart systemd-networkd

Now wlan0 will show up as ‘Configuring…’, basically waiting for the wireless program to connect it to the WAN – no problem, except that the program we want hasn’t been installed.

That was the second problem with my particular device, that it would not connect to a WPA hotspot no matter what I tried. The issue is with wpa_supplicant which is included as the default and is configured to use udev — this may or may not work for a USB adapter, but had problems with the onboard adapter and a cell phone hotspot. The solution is to upgrade to iwd which is far more up to date. It uses iw and ip so the problematic iwconfig along with wpa_supplicant are not necessary. Also unnecessary are netctl, netcfg, netcfg-auto, and wifi-menu… so much simpler to keep only networkctl and install iwd. There’s no need to install the bulky gnome network-manger, either, as some forums suggest. To achieve this, I had to open up an unencrypted hotspot – no password, no need for wpa_supplicant.

systemctl enable dhcpcd
systemctl start dhcpcd
iw wlan0 connect "<hotspot>" ## important that the
                             ## hotspot name is in quotes

Once connected to the internet:

ping 4.2.2.2 ## make sure there's a connection
pacman-key --init && pacman-key --populate
pacman -Rns wpa_supplicant wireless_tools netctl
pacman -Syyu linux-aarch-headers ## use linux-rpi
                                 ## headers for 32-bit
reboot

Reconnect to the hotspot.

Edit /etc/mkinitcpio.conf and remove ‘microcode’ from the HOOKS section

pacman -S most htop iwd v4l-utils v4l2loopback-dkms v4l2loopback-utils i2c-tools uboot-tools # optional: ffmpeg-rpi vlc-rpi

If prompted for a jack provider, choose pipewire-jack — this will be useful later.

hostnamectl set-hostname streamer
systemctl enable iwd
systemctl start iwd

Refer to https://wiki.archlinux.org/title/Iwd for more complete instructions on using iwd from the command line and managing connections.
Systemd-networkd and dhcpcd handle assigning an IP address to the interface automatically so the basic routine for connecting to a hotspot is:

iwctl station wlan0 scan
iwctl station wlan0 get-networks
iwctl station wlan0 connect "<hotspot>" ## quotes matter

If there’s a password required you will be prompted, and WPA works fine. On reboot, the wifi connection is now persistent…

This is an ideal stopping point for the base image.


See install and backup for instructions on making and restoring images.

notes

There is a difference between the RPI 3B+ Rev 1.2 and 1.3 – it’s the wireless. Rev 1.2 only supports 2.4Ghz. Rev 1.3 has a 2.4/5Ghz adapter. Get information about wireless capabilities from ‘iw list’. I had to change the settings for my hotspot in order for it to show up in a scan.

When copying the files, the system stalls on a file in /var/log/journal/<session>
Removing this directory was the solution. I have no idea what the problem is with the file but the system hangs on copying if the journal isn’t removed first.

During boot, there’s a quick yellow-colored warning that flies by on the screen… I’ve poured over dmesg and can’t figure out what it is. Maybe it’s related, or maybe its because there’s no ethernet, but I’ll assume it can be safely ignored.

Two errors persist – one is about adding hdmi_enable_4kp60 to /boot/config.txt but this does not make the error go away. The second error may be related – unable to find drm device by node – however, drminfo shows everything is good and the module is loaded and running without a problem. Kernel messages look like vc4 hardware acceleration is functional, so if there are any configuration issues they won’t likely surface until a graphical interface is installed.

ffmpeg-rpi and vlc-rpi are built to use hardware acceleration. These have been removed from the base image for size and because streamer-console now covers the extras. By keeping v4l2, this should be sufficient to start a camera stream from the command line using streamer-base. The vlc-config.txt found in /boot is not be getting sourced at boot time – but config.txt has been edited to reflect changes for RPI 3B+ only. If editing /boot remember to run ./mkscr before rebooting

most and htop are personal preferences, as is the font choice.

streamer-console includes man pages

The difference between streamer-base and streamer-console is the list of included packages. Using ‘pacman -Q > _package.list’, these files are in the share folder.

Images and files can be found at http://skysurfer.media/share