I am trying out the minimal GNU/Linux distribution Alpine Linux on a Raspberry Pi. By default, Alpine for a Raspberry is run from memory and not the SD card.
There is an unofficial guide for disk-based installation at Alpine’s Wiki. The installation process described here is a more detailed version of this guide with inspiration from https://www.rigon.tk/documentation/alpine-raspberry-pi.
I am preparing the SD card on a laptop running Linux Mint.
Download the tarball for the Raspberry Pi. At the time of writing the newest version is
Mount the SD card and determine the mount point with e.g.
lsblk(8). In my case:
$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb 8:16 1 14.9G 0 disk └─sdb1 8:17 1 14.9G 0 part /media/robert/3636-3339
Unmount the partion(s):
sudo umount /dev/sdb1
- Create a bootable FAT32 partition with around 150 MB and fill the remainder of the SD card with another partition. Here I am using GNU parted. In interactive mode the FAT32 partition can be created as follows:
sudo parted /dev/sdb (parted) mklabel msdos (parted) mkpart primary fat32 1MiB 150MiB (parted) set 1 boot on (parted) quit
Alternatively, create the partitions using the shell:
sudo parted --script /dev/sdb mklabel msdos mkpart primary fat32 1MiB 150MiB mkpart primary ext4 151MiB 100%
You can verify that the partition has been created successfully in parted’s interactive mode.
- Format the partition as FAT32:
sudo mkfs.vfat -F 32 /dev/sdb1
- Extract the tarball contents to the FAT32 partition:
sudo mkdir /mnt/alpine sudo mount /dev/sdb1 /mnt/alpine sudo tar -xzf /path/to/alpine-rpi-3.7.0-armhf.tar.gz --no-same-owner -C /mnt/alpine sudo umount /mnt/alpine sudo rmdir /mnt/alpine
--no-same-owner I get permission errors from
Apparently this is because the SD card is mounted with SMB.
/mnt/alpine/config.txt on the SD card containes configurations for multiple Raspberry version.
The unnecesarry parts can be remove by changing it to be
disable_splash=0 boot_delay=0 gpu_mem=256 gpu_mem_256=32 kernel=boot/vmlinuz-rpi initramfs boot/initramfs-rpi
Insert the SD card into the Raspberry Pi and turn it on.
Log in as
root with an empty password.
Setup the installation by running
setup-alpine and save the changes with
lbu commit -d.
Note that in this disk-less installation changes are only saved if you commit them – this also includes any installed programs.
You can verify that the setup works by rebooting (with
reboot or turning off with
Once the basic setup is done, you can move on to the disk-based installation.
Create the filesystem in
/dev/mmcblk0p2(if it is not already created):
apk update apk add e2fsprogs mkfs.ext4 /dev/mmcblk0p2
Do a disk install via a mountpountYou will get some error messages from extlinux, but they can be ignored.
mkdir /stage mount /dev/mmcblk0p2 /stage setup-disk -o /media/mmcblk0p1/MYHOSTNAME.apkovl.tar.gz /stage
At this point I would run out of space on the FAT32 partition, implying that I cannot edit the files required in the remaining steps.
However, it turns out that all the disk space is consumed by the local APK cache folder,
Delete some files in this folder to free space.
Add this line to
/stage/etc/fstabto mount the Raspberry’s boot partition again:
/dev/mmcblk0p1 /media/mmcblk0p1 vfat defaults 0 0
/media/mmcblk0p1to make it writeable:and add “
mount -o remount,rw /media/mmcblk0p1
root=/dev/mmcblk0p2” to (the end of)
/media/mmcblk0p1/cmdline.txtso that it looks like
modules=loop,squashfs,sd-mod,usb-storage quiet dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2
Copy relevant boot files to the FAT32 partition. Here we first backup the previous files:
cd /media/mmcblk0p1 mkdir kernel-installer mv boot/*rpi kernel-installer/ cp /stage/boot/* boot/
After rebooting, Alpine starts from
First I create a non-root user and add it to the
wheel group (to allow changing to
adduser -G wheel robert apk add sudo visudo
wheel ALL=(ALL) ALL.
The Raspberry does not have a hardware clock and ALpine informs you of this at boot. In order to add a software clock and delete the hardware clock, run
rc-update add swclock boot rc-update del hwclock boot service hwclock stop service swclock start
An NTP daemon is needed to get the time and if one is not installed, run
setup-ntp (in my case it was already running).
Save the changes and reboot to check if the setup is working
lbu commit reboot