How to install Arch Linux ARM on Raspberry Pi 3b+

Published by mr.pigeon on

arch linux + raspberry pi

How to Install Arch Linux on a Raspberry Pi 3b+

Introduction

Before installing Arch Linux on a Raspberry Pi, lets first understand what Arch Linux is. Arch Linux is an independently developed, x86-64 general purpose GNU/Linux distribution. It is versatile enough to fit many kinds of users. The developers focuses on the simplicity, minimalism, and code elegance of the system. Arch is installed as a minimal base system, configured by the user upon which their own perfect environment is established by installing only what required or desired for their unique purposes. GUI configurations utilities are not officially provided, and most system configurations is performed from the shell by editing configuration files. Arch strives to stay bleeding edge, and offers the most latest stable versions of most software.

Arch Linux has its own package manger system called 'Pacman' which couples simple binary packages with an easy-to-use package build system. This allows users to easliy manage and customize packages ranging from official Arch software repositories to the user's own personal packages to packages from 3rd party sources.

Arch Linux uses a "rolling release" system which allows one-time installation and perpetual software upgrades. By issuing one command Arch system is kept up-to-date and on the bleeding edge.

The installation of Arch Linux on the Raspberry Pi is not exactly an installation but an extraction of the latest arch release root filesystem for the ARM architecture to the SD card. Before we reach to that, we first need to prepare the partitions we are going to work with.

Step 1: Preparing SD card partitions

Assuming we are preparing the SD card from a linux distribution, replace sdX with the appropriate device letter as it appears in dmesg

sudo parted --script /dev/sdX \
  mklabel msdos \
  mkpart primary fat32 1MiB 200MiB \
  mkpart primary ext4 200MiB 100% \
  set 1 boot on

Step 2: Format the partitions

sudo mkfs.vfat /dev/sdX1
sudo mkfs.ext4 /dev/sdX2

Step 3: Mount

After we have prepared our partitions and formatted them, lets mount them so we can unpack the root filesystem there.

sudo mkdir /mnt/boot
sudo mkdir /mnt/root
mount /dev/sdX1 /mnt/boot
mount /dev/sdX2 /mnt/root

Step 4: Download & Extract the root filesystem (as root, not via sudo)

wget http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-latest.tar.gz
bsdtar -xpf ArchLinuxARM-rpi-latest.tar.gz -C /mnt/root/
sync

Step 5: Move boot files to the boot partition

sudo mv /mnt/root/boot/* /mnt/boot

Step 6: Unmount

sudo umount /mnt/boot /mnt/root
  • Remove the SD card from your computer, plug it into the Raspberry Pi, attach ethernet cable, power, and boot it.
  • Connect to your Raspberry Pi using a serial cable or SSH to it by the IP you get from your router.
  • Default user: alarm/alarm
  • Default root: root/root

Step 7: package signing keys & pacman keyring

sudo pacman-key --init
sudo pacman-key --populate archlinuxarm
sudo -Sy pacman
sudo pacman -S archlinux-keyring
sudo pacman -Syu

Optional: Add color to pacman output

sudo sed -i 's/#Color/Color/' /etc/pacman.conf

Step 8: Install useful packages

The base root filesystem comes with a basic set of tools, it is a good idea to install the following and add them to your system.

sudo pacman -S --needed nfs-utils base-devel sudo binutils diffutils libnewt dialog wpa_supplicant wireless_tools iw crda lshw tmux pkgfile vim git go rxvt-unicode

Step 9: User Configurations

To make our system more secure, we will change the default root password, remove the default user and add our own user account to the system and set it's password

sudo userdel alarm
sudo passwd root
sudo useradd -m -G wheel -s /bin/bash username_here
sudo passwd username_here

Step 10: SUDO'ers

Best practice says we shouldn't work directly with root account on regular basis, instead we will add our regular user account to the SUDO'ers list so we can use root privileged permissions only when neccesarry.

visudo
# Uncomment the line
%wheel ALL=(ALL) ALL

Step 11: Set the Hostname

sudo hostnamectl set-hostname hostname-here

Step 12a: Networking (Wired)

If you prefer you can skip this part and use the default which is DHCP, otherwise edit the file /etc/systemd/network/eth.network and match your configuration

[Match]
Name=eth*
[Network]
DNSSEC=no
Address=192.168.1.100/24
Gateway=192.168.1.1
DNS=192.168.1.1

Step 12b: Networking (WiFi)

Navigate to /etc/wpa_supplicant folder and create a file i.e home-network and enter the following in the file:

network={
  ssid="YOURSSID"
  psk="YOURWIFIPASSWORD"
}

Now, run the following command to connect to your WiFi:

sudo wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/home-network &
dhcpcd wlan0

Step 13: Enable SPI and I2C ports

In order to enable SPI and I2C ports on our Raspberry Pi device we will need to add those two lines in /boot/config.txt

device_tree_param=spi=on
dtparam=i2c_arm=on

Step 14 (Optional): Enable AUR repository

git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si

Step 15 (Optional): Setup a swapfile

Depending on your use of the Raspberry-Pi, Allocating a swap memory can be a good idea due to the fact that the Raspberry-Pi comes with only 1GB of RAM. In order to give the system more breathing space, we can allocate a swapfile that the system can turn to if the available system memory is not enough. To do so, we will first allocate a sawpfile, set its permissions, and format the file as swap.

sudo fallocate -l 1024M /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo echo 'vm.swappiness=1' > /etc/sysctl.d/99-sysctl.conf

Add swap entry to the end of /etc/fstab file so it will be ready at boot time.

/swapfile   none  swap  defaults  0 0

Conclusion

In this tutorial we have successfully prepared a SD card with the Arch Linux root filesystem, added useful packages, configured our users and networking and additional tunning for the system.

Read more


4 Comments

Avatar

Izik · April 28, 2020 at 5:55 pm

Thank you very much for this guide.

Avatar

Bernhard Ernst · October 4, 2020 at 9:46 pm

Very good guide, thanks for that. It even works perfect with my raspberry 4, which now runs Arch.

Leave a Reply

Your email address will not be published. Required fields are marked *