Skip to content

Instantly share code, notes, and snippets.

@TheZoc
Last active October 13, 2024 18:02
Show Gist options
  • Save TheZoc/849a82d3eed219998cd82fb4040607ae to your computer and use it in GitHub Desktop.
Save TheZoc/849a82d3eed219998cd82fb4040607ae to your computer and use it in GitHub Desktop.
This is a guide to setup Arch Linux in Raspberry Pi 4, using macOS as the auxiliary system.

Raspberry Pi Setup Guide

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.

What you will need

  • 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.

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

  1. Insert the microSD card in the USB reader, and insert the reader in your mac. Again: Do NOT use the built in SD reader!
  2. 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".
  3. 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!
  4. Unmount the volumes using Disk Utility. Do NOT eject the device, only unmount the volumes. They will appear greyed out after unmounting.
  5. sudo fdisk -i /dev/disk2. This will initialize a new MBR on your microSD. This will destroy all data!
  6. sudo fdisk -e /dev/disk2. This will enter fdisk in "edit in interactive mode".
  7. 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
  1. Type erase and press enter.
  2. Type write and press enter.
  3. Type print and press enter. This should give you the table displayed in step 7.
  4. Type quit and press enter.
  5. Here, we're done with the fdisk step. If you're coming from step 7, this is the right step to proceed on.
  6. 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.
  7. 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.
  8. Download the version you want to run in your Raspberry pi to your favourite directory. In my exampe, I downloaded it to ~/Downloads.
  9. 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 :)
  10. cd /Volumes/root
  11. 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.
  12. sudo mv boot/* ../boot
  13. sudo sync
  14. If you decided to download AArch64 version, you need to run this command:
sudo sed -i 's/mmcblk0/mmcblk1/g' etc/fstab
  1. Eject the devide using Disk Utility.

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.

  1. Get the necessary tools to partition and format the microSD card:
pacman -S sudo
pacman -S dosfstools
  1. Use lsblk to check the storage devices currently attached to the system.
  2. Insert the microSD card in the USB reader, and insert the reader in your system.
  3. 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.
  4. Use sudo fdisk /dev/sda to start partitioning the card. Be sure to use the correct device from step 4 before proceeding!
  5. 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.
  6. Type o - This will clear out any partitions on the device.
  7. Type p - This will show the current partitions on the device. There should be no partitions left.
  8. 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 +512M for the last sector.
  9. If after you're done with the step 9 it asks about removing a signature, confirm it with y.
  10. Type t to change the partition type, then type c to change the first partition type to W95 FAT32 (LBA).
  11. 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.
  12. If after you're done with the step 12 it asks about removing a signature, confirm it with y.
  13. Type w to write the partition table and exit.
  14. Your microSD card is now partitioned.
  15. Format the partitions. Remember to use the correct device from step 4!
mkfs.vfat /dev/sda1
mkfs.ext4 /dev/sda2
  1. cd /mnt. Depending on your distro, this could be cd /mount
  2. 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
  1. Selected the version you want for your RaspberryPI and use wget to download it.
wget http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-aarch64-latest.tar.gz
  1. 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
  1. mv boot/* ../boot
  2. sync
  3. If you decided to download AArch64 version, you need to run this command:
sed -i 's/mmcblk0/mmcblk1/g' etc/fstab
  1. cd ..
  2. umount boot root
  3. rmdir boot root

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:

  1. 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.
  2. 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.
  3. 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.
  4. If this is your first time using nano, Ctrl + O saves the file and Ctrl + X exits nano.
  5. Run locale-gen.
  6. localectl set-locale LANG=en_US.UTF-8. Make sure you replace en_US.UTF-8 with the locale you uncommented in step 3.
  7. 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 ;)
  8. 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
  1. (Optional) Add color to pacman output: sed -i 's/#Color/Color/' /etc/pacman.conf
  2. 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:

  1. pacman-key --init
  2. pacman-key --populate archlinuxarm
  3. pacman -Syu
  4. This could take a few minutes, depending on how much you have to update. Go get coffee :)
  5. Once it is done, run reboot and you're ready to go!

Part 3: User setup

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.

  1. pacman -S sudo
  2. EDITOR=nano visudo. If you know how to use vi, you can omit the EDITOR=nano part.
  3. Search for the line %wheel ALL=(ALL) ALL and uncomment it (i.e. delete the # from the start of the line.)
  4. 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.

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!

Wi-Fi Setup

karog, on ArchLinux ARM forums provided a simple way to connect to Wi-Fi. As root, do the following steps:

  1. nano /etc/systemd/network/wlan0.network to configure the wlan0 interface:
  2. Add the following contents to the file:
[Match]
Name=wlan0

[Network]
DHCP=yes
  1. wpa_passphrase "<SSID>" "<PASSWORD>" > /etc/wpa_supplicant/wpa_supplicant-wlan0.conf. Replace and with your respective Wi-Fi network name and password.
  2. systemctl enable wpa_supplicant@wlan0 to enable the Wi-Fi when booting
  3. systemctl 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):

  1. systemctl stop wpa_supplicant@wlan0
  2. systemctl disable wpa_supplicant@wlan0
  3. rm /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
  4. rm /etc/systemd/network/wlan0.network
@emzxcv
Copy link

emzxcv commented Jul 22, 2024

I still can't seem to get it working...
I am getting an error like PARTUUID="" not found.

etc/fstab looks like this and i used the aarch64.

# <file system> <dir> <type> <options> <dump> <pass>
/dev/mmcblk1p1  /boot   vfat    defaults        0       0

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