Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Last active February 1, 2020 17:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WebReflection/f98ab387a0cbde9230920ad6d16565aa to your computer and use it in GitHub Desktop.
Save WebReflection/f98ab387a0cbde9230920ad6d16565aa to your computer and use it in GitHub Desktop.
How to configure aarch64 Raspberry Pi 3 on ArchLinux

PC Setup

To make this possible you need qemu static built for other architectures. Be sure the following works before going any further here.

alias aur=pakku|yay|yaourt
aur -Sy --needed --noconfirm qemu-user-static binfmt-qemu-static

Disk Setup

Create an ext4 partition on a capable, and possibly fast, HD. Theoretically the disk could be any big enouogh file created in your own env, but I prefer keeping the HD external to be able to carry it with me.

The suggested minimum size for such disk is 64GB. You won't need all this space but building anything might need extra space.

Label such partition RPi3 for simplicity sake.

Download latest ArchLinux for rpi 3:

curl -LO http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-3-latest.tar.gz

Mount the ext4 partition in a folder and extract it (as root):

DISK=/dev/sdXN
mkdir -p ~/RPi3
mount $DISK ~/RPi3
bsdtar -xpf ArchLinuxARM-rpi-3-latest.tar.gz -C ~/RPi3
sync
cp /usr/bin/qemu-aarch64-static ~/RPi3/usr/bin
sync
umount ~/RPi3
rm -rf ~/RPi3

That's it. Unplug the disk, and plug it back.

ArchLinux Setup

Mount the disk, if needed, otherwise, as a regular user:

sudo mount -n -o remount,suid /run/media/${USER}/RPi3
sudo arch-chroot /run/media/${USER}/RPi3 /bin/bash

I have saved above content into an rpi3 file, added #!/usr/bin/bash and used chmod a+x rpi3 to be able, as regular user, to simply ./rpi3 whenever I want/need.

Please note the remount part is necessary to have not sudo, but at least yaourt to run in there without issues.

Once in, ensure you are in the right env/arch via uname -m which shuold show aarch64.

First Time In

As soon as chrooted, create a profile file that will do some necessary step each time.

echo "
# setup a DNS
echo 'nameserver 1.1.1.1
nameserver 1.0.1.0'>/etc/resolv.conf

# use more space for the /tmp if needed
mount -o remount,size=16G,noatime /tmp
">>~/.bashrc
source ~/.bashrc

Keys and Update

Update the whole env after populating all keys:

pacman-key --init
pacman-key --populate archlinuxarm
pacman -Syu

Language and helpers

Set the default language (en-US in this case) and install aur

export LANG=en_US.UTF-8
export LANGUAGE="$LANG"
export LC_ALL="$LANG"
sed -i "s/#$LANG UTF-8/$LANG UTF-8/" /etc/locale.gen
locale-gen
locale > /etc/locale.conf

bash <(curl -s https://archibold.io/install/aur)

su alarm -c 'bash <(curl -s https://archibold.io/utils/sudo)'

Swap ?

Theoretically the hosting system swap shouold be enouogh. But if you don't have much, remember to swapon /swap file once chrooted, after creating the /swap file via dd if=/dev/zero of=./swap bs=8192 count=1024000, as example, for an 8GB swap.

Also needed:

chmod 0600 /swap
mkswap /swap

Working with AUR

Since sudo is basically useless in this environment, and su alarm is not too powerful when sudo is needed with AUR packages, the only way I've found to install right away from AUR is via the good old, deprecated, unmaintained yaourt.

I've uploaded an archibold.io script that doesn't need sudo and builds yaourt:

bash <(curl -s https://archibold.io/install/yaourt)

Once installed, remember to perform any operation via alarm user, not via the root one.

Alternative

I've also created a very minimalistic AUR installed called, guess what, aur.

bash <(curl -s https://archibold.io/install/aur)

That gives you the ability to install pretty much anything without sudo, unless the package itself requires it, of course.

aur wpewebkit
aur --preserve wpewebkit

If the --preserve flag is passed, the built folder won't be removed, which is handy when you cross build packages for the aarch64 target.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment