This tutorial will help you install Alpine Linux on your Raspberry Pi.
- Download the Alpine for Raspberry Pi tarball. 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, Raspberry Pi 3 and Compute Module 3, and Raspberry Pi 4 model B.
- Create a bootable FAT32 partition on your SD card. The partitioning and formatting part of the instructions on the linked page could be done using a graphical partitioning tool such as gnome-disks, just make sure the partition type is
W95 FAT32 (LBA). (The current type can be found in the "Type" column in the output of
- Extract the tarball to the root of the bootable FAT32 partition.
To setup a headless system, a bootstrapping configuration overlay file headless.apkovl.tar.gz may be added to enable basic networking, so that following configuration steps can be performed under
ssh. Pi Zero may be configured with simple USB ethernet-gadget networking with another computer sharing its internet connection.
Optionally create a usercfg.txt file on the partition to configure low-level system settings. Specifications can be found here. However, note some settings can only be set directly in config.txt, which may be overwritten after updates. In particular,
gpu_mem will have no effect when specified in usercfg.txt (source). Some interesting values include:
- To enable the UART console:
- To enable audio:
- If you see black edges around your screen after booting the Pi, you can add
- If you plan to install on a Pi Compute Module 4 with I/O board, you may need to add:
Recent versions include Broadcom firmware files. If you're using an older Alpine version, see section below.
For users who will be using their Raspberry Pi in scenarios where there is not expected to be significant changes to disk after setup (like running a static HTTP server), this is likely preferable, as running the entire system from memory will improve performance (by avoiding the slow SD card) and improve the SD card life (by reducing the writes to the card, as all logging will happen in RAM). Diskless installations still allow you to install packages, save local files, and tune the system to your needs.
However, if you:
- Expect there will be constant changes to the disk after initial setup (for example, if you expect people to login and save files to their home directories)
- Need logs to persist after reboot
- Plan to install packages which consume more space than can be loaded into RAM
- Want to install kernel modules (such as ZFS or Wireguard)
Then you may be better served by a sys-mode installation.
Follow these steps to install Alpine Linux in Diskless Mode:
- Insert the SD card into the Raspberry Pi and power 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
After installation, make sure your system is up-to-date:
Don't forget to save the changes:
Note: this does not upgrade the kernel. In order to upgrade the kernel, a full upgrade of the Alpine Linux version must be performed as described in upgrading Alpine Linux for removable media.
During the booting time, you might notice errors related to the hardware clock. The Raspberry Pi does not have a hardware clock, thus you need to disable the hwclock daemon and enable swclock:
Since the Raspberry Pi does not have a clock, Alpine Linux needs to know what the time is by using a Network Time Protocol (NTP) daemon. Make sure you have a NTP daemon installed and running. If you are not sure, you can install an 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 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 during bootup.
- Run it manually with
Enable OpenGL (Raspberry Pi 3/4)
Remount the boot partition writeable (i.e.
Add the following lines to
If you are experiencing graphical issues, you can also try:
And perhaps also raising the default
Note that raising the gpu memory is not likely to actually improve performance on the Pi4
Install the Mesa drivers:
As of Alpine 3.14, the WiFi drivers for the Raspberry Pi were moved from
linux-firmware-brcm to the
linux-firmware-cypress package (source?). Since the images seem to be an outdated version of the former, Wi-Fi will work during installation, but after the first update it will break.
Use the ethernet interface to download the required packages:
Loopback image with overlayfs
When you install Alpine in diskless mode, the entire system is loaded into memory at boot. If you want additional storage (for example, if you need more space than offered by your RAM) we need to create loop-back storage onto the SD card 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 using the /usr directory here, but you can use /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, not to the persistent 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 be sure to check everything you need is in that directory and not in folders you have not made persistent.
Traditional disk-based (sys) installation
This material is proposed for merging ...
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 them.
The Raspberry Pi doesn't need them to boot.
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 at shutdown.
N.B. 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, in which case, copying the files to boot partition manually, is not needed.
Persistent Installation on Raspberry Pi 3
Persistent Installation on Raspberry Pi 4
As of 3.14, setup-alpine should ask you if you want to create a sys mode partition on your Raspberry Pi 4.
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.
Alternatively, installing haveged, the random numbers generator, would speed up the process:
apk update apk add haveged rc-update add haveged boot lbu commit -d service haveged start
(Tested on a raspberry pi zero W in headless mode, no USB connected, Alpine 3.10.3)
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.
Wireless support with older Alpine images
If you need Wi-Fi, you'll need to download the latest Broadcom drivers to your SD card. (Replace /mnt/sdcard with the correct mount point.)
git clone --depth 1 https://github.com/RPi-Distro/firmware-nonfree.git cp firmware-nonfree/brcm/* /mnt/sdcard/firmware/brcm
- Classic install or sys mode on Raspberry Pi - a variant.
- Raspberry Pi 3 - Setting Up Bluetooth
- Raspberry Pi 3 - Configuring it as wireless access point -AP Mode
- Raspberry Pi 3 - Browser Client
- Linux Router with VPN on a Raspberry Pi
- Create a bootable SDHC from a Mac
- Build custom Raspberry Pi images based on Alpine via Pieman
- Tutorials and Howtos#Raspberry Pi