Steam in FEX

This is a guide for setting up FEX Emulator inside of an Ubuntu 24.04 Distrobox container to run Steam games on arm64 devices.
=== FEX-Emu ===
FEX-Emu is an x86/x86_64 emulator for arm64 Linux. It utilizes an x86_64 root filesystem in conjunction with the native arm64 host filesystem with an interpreter called FEXInterpreter and a modified bash shell for running x86/x86_64 scripted applications called FEXBash. The official install instructions for FEX-Emu are targeted for Ubuntu and utilize an Ubuntu PPA to distribute pre-built versions of FEX. In order to use this official FEX setup on postmarketOS I will be using Distrobox to install an Ubuntu 24.04 arm64 image on top of postmarketOS that I can then install FEX on.
=== Distrobox ===
Distrobox is a container manager designed to install and run persistent containers, optionally with root privileges and their own init system, on top of another distribution. It is available in postmarketOS. To install, simply run:
sudo apk add distrobox
=== Before Installing ===
Before installing, if you want to make sure any previous attempts have been cleaned up from your home directory, run the following commands from your home directory:
rm .steampid
rm .steampath
rm -rf .steam
rm -rf .local/share/Steam
rm -rf .config/.fex-emu
rm -rf .local/share/.fex-emu
=== Installing Ubuntu 24.04 image ===
Create the Ubuntu 24.04 Distrobox install by running:
distrobox create --image ubuntu:24.04 --root --init --additional-packages "ubuntu-desktop"
This will create an Ubuntu 24.04 container with root privileges, its own init system (systemd), and will install the ubuntu-desktop package that provides the majority of the needed libraries and utilities for a smooth setup. You can lighten the install size by manually selecting only the needed libraries, but I chose to install the full ubuntu-desktop package to minimize risk of missing dependencies.
Then you will need to enter the image by running:
distrobox enter --root ubuntu-24-04
This will go through the first-time setup which involves downloading all the packages and should eventually present you with a password prompt to create a password for your user account within the container. If it doesn't provide this prompt on the first run, run this command again and it should then give the password prompt.
After this, you should be inside of the Ubuntu container.
=== Installing FEX-Emu ===
Now that you're inside the container, you can prepare to run the FEX install script.
First, you will need to unmask the systemd-binfmt service, as this seems to be masked by default and will break the installation if left masked:
sudo systemctl unmask systemd-binfmt
Next, run the install command from the FEX-Emu GitHub Readme. I will not paste the command here as it executes a script from curl and this could be a security risk if the URL changes. Refer to the FEX-Emu GitHub for the latest install command:
https://github.com/FEX-Emu/FEX?tab=readme-ov-file#quick-start-guide
When it asks if you wish to download and install a rootfs, say yes (y) to the prompts to download the Ubuntu 24.04 (SquashFS) rootfs. When it asks if you want to extract the rootfs or use it as is, answer extract (1). There seems to be an issue using squashed rootfs inside distrobox, so we will need to extract it. When it asks if you want to use this rootfs as default, answer yes (y).
Once this finishes running, FEX should be installed. Confirm by running:
FEXInterpreter /usr/bin/uname -a
This should print out the kernel string but it should identify the architecture as x86_64 instead of arm64/aarch64.
=== Installing Steam ===
You can follow the FEX Steam installation guide from the FEX wiki: https://wiki.fex-emu.com/index.php/Steam
=== Issues and Workarounds ===
* Sometimes Steam fails to start due to steamwebhelper crashing. I've found that deleting Steam's log files might help, but this may just be placebo.
rm ~/.steam/steam/logs/*
* Wayland-native games don't seem to be working. For Source engine games (Half Life 2 and Half Life 2 Deathmatch tested), add SDL_VIDEODRIVER=x11 %command% to the launch options for the game.
* I recommend setting up a swapfile of at least 4GB before attempting to run most games. I was seeing frequent OOM crashes without, even on an 8GB RAM device.