This tutorial will help you install Alpine Linux on your Raspberry Pi.
This section will help you format and partition your SD card:
- Download Alpine for Raspberry Pi tarball for the armhf architecture which is named as
alpine-rpi-<version>-armhf.tar.gz. You will need version 3.2.0 or greater if you have a Raspberry Pi 2.
- Mount your SD card to your workstation
- Use gnome-disks or fdisk to create a FAT32 partition. If you are using fdisk, the FAT32 partition type is called W95 FAT32 (LBA) and its ID is 0x0C.
- Mark the newly created partition as bootable and save
- If you used fdisk to create the partition you need to create a filesystem on it with mkdosfs -F 32 /dev/sdX1
- Mount the previously created partition
- Extract the tarball contents to your FAT32 partition
- Unmount the SD Card.
Note: You should be safe using the armhf build on all versions of Raspberry Pi (including Pi Zero and Compute Modules); but it may perform less optimally on recent versions of Raspberry Pi. The armv7 build is compatible with Raspberry Pi 2 Model B. The aarch64 build should be compatible with Raspberry Pi 2 Model v1.2, and is compatible with Raspberry Pi 3 and Compute Module 3.
Optionally create a "usercfg.txt" file on your SD card to configure low-level system settings. Specifications can be found here. Some interesting values include:
- Enable audio: dtparam=audio=on
- If you see black edges around your screen after booting the Pi, you can add: disable_overscan=1
If you need WiFi to work, perform the following before unmounting the SD card:
- Download the latest Broadcom drivers for the Raspberry Pi to your machine and
- Copy them to [SD card]/firmware/brcm/.
git clone --depth 1 https://github.com/RPi-Distro/firmware-nonfree.git
cp firmware-nonfree/brcm/* [SD card]/firmware/brcm
- Insert the SD card into the Raspberry Pi and turn it on
- Login into the Alpine system as root. Leave the password empty.
- Once the installation is complete, commit the changes by typing
lbu commit -d
reboot to verify that the installation was indeed successful.
Update the System
Upon installation, make sure that your system is up-to-date:
Don't forget to save the changes:
During the booting time, you might notice errors related to the hardware clock. The Raspberry Pi does not have a hardware clock and therefore you need to disable the hwclock daemon and enable swclock:
Since Raspberry Pi does not have a clock, the Alpine Linux needs to know what the time is by using a Network Time Protocol (NTP) daemon. Make sure that you a NTP daemon installed and running. If you are not sure, then you can install NTP client by running the following command:
The Busybox NTP client might be the most lightweight solution. Save the changes and reboot, once the NTP software is installed and running:
After reboot, make sure that the
date command outputs the correct date and time.
WiFi on boot
If you have already configured WiFi during the setup, the connection will not return on reboot. You will need to start up a service to automatically connect to the wireless access point.
rc-update add wpa_supplicant bootto connect to the wireless access point on boot.
- Run it manually with
Enable OpenGL (Raspberry Pi 3)
Remount the boot partition writeable (ie. /media/mmcblk0p1):
Add the following lines to /media/mmcblk0p1/config.txt
256MB gpu_mem is also possible
Loopback image with overlayfs
The install is in diskless mode and forces everything into memory, if you want additional storage we need to create loop-back storage onto the SD mounted with overlayfs.
First make the SD card writable again and change fstab to always do so:
Create the loop-back file, this example is 1 GB:
Install the ext utilities:
Format the loop-back file:
Mount the storage:
Make the overlay folders, we are doing /usr here, but you can do /home or anything else:
Your /etc/fstab should look something like this:
Now commit the changes: (optionally remove the e2fsprogs, but it does contain repair tools)
Remember with this setup, if you install things and you have done this overlay for /usr, you must not commit the 'apk add', otherwise while it boots it will try and install it to memory and not to the persist storage.
If you do want to install something small at boot you can use `apk add` and `lbu commit -d`.
If it is something a bit bigger then you can use `apk add` but then not commit it, it will be persistent (in /user), but do check everything you need is in that directory and not in folders you have not made persistent.
Traditional disk-based (sys) installation
It is also possible to switch to a fully disk-based installation: this is not yet formally supported, but can be done somewhat manually. This frees all the memory otherwise needed for the root filesystem, allowing more installed packages.
Split your SD card into two partitions: the FAT32 boot partition described above (in this example it'll be
mmcblk0p1) , and a second partition to hold the root filesystem (here it'll be
mmcblk0p2). Boot and configure your diskless system as above, then create a root filesystem:
Now do a disk install via a mountpoint. The
setup-disk script will give some errors about syslinux/extlinux, but you can ignore these: the Raspberry Pi doesn't need this to boot anyway.
Add a line to
/stage/etc/fstab to mount the Pi's boot partition again:
Now add a
root=/dev/mmcblk0p2 parameter to the Pi's boot command line, either
cmdline-rpi.txt depending on model:
You might also consider
overlaytmpfs=yes here, which will cause the underlying SD card root filesystem to be mounted read-only, with an overlayed tmpfs for modifications which will be discarded on shutdown.
Beware, though, that the contents of /boot will be ignored when the Pi boots: it will use the kernel, initramfs, and modloop images from the FAT32 boot partition. To update the kernel, initfs or modules, you will need to manually (generate and) copy these to the boot partition or you could use bind mount so that manually copy the files to boot partition is not needed.
Persistent Installation on Raspberry Pi 3
Long boot time when running headless
If no peripherals are connected the system might hang for an exceptionally long period of time while it attempts to accumulate entropy.
If this is the case simply plugging in any USB device should work around this issue.
apk indicating 'No space left on device'
Note some models of the Raspberry Pi such as the 3A+ only have 512M of RAM, which on fresh Alpine deployment will only leave around 200M for tmpfs root. It's important to keep this limitation in mind when using these boards.