Raspberry Pi: Difference between revisions

From Alpine Linux
m (update on current state of install for RBPI2 with SDCARD system)
m (wording tweaks)
 
(198 intermediate revisions by 52 users not shown)
Line 1: Line 1:
[[Category:Installation]]
{{TOC right}}
This tutorial will help you install Alpine Linux on your Raspberry Pi.
 
Raspberry Pi devices are well supported on Alpine Linux by default. This page enlightens few specific information like [[#Preparing_for_the_installation| install media creation]], [[#Post_Installation| post-install]] customization and [[#Troubleshooting| troubleshooting]].
 
== Compatibility list ==
 
Refer to the information regarding Raspberry Pi models in the below table when choosing image/file to download from [https://alpinelinux.org/downloads/ Downloads] page for your device. [[Installation#Verifying_downloaded_image|Verify]] the downloaded image before proceeding further.
{|class="wikitable" align="center" style="width:100%; border:1px #0771a6 solid; background:#f9f9f9; text-align:left; border-collapse:collapse;"
|- style="background:#333333; color:#ffffff; font-size: 1.2em; text-align:center;"
| colspan="4" |Alpine Linux Hardware Support Matrix
|-
! Architecture !! Port !! Description !! Since
|-
{{:Include:Arm support matrix}}
|}
== Preparing the installation media ==
 
=== Raspberry Pi Imager ===
 
[https://www.raspberrypi.com/news/raspberry-pi-imager-imaging-utility Raspberry Pi Imager] is a GUI utility for creating distributions install media for Pi devices in few clicks: it takes care of downloading, partitioning and formatting. Pre-built binaries are available for [https://github.com/raspberrypi/rpi-imager/releases Linux/macOS/Windows].<br>
 
Alpine Linux is listed under '''Other general-purpose OS''' section from '''Choose OS''' tab.
 
This utility can also be used from an Alpine linux system: install the {{pkg|rpi-imager}} package from [[Repositories#Using_testing_repository|testing]] repository. To launch the utility in graphical mode issue the command: {{Cmd|rpi-imager}}
 
'''--cli''' option is also available. For complete usage guide, check out the <code>rpi-imager(1)</code> manpages, which you can [[install]] with the {{Pkg|rpi-imager-doc}} package.
 
=== Manual method ===
 
Alternatively, the Alpine Linux image/tarball for Raspberry Pi may be [https://alpinelinux.org/downloads/ downloaded], and SD card install media can be prepared.  Use the [[#Compatibility list|compatibility list]] above when choosing image/tarball to download.
 
{{Tip|To reduce SD wear risk, it is advised to keep at least 10% of capacity as unallocated space. If partitioned  previously at full capacity, run <code>blkdiscard /dev/mmcblk0</code> to ensure [https://man7.org/linux/man-pages/man8/blkdiscard.8.html device sectors are discarded] before re-partitioning.}}


== Preparation ==
* For image file i.e ''img.gz'', follow the regular [[Installation#Preparing installation media|installation media preparation steps]] to create a SD card which can be used as a [[Create a Bootable Device|customizable boot device]].


This section will help you format and partition your SD card:
* For tarball i.e ''tar.gz'', the SD card needs to be prepared i.e partitioned and formatted first.


# [http://alpinelinux.org/downloads/ Download] Alpine for Raspberry Pi tarball which is named as <code>alpine-rpi-<version>-armhf.rpi.tar.gz</code>.  You will need version 3.2.0 or greater if you have a Raspberry Pi 2.
# Create a '''FAT32''' partition and format it using a graphical partitioning tool such as [https://en.wikipedia.org/wiki/GNOME_Disks gnome-disks] or [https://gparted.org gparted]: just make sure the partition type is <code>W95 FAT32 (LBA)</code>. (The current type can be found in the "Type" column in the output of <code>fdisk -l</code>.)
# Mount your SD card to your workstation
#: {{warning|Do not use the volume label <code>boot</code> for the FAT partition. Due to an upstream firmware [https://github.com/raspberrypi/firmware/issues/1529 bug], kernel/initramfs cannot be loaded from subdirectory with same name as volume label. Since kernel is installed to <code>boot/</code> folder in Alpine Linux, do not use the volume label <code>boot</code> for the FAT partition.}}
# Use [https://en.wikipedia.org/wiki/GNOME_Disks gnome-disks] or [http://linux.die.net/man/8/fdisk fdisk] to create a FAT32 partition.  If you are using fdisk, the FAT32 partition type is called ''W95 FAT32 (LBA)'' and its ID is 0xC.
# Extract the tarball to the root of the bootable FAT32 partition.
# Mark the newly created partition as bootable and save
# Mount the previously created partition
# Extract the tarball contents to your FAT32 partition
# Unmount the SD Card.


== Installation ==


Alpine Linux will be installed as [[Installation#Installation_Handbook|diskless mode]], hence you need to use [[Alpine local backup|Alpine Local Backup (lbu)]] to save your modifications between reboots. Follow these steps to install Alpine Linux:
{{Note|Using image file or Raspberry Pi Imager will create a minimum-sized FAT16 volume with only about [https://gitlab.alpinelinux.org/alpine/aports/-/blob/98f4e18d0ab978e3a6dd6fad23cbbd4464a5cdc8/scripts/mkimg.arm.sh#L56 8MB of free space]. If using same media for Diskless/Data-disk Modes with large add-on packages, you may want to [[#Resize partition created with image file|grow that partition]] for more ample packages cache storage, or follow the tarball [[#Manual method|Manual method]] and allocate optimal partition size.}}


# Insert the SD Card into the Raspberry Pi and turn it on
== Considerations for choosing install modes ==
# Login into the Alpine system as root.  Leave the password empty.
# Type <code>setup-alpine</code>
# Once the installation is complete, commit the changes by typing <code>lbu commit</code>


Type <code>reboot</code> to verify that the installation was indeed successful.
The installation procedure for Alpine Linux '''requires basic understanding of the three modes''' i.e [[Installation#Installation_Overview|diskless/data disk/system disk]].  


== Post Installation ==
[[Diskless Mode|Diskless mode]] may be preferable on a pi with SD Card as the only storage device, 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). This mode is suitable for scenarios where there is not expected to be significant changes to disk after setup (like running a static HTTP server)


=== Update the System ===
[[Classic install or sys mode on Raspberry Pi|System disk]] mode installation may be more appropriate for the following use cases:


Upon installation, make sure that your system is up-to-date:
* 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)
* Logs should persist across reboots
* Plan to install packages which consume more space than can be loaded into RAM
* Plan to install kernel modules (such as ZFS)


{{cmd|apk update
System disk mode with [[OverlayFS#Immutable_root_with_tmpfs_overlay|Immutable root option]] can also be a solution to keep whole system on read-only media (lower RAM requirement than diskless mode which loads whole system in RAM) while avoiding SD wear as runtime files are mapped to ''tmpfs'' in RAM (check limitations).
apk upgrade}}


Don't forget to save the changes:
== Installation ==


{{cmd|lbu commit}}
{{Tip|To install Alpine Linux on a Pi without keyboard, mouse & display, additional preparatory steps for install media are available at [[Installation on a headless host|headless Installation]] page.}}


=== Clock-related error messages ===
Once [[#Preparing the installation media|install media is prepared]], proceed to perform [[Installation#Base_configuration|standard procedures]] for actual install and initial base setup.


During the booting time, you might notice errors related to the hardware clock. The Raspberry Pi does not have
After install and reboot, check notes below for further customization and [[#Troubleshooting| troubleshooting]].
a hardware clock and therefore you need to disable the hwclock daemon and enable swclock:


{{cmd|rc-update add swclock boot    # enable the software clock
== Post Installation ==
rc-update del hwclock boot    # disable the hardware clock}}


Since Raspberry Pi does not have a clock, the Alpine Linux needs to know what the time is by using a
=== Customize ''config.txt'' and ''usercfg.txt'' ===
[https://en.wikipedia.org/wiki/Network_Time_Protocol 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:


{{cmd|setup-ntp}}
Instead of the BIOS found on a conventional PC, Raspberry Pi devices use a configuration file called '''config.txt'''. The GPU reads '''config.txt''' before the Arm CPU and Linux initialise.
It is recommended to create a custom '''usercfg.txt''' file on boot partition to configure low-level system settings, as '''config.txt''' may be replaced during bootloader/system upgrades. However, few [https://www.raspberrypi.com/documentation/computers/config_txt.html#include settings] can only be set within '''config.txt''', and will have no effect when specified in '''usercfg.txt''' (e.g. <code>gpu_mem</code>). All available settings information can be found [https://www.raspberrypi.com/documentation/computers/config_txt.html here].<br>
Some noteworthy settings include:
* <code>dtparam=audio=on</code> to enable audio support with <code>snd_bcm2835</code> driver for onboard audio jack and legacy hdmi audio mode.
* By default system will use ''legacy video driver'': some [https://www.raspberrypi.com/documentation/computers/legacy_config_txt.html#legacy-video-options options] may be used to adjust displays modes (e.g. if you see black edges around your screen after booting the Pi, you can add <code>disable_overscan=1</code>). Alternatively, better supported ''Linux DRM-KMS driver'' may be used (see setup[[#Linux_Kernel_Graphics_Modes| below]]).
* Enabling default serial console with <code>enable_uart=1</code>, together with <code>console=serial0,115200</code> in ''cmdline.txt'' kernel parameters list.
* To maximize available CPU memory if not requiring extra GPU features (i.e. headless/CLI use-cases), cut-down bootloader may be installed with {{Pkg|raspberrypi-bootloader-cutdown|arch=}} package, and activated by adding <code>gpu_mem=16</code> in '''config.txt''' (setting may be wiped after bootloader package update).
* If you plan to install on a Pi Computer Module 4 with I/O board, you may need to add: <code>otg_mode=1</code>


Busybox NTP client might be the most lightweight solution.  Save the changes and reboot, once the NTP software is
=== Update the System ===
installed and running:


{{cmd|lbu commit
After installation, [[Alpine_Package_Keeper#Upgrade_a_Running_System|check and apply updates]] to keep your system secure.
reboot}}


After reboot, make sure that the <code>date</code> command outputs the correct date and time.
=== Linux Kernel Graphics Modes ===


=== X11 Setup ===
By default system configuration will use legacy video driver: while it may remain well suited for [https://forums.raspberrypi.com/viewtopic.php?t=310315#p1856052 lower-ram devices] (i.e. Pi Zero/1), this driver has some limitations and is now lacking support.<br>
Here are what you need if you want to try and run a single X11 application like a browser kiosk or maybe even a desktop: ​{{cmd|setup-xorg-base
Linux DRM-KMS driver is recommended for most devices: it is enabled by adding the following to '''usercfg.txt''':
​apk add xf86-video-fbdev xf86-input-mouse xf86-input-keyboard dbus ​set​xkbmap
# Enable DRM VC4 V3D driver
rc-update ​​add dbus}}
dtoverlay=vc4-kms-v3d
max_framebuffers=2
# Don't have the firmware create an initial video= setting in cmdline.txt.
# Use the kernel's default instead.
disable_fw_kms_setup=1


Also edit the default X11 module config: /etc/X11/xorg.conf.d/20-modules.conf
{{Note|<code>vc4-kms-v3d</code> overlay:
{{cmd|Section "Module"
* ignores legacy video [https://www.raspberrypi.com/documentation/computers/legacy_config_txt.html#legacy-video-options options] from '''usrcfg.txt''' / '''config.txt'''.
    Load "fbdevhw"
* enables Linux HDMI audio support by [https://www.raspberrypi.com/documentation/computers/config_txt.html#hdmi-audio default]. Eventual onboard audio jack still needs legacy <code>snd_bcm2835</code> driver through <code>dtparam{{=}}audio{{=}}on</code> option in '''usrcfg.txt'''.
    Load "fb"
* enables HDMI cec device within <code>/sys/class/rc</code>, supported through standard {{pkg|libcec|arch=}}.}}
    Load "shadow"
    Load "shadowfb"
    Load "dbe"
    Load "glx"
    Disable "dri"
EndSection}}


Commit your changes:
3D Mesa drivers may be also added for [https://docs.mesa3d.org/drivers/vc4.html vc4] (Pi Zero-3) or [https://docs.mesa3d.org/drivers/v3d.html v3d] (Pi 4-5) devices:{{cmd|apk add {{pkg|mesa-dri-gallium|arch=}}}}
{{cmd|lbu_commit}}
[https://forums.raspberrypi.com/viewtopic.php?t=363368#p2179572 vc4 devices limitations] in memory management may require regular reboots.


Now you should be able to run a browser or desktop. (Guides may follow)
=== Wireless drivers ===


== Persistent storage ==
As of Alpine 3.17, Wifi and Bluetooth drivers are available within install image: they are part of <code>linux-firmware-brcm</code> (and linked dependencies). Since kernel 6.1.25 (i.e. Alpine 3.18), onboard bluetooth is enabled & autoprobed by default. This may be disabled by setting [https://github.com/raspberrypi/rpi-firmware/tree/master/overlays krnbt] off).


=== Loopback image with overlayfs ===
Adding the following file to disable roaming and few other <code>brcmfmac</code> driver features [https://github.com/RPi-Distro/firmware-nonfree/commit/2788cb549a19bf2e77901c4071ef88c2ad683b7c may improve wifi stability].<br>
<code>$cat /etc/modprobe.d/brcmfmac.conf<br>
options brcmfmac roamoff=1 feature_disable=0x282000</code>


The install is in disk-less mode and forces everything into memory, if you want additional storage we need to create loop-back storage onto the SD mounted with overlayfs.
''Alternatively'' same parameters may be passed all-in-one-line to kernel from '''cmdline.txt''' as:<br>
<code>brcmfmac.roamoff=1 brcmfmac.feature_disable=0x282000</code>


First make the sd-card writable again and change fstab to always do so:
{{Note|On Alpine 3.22.0, aforementioned <code>brcmfmac</code> driver options '''must''' be applied to circumvent an issue due to [https://gitlab.alpinelinux.org/alpine/aports/-/issues/17195 shipping <code>wpa_supplicant</code>]. This is fixed from 3.22.1.}}
{{cmd|mount /media/mmcblk0p1 -o rw,remount
sed -i 's/vfat\ ro,/vfat\ rw,' /etc/fstab}}


Create the loop-back file, this example is 1 GB:
=== USB-gadget ===


{{cmd|dd if&#61;/dev/zero of&#61;/media/mmcblk0p1/persist.img bs&#61;1024 count&#61;0 seek&#61;1048576}}
Pi Zeros/A/A+/3A+/4B/400/5/500/CMs may be configured in various [https://trac.gateworks.com/wiki/linux/OTG#USBDeviceMode USB-gadget roles] (or a composite combination thereof) connected to host via USB: such roles may be serial-gadget (i.e. console access for setup), ethernet-gadget for networking, mass-storage (appear as USB disk), webcam, keyboard, etc...


Install the ext utilities:
This may be achieved by loading relevant drivers & options in early boot sequence: in any case <code>dtoverlay=dwc2,dr_mode=peripheral</code> must be added to '''usercfg.txt'''.<br>
Then, for instance, serial gadget may be enabled with <code>echo "g_serial" | tee -a /etc/modules-load.d/gadget.conf</code> (or adding <code>modules=g_serial</code> in '''cmdline.txt''').


{{cmd|apk add e2fsprogs}}
{{Tip|community <code>{{pkg|xg_multi|arch=}}</code> package may ease setup for serial/ethernet/mass-storage composite gadget, while ensuring interoperability across most host OS.}}


Format the loop-back file:
=== Picam ===


{{cmd|mkfs.ext4 /media/mmcblk0p1/persist.img}}
{{Note| The below instructions has been tested only in [[Classic install or sys mode on Raspberry Pi|sys mode]] install with Pi Zero 2W.}}


Mount the storage:  
# To use {{pkg|rpicam-apps|arch=}} package, upgrade to [[Repositories#Upgrading_to_edge|edge]] branch.
# Setup eudev as device manager:{{Cmd|# setup-devd udev}}
# Add <Code>camera_auto_detect=1</Code> option to the user config file {{Path|/boot/usercfg.txt}}
# Install the package {{pkg|rpicam-apps|arch=}} available in the [[Repositories#Testing|testing]] repository.
# Due to bug {{Issue|16911}}, change the permission after every reboot as follows:{{Cmd|$ doas chmod 666 /dev/dma_heap/*}}
# Test the picam by the command {{Cmd|$ libcamera-hello --list-cameras}}


{{cmd|echo "/media/mmcblk0p1/persist.img /media/persist ext4 rw,relatime,errors&#61;remount-ro 0 0" >> /etc/fstab
=== Resize partition created with image file ===
mkdir /media/persist
Media created from image file (manually or with [[#Raspberry Pi Imager|Raspberry Pi Imager]]) can '''cautiously''' be resized [https://www.pctechguide.com/hard-disks/file-systems-fat-fat8-fat16-fat32-and-ntfs-explained up to 128MB](as base image is created as FAT16 with 2k clusters) with <code>[https://serverfault.com/questions/994448/extend-linux-partition-size-without-losing-any-data-techniques fdisk]</code> (<code>parted</code>-based tools may fail doing so).<br>
mount -a}}
Proceed with care to delete <code>d</code>, and then <code>n</code> recreate primary partition of desired size-1MB (will start at sector 2048 by default), change it to <code>06</code> (FAT16) with <code>t</code> command, and go to <code>x</code> extra menu and then <code>b</code> (move beginning of data in a partition to <code>0</code> -- mind this increases size by 2048 sectors=1MB). Finally return <code>r</code> and write <code>w</code> new partition table.<br>
Then filesystem needs to be resized accordingly with <code>fatresize</code>.<br>
This should not destroy existing data.<br>
For exemple scripting it (128MB size):
{{Cmd|doas fdisk /dev/sda <<EOF 
d
n
p
1
2048
+127M
t
06
x
b
0
r
w
EOF
doas fatresize -s 128M /dev/sda}}


Make the overlay folders, we are doing /usr here, but you can do /home or anything else:
== Custom installation instructions ==


{{cmd|mkdir /media/persist/usr
* [[Classic_install_or_sys_mode_on_Raspberry_Pi#Convert diskless to sys mode|Convert diskless to sys mode]].  
mkdir /media/persist/.work
* An alternate approach [[OverlayFS#Loopback image with overlayfs|using loopback image with overlayfs]] for memory constrained Raspberry Pi models (3A+,Pi Zero) with only 512M of RAM running Diskless mode.
echo "overlay /usr overlay lowerdir&#61;/usr,upperdir&#61;/media/persist/usr,workdir&#61;/media/persist/.work 0 0" >> /etc/fstab
* [[Netbooting Raspberry Pi]] device
mount -a}}


Your /etc/fstab should look something like this:
== Troubleshooting ==
{{Cmd|/dev/cdrom      /media/cdrom    iso9660 noauto,ro 0 0
/dev/usbdisk    /media/usb      vfat    noauto,ro 0 0
/dev/mmcblk0p1 /media/mmcblk0p1 vfat rw,relatime,fmask&#61;0022,dmask&#61;0022,errors&#61;remount-ro 0 0
/media/mmcblk0p1/persist.img /media/persist ext4 rw,relatime,errors&#61;remount-ro 0 0
overlay /usr overlay lowerdir&#61;/usr,upperdir&#61;/media/persist/usr,workdir&#61;/media/persist/.work 0 0}}


Now commit the changes: (optionally remove the e2fsprogs, but it does contain repair tools)
<code>raspinfo</code> utility from the {{Pkg|raspberrypi-utils-raspinfo|arch=}} package can be used as a first step to diagnose issues: it will make a log report of essential Pi system configuration, and is often used as a reference to submit questions or bug reports within Raspberry Pi community (Forums, Github, etc).
{{cmd|lbu_commit}}


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.
After booting, you may find less system memory available than you expect, as default CPU/GPU RAM split depends on Pi models and activated settings (audio, camera, video drivers, etc). To find out how your system is actually split, use <Code>vcgencmd</Code> utility from the {{pkg|raspberrypi-utils-vcgencmd|arch=}} package as follows:{{Cmd|<nowiki># vcgencmd get_mem gpu
# vcgencmd get_mem arm</nowiki>}}


If you do want to install something small at boot you can use `apk add` and `lbu commit`.
To modify the memory allocation refer to ''legacy'' [https://www.raspberrypi.com/documentation/computers/legacy_config_txt.html#gpu_mem gpu_mem] parameter information for '''config.txt'''.


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.
=== Long boot time when running headless ===


=== Traditional disk-based (sys) installation ===
If no peripherals are connected, the system might hang for an exceptionally long period of time while it attempts to accumulate entropy.


{{Warning|This isn't yet supported by the Alpine setup scripts for Raspberry Pi. It requires manual intervention, and might break.}}
If this is the case, simply plugging in any USB device should work around this issue, since it increases the amount of entropy available to the kernel via interrupts.


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.
=== apk indicating 'No space left on device' ===


Split your SD card into two partitions: the FAT32 boot partition described above (in this example it'll be <code>mmcblk0p1</code>) , and a second partition to hold the root filesystem (here it'll be <code>mmcblk0p2</code>). Boot and configure your diskless system as above, then create a root filesystem:
While running Raspberry Pi models with only 512M of RAM (i.e. Zero, 3A+), a fresh Alpine Linux installation in Diskless mode will only leave around 200M for tmpfs root. Such allocation may be [[Diskless_Mode#Modifying_root_filesystem_size| tuned]] or alternative install modes shall be [[#Considerations_for_choosing_install_modes| considered]].


{{cmd|apk add e2fsprogs
=== Clock-related error messages ===
mkfs.ext4 /dev/mmcblk0p2}}


Now do a disk install via a mountpoint. The <code>setup-disk</code> script will give some errors about syslinux/extlinux, but you can ignore these: the Raspberry Pi doesn't need this to boot anyway.
During the booting time, you might notice errors related to the hardware clock.  Many Raspberry Pi do not have a hardware clock, or may have one without battery, in which case the behaviour depends on whether you physically cut power or not.  


{{cmd|<nowiki>mkdir /stage
Also, <code>setup-alpine</code> will adapt the installation to the type of Raspberry Pi you use, which means for example that on a RPI5, you will see <code>hwclock></code> service, whereas on a RPI4 it will use <code>swclock</code>. In doubt, make sure to do the installation on the target hardware.
mount /dev/mmcblk0p2 /stage
setup-disk -o /media/mmcblk0p1/MYHOSTNAME.apkovl.tar.gz /stage
# (ignore errors about syslinux/extlinux)</nowiki>}}


Add a line to <code>/stage/etc/fstab</code> to mount the Pi's boot partition again:
If you still experience clock errors, add the following line to '''/etc/chrony/chrony.conf''':


{{cmd|/dev/mmcblk0p1 /media/mmcblk0p1 vfat defaults 0 0}}
<code>makestep 0.1 3</code>


Now add a <code>root=/dev/mmcblk0p2</code> parameter to the Pi's boot command line, either <code>cmdline-rpi2.txt</code> or <code>cmdline-rpi.txt</code> depending on model:
=== Wireless support with older Alpine images ===


{{cmd|<nowiki>mount -o remount,rw /media/mmcblk0p1
In Alpine 3.14, the WiFi drivers for the Raspberry Pi were moved from <code>linux-firmware-brcm</code> to the <code>linux-firmware-cypress</code> 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.
sed -i '$ s/$/ root=\/dev\/mmcblk0p2/' /media/mmcblk0p1/cmdline-rpi2.txt</nowiki>}}
Use the ethernet interface to download the required packages:


You might also consider <code>overlaytmpfs=yes</code> 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.
{{cmd|apk add {{pkg|linux-firmware-cypress|arch=a*}}}}


Beware, though, that <b>the contents of /boot will be ignored when the Pi boots</b>: 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, too.
And reboot.


# NOTE !
If you need Wi-Fi, you'll need to [https://github.com/RPi-Distro/firmware-nonfree/tree/master/brcm download] the latest Broadcom drivers to your SD card.
# The for mentioned is not consistent with the most recent release of Alpine Linux, there's no need to specify -o ....
(Replace /mnt/sdcard with the correct mount point.)
# this needs to be rewritten and become more consisten awaiting an ArmHF ISO to be released


  git clone --depth 1 https://github.com/RPi-Distro/firmware-nonfree.git
  cp firmware-nonfree/brcm/* /mnt/sdcard/firmware/brcm


== See Also ==
== See also ==


* [[Classic install or sys mode on Raspberry Pi]]
* [[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]]
* [[Netbooting Raspberry Pi]]
* [[Create a bootable SDHC from a Mac]]
* [[Create a bootable SDHC from a Mac]]
* [[OverlayFS‎‎]]
* Build custom Raspberry Pi images based on Alpine via [https://github.com/tolstoyevsky/pieman Pieman]
* [[Tutorials and Howtos#Raspberry Pi]]
[[Category:Installation]]
[[Category: Raspberry]]

Latest revision as of 09:33, 13 October 2025

Raspberry Pi devices are well supported on Alpine Linux by default. This page enlightens few specific information like install media creation, post-install customization and troubleshooting.

Compatibility list

Refer to the information regarding Raspberry Pi models in the below table when choosing image/file to download from Downloads page for your device. Verify the downloaded image before proceeding further.

Alpine Linux Hardware Support Matrix
Architecture Port Description Since
ARM armhf 32 bit ARM with hard-float ABI - for ARMv6 devices- Raspberry Pi 1, Zero, ZeroW, cm1 (defconfig bcmrpi) v3.0
armv7 32 bit ARM - for ARMv7 devices - Raspberry Pi 2, 3, 3+, Zero2W, cm3, cm3+ (defconfig bcm2709) v3.9
aarch64 64 bit ARM - for ARMv8+ devices - Raspberry Pi 3, 3+, 4, 400, Zero2W, cm3, cm3+, cm4, 5, 500, 500+, cm5 (defconfig bcm2711) v3.5

Preparing the installation media

Raspberry Pi Imager

Raspberry Pi Imager is a GUI utility for creating distributions install media for Pi devices in few clicks: it takes care of downloading, partitioning and formatting. Pre-built binaries are available for Linux/macOS/Windows.

Alpine Linux is listed under Other general-purpose OS section from Choose OS tab.

This utility can also be used from an Alpine linux system: install the rpi-imager package from testing repository. To launch the utility in graphical mode issue the command:

rpi-imager

--cli option is also available. For complete usage guide, check out the rpi-imager(1) manpages, which you can install with the rpi-imager-doc package.

Manual method

Alternatively, the Alpine Linux image/tarball for Raspberry Pi may be downloaded, and SD card install media can be prepared. Use the compatibility list above when choosing image/tarball to download.

Tip: To reduce SD wear risk, it is advised to keep at least 10% of capacity as unallocated space. If partitioned previously at full capacity, run blkdiscard /dev/mmcblk0 to ensure device sectors are discarded before re-partitioning.
  • For tarball i.e tar.gz, the SD card needs to be prepared i.e partitioned and formatted first.
  1. Create a FAT32 partition and format it using a graphical partitioning tool such as gnome-disks or gparted: just make sure the partition type is W95 FAT32 (LBA). (The current type can be found in the "Type" column in the output of fdisk -l.)
    Warning: Do not use the volume label boot for the FAT partition. Due to an upstream firmware bug, kernel/initramfs cannot be loaded from subdirectory with same name as volume label. Since kernel is installed to boot/ folder in Alpine Linux, do not use the volume label boot for the FAT partition.

  2. Extract the tarball to the root of the bootable FAT32 partition.


Note: Using image file or Raspberry Pi Imager will create a minimum-sized FAT16 volume with only about 8MB of free space. If using same media for Diskless/Data-disk Modes with large add-on packages, you may want to grow that partition for more ample packages cache storage, or follow the tarball Manual method and allocate optimal partition size.

Considerations for choosing install modes

The installation procedure for Alpine Linux requires basic understanding of the three modes i.e diskless/data disk/system disk.

Diskless mode may be preferable on a pi with SD Card as the only storage device, 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). This mode is suitable for scenarios where there is not expected to be significant changes to disk after setup (like running a static HTTP server)

System disk mode installation may be more appropriate for the following use cases:

  • 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)
  • Logs should persist across reboots
  • Plan to install packages which consume more space than can be loaded into RAM
  • Plan to install kernel modules (such as ZFS)

System disk mode with Immutable root option can also be a solution to keep whole system on read-only media (lower RAM requirement than diskless mode which loads whole system in RAM) while avoiding SD wear as runtime files are mapped to tmpfs in RAM (check limitations).

Installation

Tip: To install Alpine Linux on a Pi without keyboard, mouse & display, additional preparatory steps for install media are available at headless Installation page.

Once install media is prepared, proceed to perform standard procedures for actual install and initial base setup.

After install and reboot, check notes below for further customization and troubleshooting.

Post Installation

Customize config.txt and usercfg.txt

Instead of the BIOS found on a conventional PC, Raspberry Pi devices use a configuration file called config.txt. The GPU reads config.txt before the Arm CPU and Linux initialise. It is recommended to create a custom usercfg.txt file on boot partition to configure low-level system settings, as config.txt may be replaced during bootloader/system upgrades. However, few settings can only be set within config.txt, and will have no effect when specified in usercfg.txt (e.g. gpu_mem). All available settings information can be found here.
Some noteworthy settings include:

  • dtparam=audio=on to enable audio support with snd_bcm2835 driver for onboard audio jack and legacy hdmi audio mode.
  • By default system will use legacy video driver: some options may be used to adjust displays modes (e.g. if you see black edges around your screen after booting the Pi, you can add disable_overscan=1). Alternatively, better supported Linux DRM-KMS driver may be used (see setup below).
  • Enabling default serial console with enable_uart=1, together with console=serial0,115200 in cmdline.txt kernel parameters list.
  • To maximize available CPU memory if not requiring extra GPU features (i.e. headless/CLI use-cases), cut-down bootloader may be installed with raspberrypi-bootloader-cutdown package, and activated by adding gpu_mem=16 in config.txt (setting may be wiped after bootloader package update).
  • If you plan to install on a Pi Computer Module 4 with I/O board, you may need to add: otg_mode=1

Update the System

After installation, check and apply updates to keep your system secure.

Linux Kernel Graphics Modes

By default system configuration will use legacy video driver: while it may remain well suited for lower-ram devices (i.e. Pi Zero/1), this driver has some limitations and is now lacking support.
Linux DRM-KMS driver is recommended for most devices: it is enabled by adding the following to usercfg.txt:

# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d
max_framebuffers=2

# Don't have the firmware create an initial video= setting in cmdline.txt.
# Use the kernel's default instead.
disable_fw_kms_setup=1
Note: vc4-kms-v3d overlay:
  • ignores legacy video options from usrcfg.txt / config.txt.
  • enables Linux HDMI audio support by default. Eventual onboard audio jack still needs legacy snd_bcm2835 driver through dtparam=audio=on option in usrcfg.txt.
  • enables HDMI cec device within /sys/class/rc, supported through standard libcec.

3D Mesa drivers may be also added for vc4 (Pi Zero-3) or v3d (Pi 4-5) devices:

apk add mesa-dri-gallium

vc4 devices limitations in memory management may require regular reboots.

Wireless drivers

As of Alpine 3.17, Wifi and Bluetooth drivers are available within install image: they are part of linux-firmware-brcm (and linked dependencies). Since kernel 6.1.25 (i.e. Alpine 3.18), onboard bluetooth is enabled & autoprobed by default. This may be disabled by setting krnbt off).

Adding the following file to disable roaming and few other brcmfmac driver features may improve wifi stability.
$cat /etc/modprobe.d/brcmfmac.conf
options brcmfmac roamoff=1 feature_disable=0x282000

Alternatively same parameters may be passed all-in-one-line to kernel from cmdline.txt as:
brcmfmac.roamoff=1 brcmfmac.feature_disable=0x282000

Note: On Alpine 3.22.0, aforementioned brcmfmac driver options must be applied to circumvent an issue due to shipping wpa_supplicant. This is fixed from 3.22.1.

USB-gadget

Pi Zeros/A/A+/3A+/4B/400/5/500/CMs may be configured in various USB-gadget roles (or a composite combination thereof) connected to host via USB: such roles may be serial-gadget (i.e. console access for setup), ethernet-gadget for networking, mass-storage (appear as USB disk), webcam, keyboard, etc...

This may be achieved by loading relevant drivers & options in early boot sequence: in any case dtoverlay=dwc2,dr_mode=peripheral must be added to usercfg.txt.
Then, for instance, serial gadget may be enabled with echo "g_serial" | tee -a /etc/modules-load.d/gadget.conf (or adding modules=g_serial in cmdline.txt).

Tip: community xg_multi package may ease setup for serial/ethernet/mass-storage composite gadget, while ensuring interoperability across most host OS.

Picam

Note: The below instructions has been tested only in sys mode install with Pi Zero 2W.
  1. To use rpicam-apps package, upgrade to edge branch.
  2. Setup eudev as device manager:

    # setup-devd udev

  3. Add camera_auto_detect=1 option to the user config file /boot/usercfg.txt
  4. Install the package rpicam-apps available in the testing repository.
  5. Due to bug #16911, change the permission after every reboot as follows:

    $ doas chmod 666 /dev/dma_heap/*

  6. Test the picam by the command

    $ libcamera-hello --list-cameras

Resize partition created with image file

Media created from image file (manually or with Raspberry Pi Imager) can cautiously be resized up to 128MB(as base image is created as FAT16 with 2k clusters) with fdisk (parted-based tools may fail doing so).
Proceed with care to delete d, and then n recreate primary partition of desired size-1MB (will start at sector 2048 by default), change it to 06 (FAT16) with t command, and go to x extra menu and then b (move beginning of data in a partition to 0 -- mind this increases size by 2048 sectors=1MB). Finally return r and write w new partition table.
Then filesystem needs to be resized accordingly with fatresize.
This should not destroy existing data.
For exemple scripting it (128MB size):

doas fdisk /dev/sda <<EOF d n p 1 2048 +127M t 06 x b 0 r w EOF doas fatresize -s 128M /dev/sda

Custom installation instructions

Troubleshooting

raspinfo utility from the raspberrypi-utils-raspinfo package can be used as a first step to diagnose issues: it will make a log report of essential Pi system configuration, and is often used as a reference to submit questions or bug reports within Raspberry Pi community (Forums, Github, etc).

After booting, you may find less system memory available than you expect, as default CPU/GPU RAM split depends on Pi models and activated settings (audio, camera, video drivers, etc). To find out how your system is actually split, use vcgencmd utility from the raspberrypi-utils-vcgencmd package as follows:

# vcgencmd get_mem gpu # vcgencmd get_mem arm

To modify the memory allocation refer to legacy gpu_mem parameter information for config.txt.

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, since it increases the amount of entropy available to the kernel via interrupts.

apk indicating 'No space left on device'

While running Raspberry Pi models with only 512M of RAM (i.e. Zero, 3A+), a fresh Alpine Linux installation in Diskless mode will only leave around 200M for tmpfs root. Such allocation may be tuned or alternative install modes shall be considered.

Clock-related error messages

During the booting time, you might notice errors related to the hardware clock. Many Raspberry Pi do not have a hardware clock, or may have one without battery, in which case the behaviour depends on whether you physically cut power or not.

Also, setup-alpine will adapt the installation to the type of Raspberry Pi you use, which means for example that on a RPI5, you will see hwclock> service, whereas on a RPI4 it will use swclock. In doubt, make sure to do the installation on the target hardware.

If you still experience clock errors, add the following line to /etc/chrony/chrony.conf:

makestep 0.1 3

Wireless support with older Alpine images

In 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:

apk add linux-firmware-cypress

And reboot.

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

See also