Activating wireless on the Raspberry Pi 3 B using Alpine Linux

Introduction

Alpine Linux is a relatively new distribution that, is a breath of fresh air in the Linux landscape. In a world of ever increasing complexity, Alpine is fresh minimalist distribution that keeps things relatively simple. It is not going to replace your Ubuntu/Arch/Debian desktop anytime soon but it excels running in containers and building dedicated servers.

One of the properties that makes Alpine attractive for raspberry pi is that it can run from RAM (diskless mode). This makes raspberry pi feel snappy since writing to the SD card is excruciatingly slow. It does cost some memory but if the wntire system is <100 Mb, that "wasted" memory is minimal. Running from RAM also makes the system more robust in cases of power loss. The minimalist nature of alpine makes it lightweight and requires very little bandwidth to keep it up to date.

Installation

Installation on raspberry pi is relatively straightforward. Just create a FAT32 partition on an SD card, and set the bootable flag on that partition.

$ sudo fdisk -l  /dev/sde
Disk /dev/sde: 29.7 GiB, 31914983424 bytes, 62333952 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start      End  Sectors  Size Id Type
/dev/sde1        8192 62333951 62325760 29.7G  c W95 FAT32 (LBA)
$ sudo fdisk  /dev/sde

Welcome to fdisk (util-linux 2.32).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): a
Selected partition 1
The bootable flag on partition 1 is enabled now.

Command (m for help): w
The partition table has been altered.
Syncing disks.

Then grab the raspberry pi tarball from the Alpine downloads (currently alpine-rpi-3.7.0-armhf.tar.gz is only 66Mb).

# Assuming SD card is mounted under /mnt/sd
cd /mnt/sd
curl http://dl-cdn.alpinelinux.org/alpine/v3.7/releases/armhf/alpine-rpi-3.7.0-armhf.tar.gz | tar xvzf -

Now some preparation is necessary to make our life easier. So first lets follow the wiki's suggestion and add a workaround for bug #7024.

echo enable_uart=1 > usercfg.txt

To enable wireless, you will need the Broadcom firmware files for the wifi module. These need to be placed in the SD card under firmware/brcm. You can get these here and extract them in the SD card using:

curl http://static.sevangelatos.com/raspberry_pi_firmware.tar.bz2 | tar xvjf -

In case you are reading this thing from the future, you can always grab the latest firmware files from raspbian under /lib/firmware/brcm/

Now unmount the SD card, boot it on the raspberry, login as root and run setup-alpine.

Follow the instructions until you reach the network configuration you should see the message:

Available interfaces are: eth0 wlan0.
Enter ? for help on bridges, bonding and vlans.
Which one fo you want to initialize? (or '?' or 'done') [eth0] 

If you only want to initialize the wifi interface, select wlan0. Then choose your wifi network SSID and type the wifi password. You can then enter 'done' if you don't want to enable eth0. Otherwise, enable eth0 too.

Choose the default location for storing the configuration (mmcblk0p1) and the default apk cach directory (/media/mmcblk0p1/cache). This means that whenever you want to make any changes you make permanent you can issue:

lbu commit -d

and store all configuration changes on the SD card. The SD card will also act as a cache for the packages that you download.

Finalizing installation

As a final step, upgrade your system

apk update
apk upgrade

Make wpa_supplicant automatically start on boot

rc-update add wpa_supplicant boot

and save all changes:

lbu commit -d

Next steps

You can enable community packages by editing /etc/apk/repositories

vi /etc/apk/repositories

And start adding packages...


apk add tmux

Don't forget to save your changes after you are done..

lbu commit -d

Read-up the excellent alpine documentation on Alpine Package management and Alpine Local Backup.

Happy Computing!

Show Comments