Skip to content

Build Arch Linux with Packer & deploy, manage via Ansible.

Notifications You must be signed in to change notification settings

starise/ArchLinuxPi

Repository files navigation

Arch Linux on Raspberry Pi 4

Build and deploy a custom Arch Linux image for Raspberry Pi 4.

Requirements

# Required packages on Arch Linux host
$ yay -S ansible packer qemu qemu-extra qemu-arch-extra qemu-user-static-bin

The above packages are enough to build Packer images locally (commonly on Gnu/Linux). On MacOS, Windows 10 or when you just don't want to setup Packer and all the tools, Docker is also required:

Packer - Build custom Arch image for Raspberry Pi

Pre-set packer sources available are:

  • ArchLinux ARM armv7 (32-bit)
  • ArchLinux ARM aarch64 (64-bit)

Open and edit the variables.pkrvars.hcl file to customize all the desired values.

Packer - Build image locally

Build the image using the latest available release:

$ sudo packer build -var-file="variables.pkrvars.hcl" packer/aarch64/

Packer - Build image in Docker (MacOS/Windows)

When there's no native way to use qemu-user-static (MacOS or Windows 10) the image can be built using Docker:

$ docker run --rm --privileged \
  -v /dev:/dev -v ${PWD}:/build \
  packer-builder-arm build \
  -var-file="variables.pkrvars.hcl" packer/aarch64/

On Windows 10, the command above should be executed into a WSL2 console.

Flashing the image on the SD Card

On GNU+Linux it's a very straightforward process:

# `/dev/sdX` is the device that represents your SD Card
$ umount /dev/sdX*
$ dd if=custom-rpi.img of=/dev/sdX

Another simple multiplatform tool to flash the image is Balena Etcher available for Windows 10, MacOS and GNU+Linux.

When done, put the SD Card into your Raspberry Pi 4 and Power On the device.

Access to Raspberry Pi from the local network

When your machine is up and ready, it should be accessible via SSH using the assigned static IP address (net_address variable), or using hostname.local where hostname is the assigned hostname.

$ ssh -i <path/to/id_rsa> alarm@192.168.0.1

Ansible - Configure the system

Install required collections and roles:

$ ansible-galaxy install -r requirements.yml

Open and edit group_vars/*.yml files to customize the desired values. Once you have made the desired changes, let's configure the system via Ansible running the system.yml playbook:

$ ansible-playbook system.yml