scripts/cm5-setup.sh script creates a complete, bootable Arch Linux aarch64 disk image for the RPi5 / CM5 Exaviz carrier. It handles partitioning, formatting, bootstrapping, initramfs generation, UEFI firmware deployment, and GRUB installation in a single run.
Prerequisites
The script must run as root on an x86_64 Linux host with QEMU user-space emulation installed. Required tools:| Tool | Package (Arch/Debian) |
|---|---|
parted | parted |
mkfs.fat | dosfstools |
mkfs.btrfs | btrfs-progs |
losetup | util-linux |
btrfs | btrfs-progs |
wget | wget |
unzip | unzip |
arch-chroot | arch-install-scripts |
pacstrap | arch-install-scripts |
qemu-aarch64-static | qemu-user-static |
You also need an aarch64 pacman configuration at
/etc/qemu-archstrap/pacman-aarch64.conf. This is provided by the qemu-archstrap tool referenced in the repository root.Script arguments
Output image filename. Default:
rpi5-arch.imgTotal image size passed to
truncate. Default: 16GSize of the
swap.img file created inside the @swap subvolume. Default: 4GPath to an SSH public key to inject as
/etc/dropbear/authorized_keys for early SSH rescue. Defaults to ~/.ssh/id_ed25519.pub.What the script does
Create and partition the image
Creates a sparse image file with
The image is attached as a loop device with
truncate, then uses parted to write a GPT partition table with two partitions:| Partition | Type | Range | Label |
|---|---|---|---|
| p1 (ESP) | FAT32 | 1 MiB – 257 MiB | RPI5-EFI |
| p2 (ROOT) | Btrfs | 257 MiB – 100% | ARCH-ROOT |
losetup --find --partscan.Format filesystems
Formats p1 as FAT32 (
mkfs.fat -F32 -n RPI5-EFI) and p2 as Btrfs (mkfs.btrfs -L ARCH-ROOT).Create Btrfs subvolumes
Mounts the root partition and creates six subvolumes:
All subvolumes are mounted with
| Subvolume | Mount point | Notes |
|---|---|---|
@ | / | Root filesystem |
@boot | /boot | Kernel and initramfs |
@swap | /swap | swap.img with nodatacow |
@snapshots | /.snapshots | Snapper snapshots |
@var_log | /var/log | Log isolation |
@home | /home | User home directories |
compress=zstd,space_cache=v2,noatime.Create swap.img
Creates
/swap/swap.img (default 4 GB) with nodatacow disabled via chattr +C before creating the file. This is required for Btrfs swap support.Bootstrap with pacstrap
Bootstraps an aarch64 Arch Linux environment using QEMU transparent emulation:
Write fstab, hostname, locale, timezone
Writes
/etc/fstab with UUID-based mounts for all subvolumes and the ESP. Sets hostname to archlinux-cm5, locale to en_US.UTF-8, timezone to UTC.Configure dracut
Writes
/etc/dracut.conf.d/rpi5.conf enabling the btrfs, dropbear, and network modules. See Dracut Initramfs for details.Set up Dropbear SSH keys
Generates RSA (4096-bit) and ECDSA host keys inside the chroot, then copies the
DROPBEAR_AUTHKEYS public key to /etc/dropbear/authorized_keys.Build initramfs
Runs
dracut twice — once with --hostonly for the primary image and once with --no-hostonly for the fallback image.Deploy RPi5 UEFI firmware
Downloads worproject/rpi5-uefi
v0.3 and copies RPI_EFI.fd and supporting files to the ESP. Writes config.txt to the ESP. See Boot Configuration.Write grub.cfg
Generates a GRUB menu with two entries: the primary Btrfs
@ boot and a fallback initrd entry, plus a UEFI firmware settings entry.Configure Snapper
Creates a Snapper configuration for the root subvolume with timeline snapshots. See Btrfs Snapshots.
Build output
When the script completes successfully, it prints a summary:Next steps
Flash the image
Write the built image to your CM5 eMMC or storage device.
Boot configuration
Understand the boot chain and config.txt options.