This guide will use either a macOS or an ArchLinux base system, to prepare a microSD card with Arch Linux for Raspberry Pi.
If someone managed to do the initial setup using Windows, please let me know, so I can add to this guide.
This guide will be verbose at times for some simple tasks. This is intended to help people just starting out, so it's not confusing. If something confuses you, let me know and I'll try my best to answer it.
Special thanks to karog on ArchLinuxARM forums for their contributions on improving this guide!
The aarch64
(ARM 64-bit architecture) is not officially supported at the writing of this guide.
The official arm image we will be using uses armv7h
(32 bits).
If you want to use an unoficial image that support sthe 64-bit architecture, you can find it in this forum topic.
You can follow all the steps in this guide and just need to replace the images when the time come, in Part 1, Step 15 of this guide.
- A target Raspberry Pi. I used a Raspberry Pi 4 8GB model.
- A base system that is either:
- macOS
- PC running ArchLinux
- Raspberry Pi running ArchLinux
- A USB microSD Card reader. Do NOT use the macOS built in SD Card reader! You won't be able to edit partitions if you do!
- A microSD Card. I used a 256GB one, but anything over 16GB should work.
- Patience
- For macOS Only: Paragon extFS for macOS. The Trial version is fine for this guide.
For the preparation you can use either a macOS base system or an ArchLinux base system. Select the appropriate section for your system below. Keep in mind this setup will wipe the contents of the microSD card!
- Insert the microSD card in the USB reader, and insert the reader in your mac. Again: Do NOT use the built in SD reader!
- Open Disk Utility and check what is the device name for your microSD card. Here it is
disk2
, so I will be using this name on this guide. You might need to click the "View" icon and set "Show all devices". - From the last step, my microSD is
disk2
, so I will be using/dev/disk2
. Replace accordingly, if following this guide! I am not responsible for data loss! - Unmount the volumes using Disk Utility. Do NOT eject the device, only unmount the volumes. They will appear greyed out after unmounting.
sudo fdisk -i /dev/disk2
. This will initialize a new MBR on your microSD. This will destroy all data!sudo fdisk -e /dev/disk2
. This will enter fdisk in "edit in interactive mode".- Type
print
and press enter. If you see the table below with 4 unused fields, you can type quit and proceed to step 12.
Starting Ending
#: id cyl hd sec - cyl hd sec [ start - size]
------------------------------------------------------------------------
1: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
2: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
3: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
4: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
- Type
erase
and press enter. - Type
write
and press enter. - Type
print
and press enter. This should give you the table displayed in step 7. - Type
quit
and press enter. - Here, we're done with the fdisk step. If you're coming from step 7, this is the right step to proceed on.
- Now we need to format a 512Mb FAT32 partition for booting, and an ext4 partition with the rest of the space available to store out files.
- Run
sudo diskutil partitionDisk /dev/disk2 MBR fat32 "boot" 512m UFSD_EXTFS4 "root" 0b
, and wait until completion. You will need Paragon extFS installed for this step. - Download the version you want to run in your Raspberry pi to your favourite directory. In my exampe, I downloaded it to
~/Downloads
.- AArch64 version (64-bits): http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-aarch64-latest.tar.gz
- ARMv7 version (32-bits): http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-4-latest.tar.gz
- Once the formatting is done, go to Disk Utility and eject the device. Remove the USB Card Reader, take a deep breath and reinsert it. Yes, the deep breath is important :)
cd /Volumes/root
sudo tar -xpf ~/Downloads/ArchLinuxARM-rpi-4-latest.tar.gz
. Remember to use the correct file name you downloaded in the step 15. Wait until it's fully decompressed.sudo mv boot/* ../boot
sudo sync
- If you decided to download AArch64 version, you need to run this command:
sudo sed -i 's/mmcblk0/mmcblk1/g' etc/fstab
- Eject the devide using Disk Utility.
Done! You have a barebones ArchLinux install in your microSD!
All the steps below must be done as root
.
- Get the necessary tools to partition and format the microSD card:
pacman -S sudo
pacman -S dosfstools
- Use
lsblk
to check the storage devices currently attached to the system. - Insert the microSD card in the USB reader, and insert the reader in your system.
- Use
lsblk
again. See what is the new drive attached since step 2. Here, the microSD card received the namesda
, and I'll use it for the rest of this guide. - Use
sudo fdisk /dev/sda
to start partitioning the card. Be sure to use the correct device from step 4 before proceeding! - Type
p
- This will show the current partitions on the device. Again, make sure this is the correct device! You can typeq
and press enter if thisis the wrong device. - Type
o
- This will clear out any partitions on the device. - Type
p
- This will show the current partitions on the device. There should be no partitions left. - Type
n
to add a new partition, thenp
for primary, then1
for the first partition on the drive. Press enter to accept the default first sector, then type+512M
for the last sector. - If after you're done with the step 9 it asks about removing a signature, confirm it with
y
. - Type
t
to change the partition type, then typec
to change the first partition type toW95 FAT32 (LBA)
. - Type
n
to add a new partition, thenp
for primary, then2
for the second partition on the drive. Press enter twice to accept the default first and last sector. - If after you're done with the step 12 it asks about removing a signature, confirm it with
y
. - Type
w
to write the partition table and exit. - Your microSD card is now partitioned.
- Format the partitions. Remember to use the correct device from step 4!
mkfs.vfat /dev/sda1
mkfs.ext4 /dev/sda2
cd /mnt
. Depending on your distro, this could becd /mount
- Create the mount directories, mount the drives and change directory to the root mount:
mkdir boot root
mount /dev/sda1 boot
mount /dev/sda2 root
cd root
- Selected the version you want for your RaspberryPI and use wget to download it.
- AArch64 version (64-bits): http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-aarch64-latest.tar.gz
- ARMv7 version (32-bits): http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-4-latest.tar.gz For example, to download the AArch64 use:
wget http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-aarch64-latest.tar.gz
- Decompress the file. Use the the name of the file you downloaded in the previous step. For example, to decompress the AArch64 file, use:
tar -xvzf ArchLinuxARM-rpi-aarch64-latest.tar.gz
mv boot/* ../boot
sync
- If you decided to download AArch64 version, you need to run this command:
sed -i 's/mmcblk0/mmcblk1/g' etc/fstab
cd ..
umount boot root
rmdir boot root
Done! You have a barebones ArchLinux install in your microSD!
Since AArch64 is quite new, there are some issues that could happen.
At the time this guide was written, there's an issue that it's not possible to use the keyboard after booting.
You can check the date on the bcm2711-rpi-4-b.dtb
file, in the boot partition, and if it dates 18th January 2021, it's a bad file.
You need to replace it with this one: https://github.com/raspberrypi/firmware/raw/master/boot/bcm2711-rpi-4-b.dtb
After replacing it, everything will work as it should.
If you're running an outdated version of ArchLinux, you might need to do a full system update to solve the issue.
Connect an ethernet cable, connect via ssh, login with the alarm
user, su
to root and proceed with the steps below to perform a full system update.
Put your microSD card in your Raspberry Pi and turn it on. It will boot to the login prompt.
The standard user login is alarm
and password alarm
. alarm
stands for "Arch Linux ARM".
The root user login is root
and password root
.
Go ahead and login as root and start doing the steps below:
- Update your timezone:
timedatectl set-timezone Europe/London
. You can check the available timezones withls /usr/share/zoneinfo
and searching inside that directory. Example:ls /usr/share/zoneinfo/America
will allow me to find theAmerica/Sao_Paulo
timezone. - Update the clock:
timedatectl set-ntp true
. If you have a RTC (Real Time Clock) module, you should setup it here. I don't have one to provide the steps. nano /etc/locale.gen
and remove the#
from your locale (e.g.en_US.UTF-8
). I was tempted to putvi
here, but this guide is aimed at beginners.- If this is your first time using
nano
, Ctrl + O saves the file and Ctrl + X exitsnano
. - Run
locale-gen
. localectl set-locale LANG=en_US.UTF-8
. Make sure you replaceen_US.UTF-8
with the locale you uncommented in step 3.hostnamectl set-hostname <name>
. Make sure you replace<name>
with your desired hostname. If you're out of ideas, check this reddit link for some inspiration ;)nano /etc/hosts
and make sure it has this lines, replacingmyhostname
with the hostname you set in the previous step:
127.0.0.1 localhost.localdomain myhostname localhost
::1 localhost.localdomain myhostname localhost
- (Optional) Add color to
pacman
output:sed -i 's/#Color/Color/' /etc/pacman.conf
- Setup swap memory. This will reserve 1 GiB of your SD card to use as virtual memory, and set it to an extremely low priority, so it only uses it only if your system is completely out of physical RAM memory.
fallocate -l 1024M /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap defaults 0 0' >> /etc/fstab
echo 'vm.swappiness=1' > /etc/sysctl.d/99-sysctl.conf
It is highly recommended that you perform a complete system update now.
Plug an ethernet cable to your Raspberry Pi before proceeding.
If you only have access to WiFi, check the next section for how to setup a temporary connection.
Make sure you have a working network and run:
- pacman-key --init
- pacman-key --populate archlinuxarm
- pacman -Syu
- This could take a few minutes, depending on how much you have to update. Go get coffee :)
- Once it is done, run
reboot
and you're ready to go!
It is not recommended to keep using the system as root for a number of reasons. This part aims to do a basic user setup to get you started on using your system.
Here we will use visudo
utility to edit group permissions to run administrative commands with sudo
.
pacman -S sudo
EDITOR=nano visudo
. If you know how to usevi
, you can omit theEDITOR=nano
part.- Search for the line
%wheel ALL=(ALL) ALL
and uncomment it (i.e. delete the#
from the start of the line.) - Save and exit nano.
Now you want to create your user. In the steps below, replace your_username
with your intended login username.
Still as root
, run:
useradd -m -G wheel your_username
Change your password:
passwd your_username
Delete the standard user:
userdel alarm
Now you're ready! reboot
and login with your user! Enjoy!
karog, on ArchLinux ARM forums provided a simple way to connect to Wi-Fi.
As root
, do the following steps:
nano /etc/systemd/network/wlan0.network
to configure the wlan0 interface:- Add the following contents to the file:
[Match]
Name=wlan0
[Network]
DHCP=yes
wpa_passphrase "<SSID>" "<PASSWORD>" > /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
. Replace and with your respective Wi-Fi network name and password.systemctl enable wpa_supplicant@wlan0
to enable the Wi-Fi when bootingsystemctl start wpa_supplicant@wlan0
to connect to Wi-Fi.
You're good to go!
If you ever want to remove Wi-Fi connection (e.g. when you want to make it connect only through ethernet):
systemctl stop wpa_supplicant@wlan0
systemctl disable wpa_supplicant@wlan0
rm /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
rm /etc/systemd/network/wlan0.network
this does not work if you have a compute module 4 as its missing critical files for it to boot