Preparation
-
Download the Raspberry Pi build.
Which version should I install?
TL;DR: Unless you are using Raspberry Pi 2 Model B or Raspberry Pi Zero, install
aarch64
.There are currently three versions of Alpine for Raspberry Pi:
armhf
,armv7
, andaarch64
.You should be safe using the
armhf
build on all versions including Pi Zero and Compute Modules, but it may perform less optimally on recent versions of Raspberry Pi.The
armv7
build is compatible with the Raspberry Pi 2 Model B. Theaarch64
build should be compatible with Raspberry Pi 2 Model v1.2, Raspberry Pi 3 and Compute Module 3, and Raspberry Pi 4 Model B. -
Identify your memory card name:
lsblk
.$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT mmcblk0 179:0 0 59.5G 0 disk ├─mmcblk0p1 179:1 0 174K 0 part ├─mmcblk0p2 179:2 0 1.4M 0 part └─mmcblk0p3 179:3 0 130.7M 0 part
-
Partition and format the memory card.
Install GNU Parted (
parted
) and mkfs.vfat (dosfstools
) if not available.Create a small partition for
/boot
, then allocate the rest of the disk to a separate partition.sudo parted /dev/mmcblk0 --script -- mklabel msdos sudo parted /dev/mmcblk0 --script -- mkpart primary fat32 1 256M sudo parted /dev/mmcblk0 --script -- mkpart primary ext4 256M 100%
Set the boot partition flags and format.
sudo parted /dev/mmcblk0 --script -- set 1 boot on sudo parted /dev/mmcblk0 --script -- set 1 lba on sudo mkfs.fat -F32 -I /dev/mmcblk0p1 sudo mkfs.ext4 /dev/mmcblk0p2
You can verify by printing the partition table.
sudo parted /dev/mmcblk0 --script print
-
Mount the boot partition.
sudo mount /dev/mmcblk0p1 /mnt/sd
-
Unpack the Alpine package onto the partition.
sudo tar xf alpine-rpi-**.tar.gz -C /mnt/sd --no-same-owner
-
Create the
usercfg.txt
file into the boot partition:/mnt/sd/usercfg.txt
.# Enable mini UART as serial port (/dev/ttyS0). # Also, fixes VideoCore IV (aka the GPU or the VPU) frequency to 250MHz. enable_uart=1 # give the GPU the least amount of RAM it can get by with (16MB). # This also triggers the Pi to use a cutdown version of the firmware (start_cd.elf). gpu_mem=16 # Optionally turn off audio and bluetooth. (Note "dt" stands for device tree) dtparam=audio=off,pi3-disable-bt
-
Headless Installation (optional)
If you don’t have direct access to your system, such as via a display and keyboard you can install Alpine with the overlay directory structure and headless script.
sudo curl -L -o /mnt/sd/headless.apkovl.tar.gz https://github.com/davidmytton/alpine-linux-headless-raspberrypi/releases/download/2021.06.23/headless.apkovl.tar.gz
-
Wifi Configuration (optional)
With the headless script installed. Create the
wifi.txt
into the boot partition:/mnt/sd/wifi.txt
.ssid password
-
Copy an answer file (optional).
During the setup process an answer file can be provided to automate the configuration process.
-
Unmount.
sudo umount /mnt/sd
Installation
-
Log in into Alpine with the default username and password. If you have a headless installation you can ssh into the Raspberry Pi.
Default Alpine login credentials are username
root
with empty password. -
Run setup.
setup-alpine
Alternatively to the interactive mode, an answer file can be provided during the preparation to automate the configuration process.
setup-alpine -f /media/mmcblk0p1/alpine-setup.txt
-
Create system partitions.
Resize the FAT32 partition to 1GB and use the remaining space to create a new primary bootable partition where Alpine Linux is gonna being installed.
apk add e2fsprogs mkfs.ext4 /dev/mmcblk0p2 mount /dev/mmcblk0p2 /mnt
-
Install the system files.
setup-disk -m sys /mnt
If you get
ext4 is not supported . Only supported are: vfat
error, run withFORCE_BOOTFS
set.FORCE_BOOTFS=1 setup-disk -m sys /mnt
-
Remount old partition in RW. An update in the first partition is required for the next reboot.
mount -o remount,rw /media/mmcblk0p1
-
Clean up the boot folder in the first partition to drop unused files.
rm -f /media/mmcblk0p1/boot/* cd /mnt rm boot/boot
-
Move the image and
init ram
for Alpine Linux into the right place.mv boot/* /media/mmcblk0p1/boot rm -Rf boot mkdir media/mmcblk0p1 # It's the mount point for the first partition on the next reboot
-
Update
/etc/fstab
:echo "/dev/mmcblk0p1 /media/mmcblk0p1 vfat defaults 0 0" >> etc/fstab sed -i '/cdrom/d' etc/fstab sed -i '/floppy/d' etc/fstab
-
Enable edge repository.
sed -i '/edge/s/^#//' /mnt/etc/apk/repositories
-
For the next boot, indicate that the root filesystem is on the second partition. If the cmdline.txt file contains a line that starts with /root, then use sed:
sed -i 's/$/ root=\/dev\/mmcblk0p2 /' /media/mmcblk0p1/cmdline.txt
-
Make sure that appropriate
cgroups
are enabledsed -i "s/$/ cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1/" /media/mmcblk0p1/cmdline.txt
-
If using
chrony
, allow the system clock to be stepped in the first three updates if its offset is larget than 1 second.echo "makestep 1.0 3" >> /etc/chrony/chrony.conf
-
Reboot
Get my latest posts and updates. Subscribe to my newsletter.