Raspberry Pi: Difference between revisions

From Alpine Linux
(Split persistent storage into separate section; add subsection on (unsupported) disk-based install.)
No edit summary
(48 intermediate revisions by 25 users not shown)
Line 1: Line 1:
[[Category:Installation]]
{{TOC right}}
 
This tutorial will help you install Alpine Linux on your Raspberry Pi.
This tutorial will help you install Alpine Linux on your Raspberry Pi.


== Preparation ==
== Preparation ==


This section will help you format and partition your SD card:
# [http://alpinelinux.org/downloads/ 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.
# [https://wiki.alpinelinux.org/wiki/Create_a_Bootable_USB#Format_USB_stick Create a bootable FAT32 partition on your SD card.] You can use a partitioning tool such as [https://en.wikipedia.org/wiki/GNOME_Disks gnome-disks] or [http://linux.die.net/man/8/fdisk fdisk].
# Create a filesystem on the partition with <code>mkdosfs -F 32 /dev/sdX1</code> (Replace sdX1 with the correct reference to the partition you just created.)
# Mount the partition and extract the tarball contents unto it.
 
Optionally create a '''usercfg.txt''' file on the partition to configure low-level system settings. Specifications can be found [https://www.raspberrypi.org/documentation/configuration/config-txt here]. Some interesting values include:
* To enable audio: <code>dtparam=audio=on</code>
* If you see black edges around your screen after booting the Pi, you can add <code>disable_overscan=1</code>


# [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.
If you need WiFi to work, you have 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.)
# 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.
  git clone --depth 1 https://github.com/RPi-Distro/firmware-nonfree.git
# Mark the newly created partition as bootable and save
  cp firmware-nonfree/brcm/* /mnt/sdcard/firmware/brcm
# Mount the previously created partition
# Extract the tarball contents to your FAT32 partition
# Unmount the SD Card.


== Installation ==
== Installation ==
Line 18: Line 23:
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:
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:


# Insert the SD Card into the Raspberry Pi and turn it on
# Insert the SD card into the Raspberry Pi and turn it on
# Login into the Alpine system as root.  Leave the password empty.
# Login into the Alpine system as root.  Leave the password empty.
# Type <code>setup-alpine</code>
# Type <code>setup-alpine</code>
# Once the installation is complete, commit the changes by typing <code>lbu commit</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.
Type <code>reboot</code> to verify that the installation was indeed successful.
Line 36: Line 41:
Don't forget to save the changes:
Don't forget to save the changes:


{{cmd|lbu commit}}
{{cmd|lbu commit -d}}


=== Clock-related error messages ===
=== Clock-related error messages ===
Line 53: Line 58:
{{cmd|setup-ntp}}
{{cmd|setup-ntp}}


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


{{cmd|lbu commit
{{cmd|lbu commit -d
reboot}}
reboot}}


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


=== X11 Setup ===
=== WiFi on boot ===
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
If you have already [[Connecting_to_a_wireless_access_point|configured WiFi]] during the setup, the connection will not return on reboot.
​apk add xf86-video-fbdev xf86-input-mouse xf86-input-keyboard dbus ​set​xkbmap
You will need to start up a service to automatically connect to the wireless access point.
rc-update ​​add dbus}}
# Run <code>rc-update add wpa_supplicant boot</code> to connect to the wireless access point on boot.
# Run it manually with <code>/etc/init.d/wpa_supplicant start</code>.


Also edit the default X11 module config: /etc/X11/xorg.conf.d/20-modules.conf
=== Enable OpenGL (Raspberry Pi 3) ===
{{cmd|Section "Module"
    Load "fbdevhw"
    Load "fb"
    Load "shadow"
    Load "shadowfb"
    Load "dbe"
    Disable "glx"
    Disable "dri"
EndSection}}


Commit your changes:
Remount the boot partition writeable (ie. /media/mmcblk0p1):
{{cmd|lbu_commit}}


Now you should be able to run a browser or desktop. (Guides may follow)
{{cmd|mount -o remount,rw /media/mmcblk0p1}}
 
Add the following lines to /media/mmcblk0p1/config.txt
 
dtoverlay=vc4-kms-v3d
gpu_mem=128
 
256MB gpu_mem is also possible
 
Install mesa-dri-vc4:
{{cmd|apk add mesa-dri-vc4}}
 
Reboot:
 
{{cmd|lbu_commit -d; reboot}}


== Persistent storage ==
== Persistent storage ==
Line 86: Line 96:
=== Loopback image with overlayfs ===
=== Loopback image with overlayfs ===


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.
The install is in diskless mode and forces everything into memory, if you want additional storage we need to create loop-back storage onto the SD mounted with overlayfs.


First make the sd-card writable again and change fstab to always do so:
First make the SD card writable again and change fstab to always do so:
{{cmd|mount /media/mmcblk0p1 -o rw,remount
{{cmd|mount /media/mmcblk0p1 -o rw,remount
sed -i 's/vfat\ ro,/vfat\ rw,' /etc/fstab}}
sed -i 's/vfat\ ro,/vfat\ rw,/' /etc/fstab}}


Create the loop-back file, this example is 1 GB:
Create the loop-back file, this example is 1 GB:
Line 125: Line 135:


Now commit the changes: (optionally remove the e2fsprogs, but it does contain repair tools)
Now commit the changes: (optionally remove the e2fsprogs, but it does contain repair tools)
{{cmd|lbu_commit}}
{{cmd|lbu_commit -d}}


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


If you do want to install something small at boot you can use `apk add` and `lbu commit`.
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 do check everything you need is in that directory and not in folders you have not made persistent.
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.
Line 135: Line 145:
=== Traditional disk-based (sys) installation ===
=== Traditional disk-based (sys) installation ===


{{Warning|This isn't yet supported by the Alpine setup scripts for Raspberry Pi. It requires manual intervention, and might not work.}}
{{Warning|This isn't yet supported by the Alpine setup scripts for Raspberry Pi. It requires manual intervention, and might break.}}


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.
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.
Line 155: Line 165:
{{cmd|/dev/mmcblk0p1 /media/mmcblk0p1 vfat defaults 0 0}}
{{cmd|/dev/mmcblk0p1 /media/mmcblk0p1 vfat defaults 0 0}}


Now add a <code>root=/dev/mmcblk0p3</code> parameter to the Pi's boot command line, either <code>cmdline-rpi2.txt</code> or <code>cmdline-rpi.txt</code> depending on model:
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:


{{cmd|<nowiki>mount -o remount,rw /media/mmcblk0p1
{{cmd|<nowiki>mount -o remount,rw /media/mmcblk0p1
sed -i '$ s/$/ root=\/dev\/mmcblk0p3/' /media/mmcblk0p1/cmdline-rpi2.txt</nowiki>}}
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.
 
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.
 
{{cmd|<nowiki>echo /media/mmcblk0p1/boot /boot none defaults,bind 0 0 >> /etc/fstab</nowiki>}}
 
=== Persistent Installation on Raspberry Pi 3 ===
 
See this page : https://wiki.alpinelinux.org/wiki/Classic_install_or_sys_mode_on_Raspberry_Pi
 
See https://web.archive.org/web/20171125115835/https://forum.alpinelinux.org/comment/1084#comment-1084


You might also consider <code>overlayroot=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.
== Troubleshooting ==


The contents of <code>/boot</code> will be ignored by the Pi's bootloader. If you update the kernel package, or run <code>mkinitfs</code>, you will need to copy the relevant files from <code>/boot</code> to <code>/media/mmcblk0p1/boot</code>.
=== 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 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.


== See Also ==
== See Also ==


* [[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]]
* [[Linux Router with VPN on a Raspberry Pi]]
* [[Create a bootable SDHC from a Mac]]
* [[Create a bootable SDHC from a Mac]]
* Build custom Raspberry Pi images based on Alpine via [https://github.com/tolstoyevsky/pieman Pieman]
[[Category:Installation]]
[[Category: Raspberry]]

Revision as of 12:49, 16 March 2020

This tutorial will help you install Alpine Linux on your Raspberry Pi.

Preparation

  1. 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.
  2. Create a bootable FAT32 partition on your SD card. You can use a partitioning tool such as gnome-disks or fdisk.
  3. Create a filesystem on the partition with mkdosfs -F 32 /dev/sdX1 (Replace sdX1 with the correct reference to the partition you just created.)
  4. Mount the partition and extract the tarball contents unto it.

Optionally create a usercfg.txt file on the partition to configure low-level system settings. Specifications can be found here. Some interesting values include:

  • To enable audio: dtparam=audio=on
  • If you see black edges around your screen after booting the Pi, you can add disable_overscan=1

If you need WiFi to work, you have 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

Installation

Alpine Linux will be installed as diskless mode, hence you need to use Alpine Local Backup (lbu) to save your modifications between reboots. Follow these steps to install Alpine Linux:

  1. Insert the SD card into the Raspberry Pi and turn it on
  2. Login into the Alpine system as root. Leave the password empty.
  3. Type setup-alpine
  4. Once the installation is complete, commit the changes by typing lbu commit -d

Type reboot to verify that the installation was indeed successful.

Post Installation

Update the System

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

apk update apk upgrade

Don't forget to save the changes:

lbu commit -d

Clock-related error messages

During the booting time, you might notice errors related to the hardware clock. The Raspberry Pi does not have a hardware clock and therefore you need to disable the hwclock daemon and enable swclock:

rc-update add swclock boot # enable the software clock 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 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:

setup-ntp

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

lbu commit -d reboot

After reboot, make sure that 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.

  1. Run rc-update add wpa_supplicant boot to connect to the wireless access point on boot.
  2. Run it manually with /etc/init.d/wpa_supplicant start.

Enable OpenGL (Raspberry Pi 3)

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

mount -o remount,rw /media/mmcblk0p1

Add the following lines to /media/mmcblk0p1/config.txt

dtoverlay=vc4-kms-v3d
gpu_mem=128

256MB gpu_mem is also possible

Install mesa-dri-vc4:

apk add mesa-dri-vc4

Reboot:

lbu_commit -d; reboot

Persistent storage

Loopback image with overlayfs

The install is in diskless mode and forces everything into memory, if you want additional storage we need to create loop-back storage onto the SD mounted with overlayfs.

First make the SD card writable again and change fstab to always do so:

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:

dd if=/dev/zero of=/media/mmcblk0p1/persist.img bs=1024 count=0 seek=1048576

Install the ext utilities:

apk add e2fsprogs

Format the loop-back file:

mkfs.ext4 /media/mmcblk0p1/persist.img

Mount the storage:

echo "/media/mmcblk0p1/persist.img /media/persist ext4 rw,relatime,errors=remount-ro 0 0" >> /etc/fstab mkdir /media/persist mount -a

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

mkdir /media/persist/usr mkdir /media/persist/.work echo "overlay /usr overlay lowerdir=/usr,upperdir=/media/persist/usr,workdir=/media/persist/.work 0 0" >> /etc/fstab mount -a

Your /etc/fstab should look something like this:

/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=0022,dmask=0022,errors=remount-ro 0 0 /media/mmcblk0p1/persist.img /media/persist ext4 rw,relatime,errors=remount-ro 0 0 overlay /usr overlay lowerdir=/usr,upperdir=/media/persist/usr,workdir=/media/persist/.work 0 0

Now commit the changes: (optionally remove the e2fsprogs, but it does contain repair tools)

lbu_commit -d

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.

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 do check everything you need is in that directory and not in folders you have not made persistent.

Traditional disk-based (sys) installation

Warning: This isn't yet supported by the Alpine setup scripts for Raspberry Pi. It requires manual intervention, and might break.


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:

apk add e2fsprogs mkfs.ext4 /dev/mmcblk0p2

Now do a disk install via a mountpoint. The setup-disk script will give some errors about syslinux/extlinux, but you can ignore these: the Raspberry Pi doesn't need this to boot anyway.

mkdir /stage mount /dev/mmcblk0p2 /stage setup-disk -o /media/mmcblk0p1/MYHOSTNAME.apkovl.tar.gz /stage # (ignore errors about syslinux/extlinux)

Add a line to /stage/etc/fstab to mount the Pi's boot partition again:

/dev/mmcblk0p1 /media/mmcblk0p1 vfat defaults 0 0

Now add a root=/dev/mmcblk0p2 parameter to the Pi's boot command line, either cmdline-rpi2.txt or cmdline-rpi.txt depending on model:

mount -o remount,rw /media/mmcblk0p1 sed -i '$ s/$/ root=\/dev\/mmcblk0p2/' /media/mmcblk0p1/cmdline-rpi2.txt

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 on shutdown.

Beware, though, that 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 so that manually copy the files to boot partition is not needed.

echo /media/mmcblk0p1/boot /boot none defaults,bind 0 0 >> /etc/fstab

Persistent Installation on Raspberry Pi 3

See this page : https://wiki.alpinelinux.org/wiki/Classic_install_or_sys_mode_on_Raspberry_Pi

See https://web.archive.org/web/20171125115835/https://forum.alpinelinux.org/comment/1084#comment-1084

Troubleshooting

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

See Also