Skip to content

Instantly share code, notes, and snippets.

@larsch
Created July 6, 2017 06:05
Show Gist options
  • Star 54 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
  • Save larsch/4a320f8ee5586fe6170af8051fcd9f85 to your computer and use it in GitHub Desktop.
Save larsch/4a320f8ee5586fe6170af8051fcd9f85 to your computer and use it in GitHub Desktop.
Install Arch Linux ARM for Raspberry Pi Zero W on SD Card (with commands to configure WiFi before first boot).
#!/bin/sh -exu
dev=$1
cd $(mktemp -d)
function umountboot {
umount boot || true
umount root || true
}
# RPi1/Zero (armv6h):
archlinux=/tmp/ArchLinuxARM-rpi-latest.tar.gz
url=http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-latest.tar.gz
# RPi2 (armv7h):
# archlinux=/tmp/ArchLinuxARM-rpi-2-latest.tar.gz
# url=http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-2-latest.tar.gz
curl -L -o $archlinux -z $archlinux $url
parted -s $dev mklabel msdos
parted -s $dev mkpart primary fat32 1 128
parted -s $dev mkpart primary ext4 128 -- -1
mkfs.vfat ${dev}1
mkfs.ext4 -F ${dev}2
mkdir -p boot
mount ${dev}1 boot
trap umountboot EXIT
mkdir -p root
mount ${dev}2 root
bsdtar -xpf $archlinux -C root
sync
mv root/boot/* boot
# Commands to configure WiFi before first boot (netctl-auto)
# - you need to temp edit root/etc/pacman.d to point to /path/to/root/etc/pacman.d/mirrorlist
# - change it back after installing
# pacman -r root --arch armv6h --config root/etc/pacman.conf --cachedir root/var/cache/pacman/pkg --dbpath root/var/lib/pacman -Sy
# pacman -r root --arch armv6h --config root/etc/pacman.conf --cachedir root/var/cache/pacman/pkg --dbpath root/var/lib/pacman -S wpa_actiond
# ln -sf /usr/lib/systemd/system/netctl-auto@.service root/etc/systemd/system/netctl-auto@wlan0.service
# cat >root/etc/netctl/wlan0-SSID <<EOF
# Description='WiFi - SSID'
# Interface=wlan0
# Connection=wireless
# Security=none
# ESSID=enter-ssid-here
# IP=dhcp
# EOF
@blalor
Copy link

blalor commented Jul 3, 2018

Looks like you need to systemctl enable netctl-auto@wlan0.service for this to work on boot.

@yarons
Copy link

yarons commented Jun 13, 2019

Great work there although I would suggest adding an option to switch mkfs.vfat ${dev}1 into mkfs.vfat ${dev}p1 in case of mmcblk/SD Card, not to mention cases of NVMe (Which are highly plausible in that case).

@truedat101
Copy link

For actual bourne shell on Ubuntu, I found function undefined line 5, rewrite as:

umountboot() {
...
}

@samip5
Copy link

samip5 commented Dec 3, 2022

@truedat101
Copy link

Some details here: https://forums.raspberrypi.com/viewtopic.php?t=326235 . It seems they've moved on to the rpi zero-2 .

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