Raspberry Pi Zero W - Installation

From Alpine Linux

Introduction

This wiki describes how I installed Alpine Linux 3.9.2 armhf on a Raspberry Pi Zero W. I had problems with it initially as WiFi wouldn't connect when going through the setup-alpine script and when I was able to get it connect (after numerous failed manual attempts) it wouldn't reconnect on reboot. The solution documented below adds and starts the rngd service prior to running setup-alpine which fixes the wifi connection problems and allows you to walk through the setup script successfully. It also adds the rngd and wpa_supplicant services to start at boot and removes the network service from the rc-update list completely, which seems like the wrong thing to do and probably is - networking still gets started, probably as a dependency to something else, and it starts after rngd and wpa_supplicant, which is what I needed. When the networking service was set to "boot" (which it was out of the box) it was starting before rngd and wpa_supplicant so wlan0 would never connect.

I need to go back through this again but it should work as written. Some steps may not be necessary for your use case and some steps may not be necessary at all, but don't seem to hurt. I'm still learning about Alpine Linux and hope to improve this process as I do more reading and experimentation.

Update - 7 Dec 2019 - I went through installation again on a Pi Zero W with Alpine 3.10.3 for armhf. First boot after writing the image to the SD card seems to work ok as far as WiFi functionality is concerned. Setup script completes and I was able to connect to WiFi and pull down packages etc. I decided to not install the rngd related packages at this point to see how a reboot looked, answer is not good. The dhcp request just times out. Running setup-alpine again at this point also doesn't work. If you start over and rewrite the image to the SD card, the first boot will again work ok, it's only rebooting that breaks Wifi. I think it's best to follow the steps for installing the rngd related packages and configuring the service to start at boot. Note that you can install what you need on first boot using apk, you don't need to copy the packages to the SD card offline as written below.

Update - 29 Dec 2019 - See also a method to perform a headless setup: Raspberry Pi - Headless Installation

Write image to SD

First, format an SD card with the FAT filesystem. That can be done with a graphical tool like GParted once the SD card is mounted on your operating system. The following assumes the SD card device is at /dev/sdb1.

Mount the SD card:

sudo mount /dev/sdb1 /mnt

Then, copy the files:

tar -xzvf alpine-rpi-3.9.2-armhf.tar.gz -C /mnt --no-same-owner

If you have no means to mount the SD card normally with an SD reader, it can be mounted via USB via the Raspberry Pi Zero W, using the usbbootgui tool to mount as eMMC/SD card reader. On Ubuntu, this can be installed as follows:

sudo add-apt-repository ppa:rpi-distro/ppa

sudo apt install usbbootgui

A GUI should open as soon as you plug in your Pi; otherwise run

usbbootgui

Edit cmdline.txt and add line for serial console (Optional)

This is for my use case and optional if you are using a local keyboard and monitor. I do not connect a keyboard and monitor but rather do the setup via the Pi's serial GPIO pins.

Create a file called cmdline.txt in the root of the SD card and place the following text in it:

modules=loop,squashfs,sd-mod,usb-storage quiet dwc_otg.lpm_enable=0 console=tty1 console=ttyAMA0,115200

Create usercfg.txt and edit (Optional)

This is mostly optional I believe and applies to my use case where I will be running the Pi in a headless appliance type mode. I reduce the memory allocated for the GPU, turn off audio (not sure I still need this on the Zero W), disable bluetooth (which I think puts the serial console back on the real uart, again, need to double check), add w1 for a temperature sensor, and set the enable_uart to 1 (may not be necessary, need to verify and add comments). This can be done by creating a file called usercfg.txt at the base of the SD card with the following contents:

gpu_mem=16 dtparam=audio=off dtoverlay=pi3-disable-bt dtoverlay=w1-gpio enable_uart=1

Create cache folder and add rng-tools packages

mkdir /mnt/cache

I copy pasted the following into the cache dir on sd card. I have another Alpine env to apk fetch packages from (chroot on Fedora)

rng-tools-6.3.1-r1.652a1399.apk rng-tools-openrc-6.3.1-r1.e9b063f8.apk

Boot Pi with prepared SD card, login as root and add packages

I'm still new to Alpine, not sure if the setup-apkcache step is necessary or accomplishes anything here.

localhost:~# setup-apkcache Enter apk cache directory (or '?' or 'none') [/var/cache/apk]: /media/mmcblk0p1/cache/ localhost:~# apk add --allow-untrusted /media/mmcblk0p1/cache/rng-tools-6.3.1-r1.652a1399.apk (1/1) Installing rng-tools (6.3.1-r1) Executing busybox-1.29.3-r10.trigger OK: 8 MiB in 21 packages localhost:~# apk add --allow-untrusted /media/mmcblk0p1/cache/rng-tools-openrc-6.3.1-r1.e9b063f8.apk (1/1) Installing rng-tools-openrc (6.3.1-r1) OK: 8 MiB in 22 packages

Start rngd service

localhost:~# service rngd start * Caching service dependencies ... [ ok ] * Starting rngd ... Initalizing available sources [ ok ]

Run setup-alpine wifi connection should setup ok with rngd running.

The setup process turns off the rngd service at some point but it's after wifi is connected

setup-alpine

Configure services and reboot

Removing networking from boot results in it not being present in any stage which seems like the wrong fix but it still gets run by something and after rngd and wpa_supplicant which is what we want:

pet-protect:~# rc-update add rngd boot * service rngd added to runlevel boot pet-protect:~# rc-update add wpa_supplicant boot * service wpa_supplicant added to runlevel boot pet-protect:~# rc-update del networking boot * service networking removed from runlevel boot pet-protect:~# rc-update -u * Caching service dependencies ... [ ok ] pet-protect:~# lbu commit -d pet-protect:~# reboot