TheZoc / Setting up guide for ArchLinux on Raspberry Pi.md
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!
Information about the ARM 64-bit architecture
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
Part 1: microSD Preparation
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!
Using macOS to prepare the microSD
- 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 200Mb 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» 200m 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
Done! You have a barebones ArchLinux install in your microSD!
Using ArchLinux to prepare the microSD
All the steps below must be done as root .
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 name sda , 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 type q 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, then p for primary, then 1 for the first partition on the drive. Press enter to accept the default first sector, then type +200M 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 type c to change the first partition type to W95 FAT32 (LBA) .
- Type n to add a new partition, then p for primary, then 2 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 be cd /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
Done! You have a barebones ArchLinux install in your microSD!
Part 1.5: AArch64 Troubleshooting
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.
Part 2: Initial configuration
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 with ls /usr/share/zoneinfo and searching inside that directory. Example: ls /usr/share/zoneinfo/America will allow me to find the America/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 put vi here, but this guide is aimed at beginners.
- If this is your first time using nano , Ctrl + O saves the file and Ctrl + X exits nano .
- Run locale-gen .
- localectl set-locale LANG=en_US.UTF-8 . Make sure you replace en_US.UTF-8 with the locale you uncommented in step 3.
- hostnamectl set-hostname . Make sure you replace 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, replacing myhostname 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.
Part 3.1 — Enabling wheel group to run sudo
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 use vi , you can omit the EDITOR=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.
Part 3.2 — Creating a new user.
Now you want to create your user. In the steps below, replace your_username with your intended login username.
useradd -m -G wheel your_username
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 «» «» > /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 booting
- systemctl start wpa_supplicant@wlan0 to connect to Wi-Fi.
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