Raspberry Pi: Difference between revisions

From Alpine Linux
m (added wikilink, removed extra space)
 
(135 intermediate revisions by 42 users not shown)
Line 1: Line 1:
[[Category:Installation]]
{{TOC right}}
This tutorial will help you install Alpine Linux on your Raspberry Pi.


== Preparation ==
Raspberry Pi devices are well supported on Alpine Linux by default: users can follow generic [[Installation| standard procedures]] for install and setup. However this page enlightens few specific information like [[#Preparing_for_the_installation| install media creation]], [[#Post_Installation| post-install]] customization and [[#Troubleshooting| troubleshooting]].


This section will help you format and partition your SD card:
== Considerations for choosing install modes [[Installation#Installation_Overview|(diskless/data disk/system disk)]] ==


# [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.
For scenarios where there is not expected to be significant changes to disk after setup (like running a static HTTP server), [[Diskless Mode|diskless mode]] may be 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). [[Alpine local backup|Alpine Local Backup (lbu)]] utility is used to save limited amount of local files, and system settings.
# Mount your SD card to your workstation
# 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.
# 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.
{{note| Due to a bug (#7024), you might want to add a "usercfg.txt" file (which is included by config.txt) with <code>enable_uart&#61;1</code> written in it. Otherwise, the error message "Can't open /dev/ttyS0" will repeatedly be written to the console.}}


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


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


# Insert the SD Card into the Raspberry Pi and turn it on
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).
# 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 -d</code>


Type <code>reboot</code> to verify that the installation was indeed successful.
== Compatibility list ==


== Post Installation ==
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.
{{:Include:Architecture support matrix}}


=== Update the System ===
== Preparing for the installation==


Upon installation, make sure that your system is up-to-date:
=== Raspberry Pi Imager ===


{{cmd|apk update
[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>
apk upgrade}}
Alpine Linux is listed under '''Other general-purpose OS''' section from '''Choose OS''' tab.


Don't forget to save the changes:
This utility can also be used from an Alpine linux system: install the {{pkg|rpi-imager}} package from <code>edge/testing</code> repository. To launch the utility in graphical mode issue the command: {{Cmd|rpi-imager}}


{{cmd|lbu commit -d}}
'''--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.


=== Clock-related error messages ===
{{Note|Raspberry Pi Imager will only create a minimum-sized FAT32 partition of about 100MB. If you need a bigger partition (i.e. with more room for diskless packages and cache), you may want to grow that partition afterwards, or follow the [[#Manual method|Manual method]] below.}}


During the booting time, you might notice errors related to the hardware clock.  The Raspberry Pi does not have
=== Manual method ===
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
Alternatively, image or tarball may be downloaded, and SD card media formatted and prepared as per below:
rc-update del hwclock boot   # disable the hardware clock}}
* [https://alpinelinux.org/downloads/ Download] the Alpine Linux image or tarball for Raspberry Pi . Use the compability list above when choosing image/tarball to download.
* [[Create_a_Bootable_Device#Manually_copying_Alpine_files|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 [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>.)
*: {{Tip|to reduce SD wear risk, it is advised to keep at least 10% of capacity as unallocated space. If media was previously partitioned at full capacity, running <code>blkdiscard /dev/mmcblk0</code> makes sure to [https://man7.org/linux/man-pages/man8/blkdiscard.8.html discard device sectors] before re-partitioning.}}
*: {{warning|Do not use the volume label <code>boot</code> for the fat32 partition. Due to an upstream [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 fat32 partition.}}
* Extract the tarball to the root of the bootable FAT32 partition.


Since Raspberry Pi does not have a clock, the Alpine Linux needs to know what the time is by using a
Once install media is prepared, proceed to [[Installation#Base_configuration|standard procedures]] for install and initial base setup.
[https://en.wikipedia.org/wiki/Network_Time_Protocol Network Time Protocol (NTP)] daemon. Make sure that you a
{{Tip|To install Alpine Linux on a pi without keyboard, mouse & display, additional preparatory steps are available at [[Installation on a headless host|headless Installation]] page.}}
NTP daemon installed and running. If you are not sure, then you can install NTP client by running the following
After install and reboot, check notes below for further customization and [[#Troubleshooting| troubleshooting]].
command:


{{cmd|setup-ntp}}
== Post Installation ==


Busybox NTP client might be the most lightweight solution. Save the changes and reboot, once the NTP software is
=== Customize ''config.txt'' and ''usercfg.txt'' ===
installed and running:


{{cmd|lbu commit -d
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.
reboot}}
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. Available settings information can be found [https://www.raspberrypi.com/documentation/computers/config_txt.html here]. 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>).
Some interesting values include:{{Cat|usercfg.txt|<nowiki>enable_uart=1 # To enable the UART console:
dtparam=audio=on # To enable audio </nowiki>}}
* 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]]).
* 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>
* Pi Zeros/A/A+/3A+/4B/400/5/500/CMs may be configured as USB serial-gadget (i.e. console access for setup) or ethernet-gadget networking: add <code>dtoverlay=dwc2,dr_mode=peripheral</code> in '''usercfg.txt''' and <code>modules=g_cdc</code> in '''cmdline.txt'''
* 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).


After reboot, make sure that the <code>date</code> command outputs the correct date and time.
=== Update the System ===


=== X11 Setup ===
After installation, make sure your system is up-to-date:
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
​apk add xf86-video-fbdev xf86-video-vesa xf86-input-mouse xf86-input-keyboard dbus ​set​xkbmap kbd 
rc-update ​​add dbus}}


Install XFCE:
{{cmd|apk update
{{cmd|apk add xfce4}}
apk upgrade}}
 
{{Note| If on diskless mode:
* don't forget to save changes after any system or configuration files update with <code>lbu commit -d</code>
* in order to upgrade the kernel, follow [[Diskless_Mode#Upgrading_a_diskless_system| update-kernel]] script procedure.}}
 
=== Linux Kernel Graphics Modes ===


Commit your changes:
By default system configuration will use legacy video driver: this driver has some limitations and is lacking support.<br>
{{cmd|lbu_commit -d}}
It is recommended to enable Linux DRM-KMS driver 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: This overlay disables legacy video [https://www.raspberrypi.com/documentation/computers/legacy_config_txt.html#legacy-video-options options].


Install the Mesa drivers (Pi4 and Pi5):{{cmd|apk add {{pkg|mesa-dri-gallium|arch=a*}}}}


{{cmd|startx}}
=== Wireless drivers ===


=== Enable OpenGL (RPi 3) ===
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).


Remount the boot partition writeable (ie. /media/mmcblk0p1):
=== Picam ===


{{cmd|mount -o remount,rw /media/mmcblk0p1}}
{{Note|The below instructions to get picam to work with Pi Zero 2 W model has been tested in [[Classic install or sys mode on Raspberry Pi|sys mode]] only.}}


Add the following lines to /media/mmcblk0p1/config.txt
# Upgrade to [[Repositories#Upgrading_to_edge|edge]] version as {{pkg|rpicam-apps|arch=}} package is not yet supported in v3.21.
# 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}}


dtoverlay=vc4-kms-v3d
== Custom installation instructions ==
gpu_mem=256


Install mesa-dri-vc4:
* To switch a Diskless installation to a fully disk-based installation refer [[Classic_install_or_sys_mode_on_Raspberry_Pi#Convert diskless to sys mode|Convert diskless to sys mode]].
{{cmd|apk add mesa-dri-vc4}}
* An alternate approach [[OverlayFS#Loopback image with overlayfs|using loopback image with overlayfs]] for memory constrained Raspberry Pi models (3A+,Pi0) with only 512M of RAM running Diskless mode.
=== Netboot ===


Reboot:
The Raspberry Pi 4 bootloader can be configured to [https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#raspberry-pi-4-bootloader-configuration boot from the network]. Configure the bootloader with at least


{{cmd|lbu_commit -d; reboot}}
{{cmd|<nowiki>BOOT_ORDER=0xf142
TFTP_PREFIX=1</nowiki>}}


== Persistent storage ==
and optionally also {{cmd|<nowiki>TFTP_IP=x.x.x.x</nowiki>}} where <code>x.x.x.x</code> is the IP address of your TFTP server.


=== Loopback image with overlayfs ===
If not configuring <code>TFTP_IP</code> in the bootloader, you'll need to configure your DHCP server to advertise the TFTP server IP address. This varies depending on your DHCP server; use the following details if applicable:


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.
# Vendor class: <code>PXEClient:Arch:00000:UNDI:002001</code>
# Filename: <code>/</code>


First make the sd-card writable again and change fstab to always do so:
The minimal set of files that your TFTP server needs to host are:
{{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:
# <code>bcm2711-rpi-4-b.dtb</code> (from [https://raw.githubusercontent.com/raspberrypi/firmware/master/boot/bcm2711-rpi-4-b.dtb raspberrypi/firmware/master/boot/bcm2711-rpi-4-b.dtb])
# <code>cmdline.txt</code> (see below)
# <code>config.txt</code> (see below)
# <code>fixup4.dat</code> (from [https://raw.githubusercontent.com/raspberrypi/firmware/master/boot/fixup4.dat raspberrypi/firmware/master/boot/fixup4.dat], alternatively <code>fixup4cd.dat</code> for the cut down version)
# <code>initramfs-rpi4</code> (from [https://dl-cdn.alpinelinux.org/alpine/edge/releases/aarch64/netboot/initramfs-rpi4 alpine/edge/releases/aarch64/netboot/initramfs-rpi4])
# <code>start4.elf</code> (from [https://raw.githubusercontent.com/raspberrypi/firmware/master/boot/start4.elf raspberrypi/firmware/master/boot/start4.elf], alternatively <code>start4cd.elf</code> for the cut down version)
# <code>vmlinuz-rpi4</code> (from [https://dl-cdn.alpinelinux.org/alpine/edge/releases/aarch64/netboot/vmlinuz-rpi4 alpine/edge/releases/aarch64/netboot/vmlinuz-rpi4])


{{cmd|dd if&#61;/dev/zero of&#61;/media/mmcblk0p1/persist.img bs&#61;1024 count&#61;0 seek&#61;1048576}}
<code>config.txt</code>:
{{cmd|<nowiki>[pi4]
kernel=vmlinuz-rpi4
initramfs initramfs-rpi4
arm_64bit=1
</nowiki>}}


Install the ext utilities:
<code>cmdline.txt</code>:
{{cmd|<nowiki>modules=loop,squashfs console=ttyAMA0,115200 ip=dhcp alpine_repo=http://dl-cdn.alpinelinux.org/alpine/edge/main modloop=http://dl-cdn.alpinelinux.org/alpine/edge/releases/aarch64/netboot/modloop-rpi4</nowiki>}}


{{cmd|apk add e2fsprogs}}
Instead of using the <nowiki>http://dl-cdn.alpinelinux.org/alpine/edge/releases/aarch64/netboot/</nowiki> base URL above, pinning to a specific point in time is preferred. Raspberry Pi 4 netboot files are available from https://dl-cdn.alpinelinux.org/alpine/edge/releases/aarch64/netboot-20230329/ onward.


Format the loop-back file:
With the above configured the Raspberry Pi 4 should be able to boot from the network without an SD card.


{{cmd|mkfs.ext4 /media/mmcblk0p1/persist.img}}
== Enable the Serial Console ==


Mount the storage:
Besides having <code>enable_uart=1</code> in ''usercfg.txt'', the kernel command-line option <var>console</var> needs to be changed to <code>console=serial0,115200</code> in ''cmdline.txt''.


{{cmd|echo "/media/mmcblk0p1/persist.img /media/persist ext4 rw,relatime,errors&#61;remount-ro 0 0" >> /etc/fstab
From a Linux desktop, connect to it with something like this:
mkdir /media/persist
mount -a}}


Make the overlay folders, we are doing /usr here, but you can do /home or anything else:
{{cmd|cu -l /dev/ttyUSB0 -s 115200}}


{{cmd|mkdir /media/persist/usr
== Troubleshooting ==
mkdir /media/persist/.work
echo "overlay /usr overlay lowerdir&#61;/usr,upperdir&#61;/media/persist/usr,workdir&#61;/media/persist/.work 0 0" >> /etc/fstab
mount -a}}


Your /etc/fstab should look something like this:
<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|/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)
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
{{cmd|lbu_commit -d}}
# vcgencmd get_mem arm</nowiki>}}


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.
To modify the memory allocation refer to [[#Customize config.txt|Customize config.txt]] section.


If you do want to install something small at boot you can use `apk add` and `lbu commit -d`.
=== Long boot time when running headless ===


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.
If no peripherals are connected, the system might hang for an exceptionally long period of time while it attempts to accumulate entropy.


=== Traditional disk-based (sys) installation ===
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.


{{Warning|This isn't yet supported by the Alpine setup scripts for Raspberry Pi. It requires manual intervention, and might break.}}
=== apk indicating 'No space left on device' ===


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.
While running Raspberry Pi models(3A+,Pi0) with only 512M of RAM, a fresh Alpine Linux installation in Diskless mode will only leave around 200M for tmpfs root. Allocation may be [[Diskless_Mode| tuned]] or alternative install modes shall be [[#Considerations_for_choosing_install_modes_(diskless/data_disk/system_disk)| considered]].


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:
=== Clock-related error messages ===


{{cmd|apk add e2fsprogs
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.  
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.
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.


{{cmd|<nowiki>mkdir /stage
If you still experience clock errors, add the following line to '''/etc/chrony/chrony.conf''':
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:
<code>makestep 0.1 3</code>  


{{cmd|/dev/mmcblk0p1 /media/mmcblk0p1 vfat defaults 0 0}}
=== Wireless support with older Alpine images ===


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:
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.
Use the ethernet interface to download the required packages:


{{cmd|<nowiki>mount -o remount,rw /media/mmcblk0p1
{{cmd|apk add {{pkg|linux-firmware-cypress|arch=a*}}}}
sed -i '$ s/$/ root=\/dev\/mmcblk0p2/' /media/mmcblk0p1/cmdline-rpi2.txt</nowiki>}}


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.
And reboot.


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 or you could use bind mount so that manually copy the files to boot partition is not needed.
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.
(Replace /mnt/sdcard with the correct mount point.)


{{cmd|<nowiki>echo /media/mmcblk0p1/boot /boot none defaults,bind 0 0 >> /etc/fstab</nowiki>}}
  git clone --depth 1 https://github.com/RPi-Distro/firmware-nonfree.git
  cp firmware-nonfree/brcm/* /mnt/sdcard/firmware/brcm


=== Persistent Installation on RPi3 ===
=== Filesystem for boot partition ===


See this page : https://wiki.alpinelinux.org/wiki/Classic_install_or_sys_mode_on_Raspberry_Pi
If you are trapped at the dreaded rainbow screen, with the green led blinking a few times in a row, repeatedly, check the boot partition type.


See https://forum.alpinelinux.org/comment/1084#comment-1084
The rpi2 require '''fat32''' for the boot partition, NOT '''fat16'''.  Use linux fdisk to set the boot partition type as "c" (for fat32/lba) and set the '''lba''' and '''boot''' flags for the partition as suggested. Create the boot partition filesystem as fat32 with:{{Cmd|mkdosfs -F 32 /dev/sdX1}}


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


* [[Classic install or sys mode on Raspberry Pi]] - a variant.
* [[Classic install or sys mode on Raspberry Pi]]  
* [[Raspberry Pi 3 - Setting Up Bluetooth]]
* [[Raspberry Pi 3 - Setting Up Bluetooth]]
* [[Raspberry Pi 3 - Configuring it as wireless access point -AP Mode]]
* [[Raspberry Pi 3 - Configuring it as wireless access point -AP Mode]]
* [[Raspberry Pi 3 - Browser Client]]
* [[Linux Router with VPN on a Raspberry Pi]]
* [[Linux Router with VPN on a 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]
* 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 04:25, 21 April 2025

Raspberry Pi devices are well supported on Alpine Linux by default: users can follow generic standard procedures for install and setup. However this page enlightens few specific information like install media creation, post-install customization and troubleshooting.

Considerations for choosing install modes (diskless/data disk/system disk)

For scenarios where there is not expected to be significant changes to disk after setup (like running a static HTTP server), diskless mode may be 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). Alpine Local Backup (lbu) utility is used to save limited amount of local files, and system settings.

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 persists 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).

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
x86 x86 32 bit i686 compatible (or later) CPUs with at least CMOV and SSE2 All
x86_64 AMD64 compatible 64-bit x86 instruction set All
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 (defconfig bcm2711) v3.5
PowerPC ppc64le 64 bit PowerPC (little-endian) mostly for POWER8 and POWER9 v3.6
IBM System Z s390x IBM Z mainframes, especially IBM Z and IBM LinuxONE (z196 minimum) v3.6
RISC V riscv64 64 bit RISC V v3.20
LoongArch loongarch64 64 bit LoongArch v3.21

Preparing for the installation

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 edge/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.

Note: Raspberry Pi Imager will only create a minimum-sized FAT32 partition of about 100MB. If you need a bigger partition (i.e. with more room for diskless packages and cache), you may want to grow that partition afterwards, or follow the Manual method below.

Manual method

Alternatively, image or tarball may be downloaded, and SD card media formatted and prepared as per below:

  • Download the Alpine Linux image or tarball for Raspberry Pi . Use the compability list above when choosing image/tarball to download.
  • 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 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.)
    Tip: to reduce SD wear risk, it is advised to keep at least 10% of capacity as unallocated space. If media was previously partitioned at full capacity, running blkdiscard /dev/mmcblk0 makes sure to discard device sectors before re-partitioning.
    Warning: Do not use the volume label boot for the fat32 partition. Due to an upstream 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 fat32 partition.

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

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

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

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. Available settings information can be found here. However, few settings can only be set within config.txt, and will have no effect when specified in usercfg.txt (e.g. gpu_mem).

Some interesting values include:

Contents of usercfg.txt

enable_uart=1 # To enable the UART console: dtparam=audio=on # To enable audio
  • 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).
  • If you plan to install on a Pi Computer Module 4 with I/O board, you may need to add: otg_mode=1
  • Pi Zeros/A/A+/3A+/4B/400/5/500/CMs may be configured as USB serial-gadget (i.e. console access for setup) or ethernet-gadget networking: add dtoverlay=dwc2,dr_mode=peripheral in usercfg.txt and modules=g_cdc in cmdline.txt
  • 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).

Update the System

After installation, make sure your system is up-to-date:

apk update apk upgrade

Note: If on diskless mode:
  • don't forget to save changes after any system or configuration files update with lbu commit -d
  • in order to upgrade the kernel, follow update-kernel script procedure.

Linux Kernel Graphics Modes

By default system configuration will use legacy video driver: this driver has some limitations and is lacking support.
It is recommended to enable Linux DRM-KMS driver 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: This overlay disables legacy video options.

Install the Mesa drivers (Pi4 and Pi5):

apk add mesa-dri-gallium

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).

Picam

Note: The below instructions to get picam to work with Pi Zero 2 W model has been tested in sys mode only.
  1. Upgrade to edge version as rpicam-apps package is not yet supported in v3.21.
  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

Custom installation instructions

Netboot

The Raspberry Pi 4 bootloader can be configured to boot from the network. Configure the bootloader with at least

BOOT_ORDER=0xf142 TFTP_PREFIX=1

and optionally also

TFTP_IP=x.x.x.x

where x.x.x.x is the IP address of your TFTP server.

If not configuring TFTP_IP in the bootloader, you'll need to configure your DHCP server to advertise the TFTP server IP address. This varies depending on your DHCP server; use the following details if applicable:

  1. Vendor class: PXEClient:Arch:00000:UNDI:002001
  2. Filename: /

The minimal set of files that your TFTP server needs to host are:

  1. bcm2711-rpi-4-b.dtb (from raspberrypi/firmware/master/boot/bcm2711-rpi-4-b.dtb)
  2. cmdline.txt (see below)
  3. config.txt (see below)
  4. fixup4.dat (from raspberrypi/firmware/master/boot/fixup4.dat, alternatively fixup4cd.dat for the cut down version)
  5. initramfs-rpi4 (from alpine/edge/releases/aarch64/netboot/initramfs-rpi4)
  6. start4.elf (from raspberrypi/firmware/master/boot/start4.elf, alternatively start4cd.elf for the cut down version)
  7. vmlinuz-rpi4 (from alpine/edge/releases/aarch64/netboot/vmlinuz-rpi4)

config.txt:

[pi4] kernel=vmlinuz-rpi4 initramfs initramfs-rpi4 arm_64bit=1

cmdline.txt:

modules=loop,squashfs console=ttyAMA0,115200 ip=dhcp alpine_repo=http://dl-cdn.alpinelinux.org/alpine/edge/main modloop=http://dl-cdn.alpinelinux.org/alpine/edge/releases/aarch64/netboot/modloop-rpi4

Instead of using the http://dl-cdn.alpinelinux.org/alpine/edge/releases/aarch64/netboot/ base URL above, pinning to a specific point in time is preferred. Raspberry Pi 4 netboot files are available from https://dl-cdn.alpinelinux.org/alpine/edge/releases/aarch64/netboot-20230329/ onward.

With the above configured the Raspberry Pi 4 should be able to boot from the network without an SD card.

Enable the Serial Console

Besides having enable_uart=1 in usercfg.txt, the kernel command-line option console needs to be changed to console=serial0,115200 in cmdline.txt.

From a Linux desktop, connect to it with something like this:

cu -l /dev/ttyUSB0 -s 115200

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 Customize config.txt section.

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(3A+,Pi0) with only 512M of RAM, a fresh Alpine Linux installation in Diskless mode will only leave around 200M for tmpfs root. 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

Filesystem for boot partition

If you are trapped at the dreaded rainbow screen, with the green led blinking a few times in a row, repeatedly, check the boot partition type.

The rpi2 require fat32 for the boot partition, NOT fat16. Use linux fdisk to set the boot partition type as "c" (for fat32/lba) and set the lba and boot flags for the partition as suggested. Create the boot partition filesystem as fat32 with:

mkdosfs -F 32 /dev/sdX1

See also