Incessant ramblings of a Linux fanatic

0%

Tutorial: 64-bit Alpine Linux Desktop on the Raspberry Pi 4

Reasoning

For Christmas this year I received a Raspberry Pi 4, the new board straight out of the UK that boasts 2-3x the compute power of the last model. I’ve been wanting to take a crack at it, but I knew I wanted to ditch Raspbian, the stock OS, right away.

Why? Well, the Pi 4 is a 64-bit embedded system. Actually, the Pi 3 was also 64-bit, but Raspbian has always been a 32-bit operating system for reasons of stability and backwards compatibility… but I’m a power user! Let’s use it to it’s full potential, shall we?

For awhile I debated on installing Arch Linux ARM, but I eventually landed on Alpine Linux. It’s a prime choice for this because it’s blisteringly lightweight, offers more packages than Arch Linux ARM, has loads of packages compiled for aarch64, and the most recent version (v3.11 as of writing) added explicit support for the Pi 4. That being said, I recommend using the edge branch for the most up to date and in-testing packages.

Equipment

If you’ve never worked on a Pi before, you should check out CanaKit’s offerings. In the case of the older Pi’s, CanaKit was always a good idea because the power supply it comes with has enough amperage to keep the Pi from starving. If you use any old wall-wart PSU, you’d get a lightning bolt icon telling you that the Pi wasn’t getting enough power. In the case of the Pi 4, the USB C port is not up to spec and actually needs an even more specific PSU; if the wrong one is used, it could damage the board.

lightning bolt

The Pi is particularly sensitive about the quality of SD card you put in it since it makes a ton of small reads and writes. A class 10, UHS 3 micro SD card is what you really want for uninterrupted performance, and it’s not even that much more expensive.

The Raspberry Pi 4 CanaKit ensures you won’t get the wrong parts, and at a great price too. It even comes with a slick case, a power switch, a quiet CPU fan, and passive coolers on top of all the stuff you must have.

The SD card reader that comes with the CanaKit is a tad subpar, however. If you find yourself frequently tinkering on SD cards, I highly recommend getting Sabrent’s USB 3.0 SD card reader. It offers superior performance, and you don’t have to struggle to remove the card every time.

Installation

Getting Alpine Linux installed on a Pi persistently isn’t a supported goal by the Alpine team yet. We’ll have to take a few detours to get this working.

Setup

Grab the tarball from Alpine’s website for Raspberry Pi (1, 2, 3, or 4) and the aarch64 architecture. Grab your SD card and format it using an MBR partition scheme (the Pi will not boot with GPT partitions). You’ll need to make two partitions:

  • 500 MB, FAT32, for booting
  • The rest, EXT4, for your system installation

Extract the tarball into the FAT32 partition, then add this file to the root of the partition:

usercfg.txt
1
2
3
4
dtparam=audio=on
disable_overscan=1
dtoverlay=vc4-fkms-v3d
gpu_mem=256

Insert the SD card, power up the Pi, and login. The default credentials are root and no password. Start up and complete a regular install using setup-alpine.

You’ll want to enable a service to automatically reconnect to the wifi network, so run rc-update add wpa_supplicant boot. We will want to commit these settings to the boot partition, so execute lbu commit -d to save them. Then reboot.

When you’re back online, we should update our system and save it: apk update && apk upgrade. Commit that once more and reboot: lbu commit -d && reboot.

Making it Persistent

The reason why persistent installations are not supported on the Pi is because ARM devices don’t use conventional BIOSes. Therefore, SYSLinux or GRUB won’t work. Instead we’re going to use our custom FAT32 boot partition (mmcblk0p1) to alleviate this problem.

1
2
3
mkdir -p /mnt/system
mount /dev/mmcblk0p2 /mnt/system
setup-disk -o /media/mmcblk0p1/$HOST.apkovl.tar.gz /mnt/system

You’ll probably get some warnings about SYSLinux here – ignore them.

Now we’re going to setup our mount points. Edit fstab on the system partition and add these lines:

/mnt/system/etc/fstab
4
5
/dev/mmcblk0p1 /media/mmcblk0p1 vfat defaults 0 0
/media/mmcblk0p1/boot /boot none defaults,bind 0 0

In order to get the kernel to properly load up our new root filesystem, we’ll have to pass a new parameter to it. Append this to cmdline.txt after remounting with mount -o remount,rw /media/mmcblk0p1:

/media/mmcblk0p1/cmdline.txt
1
<Your kernel parameters> root=/dev/mmcblk0p2

You may now reboot into your fresh system installation.

Bringing up the Desktop

Alpine actually has a little known package for quickly setting up a desktop environment, but it needs a few tweaks. The alpine-desktop metapackage includes xfce4 along with a few other tools and critical packages like xorg-server. You’ll also need to replace mdev with udev for proper input support, and install some video drivers.

1
2
3
4
5
6
7
8
9
10
11
12
# Install desktop packages.
apk add alpine-desktop mesa-dri-vc4 mesa-dri-swrast mesa-gbm xf86-video-fbdev libinput xfce4-terminal firefox sudo
setup-xorg-base

# Add a user for yourself.
adduser -g "Max O'Cull" max

# Uncomment this line: %wheel ALL=(ALL) ALL
visudo

# Add yourself to the group "wheel" for sudo access.
addgroup max wheel

Add this xorg.conf to properly connect the video drivers:

/etc/X11/xorg.conf
1
2
3
4
Section "Device"
Identifier "default"
Driver "fbdev"
EndSection

reboot and when you log back in, run startx. You’ll notice XFCE4 is a bit sluggish. This is because the compositor is enabled and is bogging down the GPU. Under XFCE’s settings, find Window Manager Tweaks and disable compositing.

Extra Credit

Congratulations, you’ve got a full 64-bit operating system that’s extremely lightweight, with up to date packages. Maybe you’re bored of a traditional desktop? Try installing these:

1
sudo apk install kodi kodi-gbm retroarch

Then running either sudo kodi or sudo retroarch (necessary to properly connect to X11 and Dbus).

Kodi

Kodi should say you’re using OpenGL ES 3.1 (under Settings > System Information > Video) if your graphics are setup correctly.

Retroarch

You’ll need to install cores to do anything useful. Normally you would go to Settings > User Interface > Views and enable Show Core Updater, however, my suspicion is that those cores are not compiled for aarch64. Instead, we’ll have to install them via APK’s:

1
sudo apk add libretro-nestopia libretro-desmume libretro-mgba libretro-mupen64plus
Like my content? You can show support here.