Installing Arch Linux ARM on a SD card for Raspberry Pi 0 W and loading wifi credentials for headless usage
Before starting I highly suggest you create a new directory on your /home/user
directory with an appropiate name for this task like rpi0alarm
so you can change directory to /home/user/rpi0alarm
and go through the following steps.
As I wrote this guide after collecting info from different sources (listed at the end) be mindful of your current path and the commands you are running to not damage your current installation on the host computer you are creating the SD Card.
Replace sdX
in the following instructions with the device name for the SD card as it appears on your computer. Use lsblk
to check the drives connected to it. If there's a single drive it will show as sda
and your SD Card will appears as sdb
(partitions being sdb1
and sdb2
). You can easily identify it also by it's size (tipically 8/16/32 GB).
- Start fdisk to partition the SD card:
$ fdisk /dev/sdX
-
At the fdisk prompt, delete old partitions and create a new one:
a. Type
o
. This will clear out any partitions on the drive.b. Type
p
to list partitions. There should be no partitions left.c. Type
n
, thenp
for primary,1
for the first partition on the drive, press ENTER to accept the default first sector, then type+100M
for the last sector.d. Type
t
, thenc
to set the first partition to type W95 FAT32 (LBA).e. Type
n
, thenp
for primary,2
for the second partition on the drive, and then press ENTER twice to accept the default first and last sector.f. Write the partition table and exit by typing
w
. -
Create and mount the FAT filesystem:
$ mkfs.vfat /dev/sdX1
$ mkdir boot
$ mount /dev/sdX1 boot
- Create and mount the ext4 filesystem:
$ mkfs.ext4 /dev/sdX2
$ mkdir root
$ mount /dev/sdX2 root
- Download and 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 root
$ sync
- Move boot files to the first partition and unmount both partitions and remove the local directories:
$ mv root/boot/* boot
$ umount boot root
$ sudo rm -R boot root
-
Create this script to enable Wifi on boot time for headless use through ssh:
In this step you are about to create a small script that will setup your wifi network so the Raspberry Pi 0 W autoconnects after booting for the first time so you can access it through SSH
a. After extracting the contents of
ArchLinuxARM-rpi-latest.tar.gz
into/root
and/boot
partitions you created on your SD Card, you now need to create on your computer a file:$ nano al-wpa-setup.sh
b. This will open a blank
nano
editor. Paste the following code and save the file (using Ctrl+o and Ctrl+x)#!/bin/sh set -e if [[ $# -ne 3 ]] ; then echo "Usage: $0 </dev/disk> <ssid> <passphase>" exit 1 fi DISK="$1" SSID="$2" PASS="$3" if [[ ! -b "${DISK}" ]] ; then echo "Not a block device: ${DISK}" exit 1 fi if [[ "${USER}" != "root" ]] ; then echo "Must run as root." exit 1 fi echo "Mounting ${DISK} into rpi0alarm/root and writing values" mkdir root mount "${DISK}2" root cat << EOF >> root/etc/systemd/network/wlan0.network [Match] Name=wlan0 [Network] DHCP=yes EOF wpa_passphrase "${SSID}" "${PASS}" > root/etc/wpa_supplicant/wpa_supplicant-wlan0.conf ln -s \ /usr/lib/systemd/system/[email protected] \ root/etc/systemd/system/multi-user.target.wants/[email protected] echo "Unmounting ${DISK} from rpi0alarm/root" umount root echo "Cleaning up and erasing local rpi0alarm/root directory" rmdir root
This script will ask for three parameters
DISK
,SSID
andPASS
and then will write those into/root
on your SD Card.c. We now need to make the script executable:
chmod +x al-wpa-setup.sh
d. Execute the script and pass the appropiate parameters,
/dev/sdX
,SSID
andwifi_password
, in this example your SD Card issdb
, SSID ishome_network
and the password isdrowssap
:./al-wpa-setup.sh /dev/sdb home_network drowssap
-
Now we can finally insert the SD card into the Raspberry Pi 0 and connect it to it's 5V power source, the green light will blink a few times and stay on. Give it a minute or so and continue.
-
Use the serial console or SSH to the IP address given to the board by your router, hostname is alarmpi.
-
Login as the default user
alarm
with the passwordalarm
. -
The default
root
password isroot
. -
Successful login will get you to the Raspberry Pi 0 prompt like so,
Welcome to Arch Linux ARM Website: http://archlinuxarm.org Forum: http://archlinuxarm.org/forum IRC: #archlinux-arm on irc.Freenode.net Last login: Day Month XX XX:XX:XX:XX YEAR from XXX.XXX.XXX.XXX [alarm@alarmpi ~]$
-
-
Initialize the pacman keyring and populate the Arch Linux ARM package signing keys:
[alarm@alarmpi] $ pacman-key --init
[alarm@alarmpi] $ pacman-key --populate archlinuxarm
-
As you don't want to run your system as root all the time or switching accounts you need to install
sudo
, in case you are planning to go withroot
user you can just skip up to step XX.a. To do so, we will have to switch momentarily to
root
to update our package list and then installsudo
[alarm@alarmpi] $ su
Enter your
root
password and from there execute,[root@alarmpi] pacman -S sudo
b. Now we have to give the user
alarm
sudo powers, we need to add this user to thewheel
usergroup,[root@alarmpi] $ gpasswd -a alarm wheel
c. And we need to edit
/etc/sudoers
to acceptwheel
group commands as root. We can do it easily with the inbuilt commandvisudo
,[root@alarmpi] $ visudo
You will be now scrolling with
vi
inside the file and you need to look and edit the following lines, we are going to uncomment this lines by removing the#
using thex
or theDelete
key. As follow are the lines we will be looking for,# %wheel ALL=(ALL) ALL
and# %wheel ALL=(ALL) NOPASSWD: ALL
,## Uncomment to allow members of group wheel to execute any command # %wheel ALL=(ALL) ALL ## Same thing without a password # %wheel ALL=(ALL) NOPASSWD: ALL
After doing that all we have to do is type
:x
to save and exit. In case there's something wrong or you edited something you shouldn't you can just go and pressEsc
and type:q!
to exit without saving any changes.d. To make all this changes take effect we have to reboot the Raspberry Pi 0,
[root@alarmpi] $ reboot
e. As a final step to check everything went well we can SSH into the Raspberry Pi 0 again and from the user
alarm
update ourpacman
cache,[alarm@alarmpi] $ sudo pacman -Syy
Thanks! Super helpful