Skip to content

Instantly share code, notes, and snippets.

@jsmcnair
Last active November 5, 2023 14:56
Show Gist options
  • Save jsmcnair/f810f66dfe327411669ac5ad6f4ac42c to your computer and use it in GitHub Desktop.
Save jsmcnair/f810f66dfe327411669ac5ad6f4ac42c to your computer and use it in GitHub Desktop.
Arch Linux ARM SD card configuration (Raspberry Pi 4)
# Based on https://archlinuxarm.org/platforms/armv8/broadcom/raspberry-pi-4
# Find the disk to work with
# lsblk | grep -v loop
DISK=${DISK-"mmcblk0"}
BOOTPART=${BOOTPART-"mmcblk0p1"}
ROOTPART=${ROOTPART-"mmcblk0p2"}
# Erase all partitions on the disk and create a new layout
DISKPATH="/dev/$DISK"
wipefs -a $DISKPATH
parted $DISKPATH mklabel gpt
parted $DISKPATH --align optimal mkpart primary fat32 1 200
parted $DISKPATH --align optimal mkpart primary ext4 201 100%
# Locate the new partitions on the disk
lsblk | grep $DISK
# Create and mount boot partition
mkfs.vfat /dev/$BOOTPART
mkdir -p /tmp/arch/boot
mount /dev/$BOOTPART /tmp/arch/boot
# Create and mount root partition
mkfs.ext4 /dev/$ROOTPART
mkdir -p /tmp/arch/root
mount /dev/$ROOTPART /tmp/arch/root
# Get the latest aarch64
wget http://uk.mirror.archlinuxarm.org/os/ArchLinuxARM-rpi-armv7-latest.tar.gz
# Extract to the mounted root partition
tar -zxvpf ArchLinuxARM-rpi-armv7-latest.tar.gz -C /tmp/arch/root && sync
# Copy boot files
mv /tmp/arch/root/boot/* /tmp/arch/boot
# Update fstab for Pi4 - this was recommended but was incorrect on my Pi (400)
# sed -i 's/mmcblk0/mmcblk1/g' /tmp/arch/root/etc/fstab
# This was required to get the Pi4 to boot
# sed -E -i 's/booti(.*)fdt_addr_r/booti\1fdt_addr/g' /tmp/arch/boot/boot.txt
# Requires mkimage from u-boot-tools if running from a different arch (e.g Ubuntu on x64)
# sudo apt install -y u-boot-tools
pushd /tmp/arch/boot &&
mkimage -A arm -T script -O linux -d boot.txt boot.scr &&
popd
# Arch linux setup script
echo '#!/bin/sh\npacman-key --init && pacman-key --populate archlinuxarm' > /tmp/arch/root/root/setup-script.sh
wget https://gist.githubusercontent.com/jsmcnair/060e209efffbcafab5e72974d0f88588/raw -O setup-script
cat setup-script >> /tmp/arch/root/root/setup-script.sh
rm setup-script
# unmount the partitions
umount /tmp/arch/*
# Ready to boot!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment