In this article, I will guide you through the process of installing and configuring Archlinux ARM on a Raspberry PI and preparing it for headless usage.
Note that the guide will be oriented to medium to advanced UNIX users, and is expected that you have a working system with some basic tools such as Git and SSH.
Install & Configure Archlinux ARM
The first step is, of course, to download the image from the official sources. It should look something like
archlinux-hf-[build-date].zip. Extract this file and move it to an easily accessible directory.
Now you should open a terminal and navigate to the directory that contains the image file. We want to install this image into our SD card, but first we must properly identify the SD device. For example, in my case, it is mapped to
/dev/sdb. If you are not sure about which identifier corresponds to your device, you can run this command after introducing your card:
dmesg | tail -n 10
We will proceed now to install the image using the
dd tool. Note that you should be careful to choose the device identifier
/dev/sdb and not a partition contained inside of it
/dev/sdb1. You may need root privileges to do this operation, and please, be extra careful to choose the right identifier, you can mess up your whole system make a mistake in this step:
dd bs=1M if=archlinux-hf-[build-date].img of=/dev/sdb
Wait a little bit and you will soon have your card ready to boot. But before we start our Raspberry Pi we are going to configure it from our very own system, thus being headless through the whole installation process.
Yeah, we are going to run Arch Linux ARM inside our own distribution, how cool is that?
Configuring Archlinux ARM from your own computer
To log in to our newly installed system from your UNIX distribution we will use a little bit of
chroot magic. But first, we need to make the necessary arrangements to be able to run ARM files from our own architecture. To do this, we are going to use qemu.
Note that this process is completely optional, you can boot the SD card from a Raspberry Pi and start configuring your system right away. Unfortunately, I don’t have a monitor or TV that supports RCA/HDMI video at the moment. So I have to hack this solution.
Emulating the ARM architecture
Assuming you are using a Debian compatible distribution we will install the following packages:
apt-get install qemu binfmt-support qemu-user-static
You should be able to see some lines that associate qemu-arm-static with your architecture:
update-binfmts --display | grep arm
Now we will install the C library that will allow us to run dynamically linked binaries:
apt-get install libc6-dev-armhf-armel-cross
In case you are running Archlinux as the host OS, you must first install qemu from the official repositories:
pacman -S qemu
If you are able to run ARM compiled executables you are good to go. To test this, you check this website, where you can learn to compile and test a simple ARM program using qemu
Starting the Chroot environment
The next thing that we want to do is to mount our newly installed Arch Linux system from the SD card to our host PC.
mkdir /mnt/archarm mount /dev/sdb2 /mnt/archarm
Then, we will copy the arm emulator to the path registered by binfmt-support.
cp /usr/bin/qemu-arm-static /mnt/archarm/usr/bin
We will continue by mounting the different paths required by the chroot environment and copying the appropriate files to have internet inside of it.
cd /mnt/archarm mount -t proc proc proc/ mount -t sysfs sys sys/ mount -o bind /dev dev/ mount -t devpts pts dev/pts/ cp -L /etc/resolv.conf etc/resolv.conf
Lastly, we will change our root to this directory and we will be set to start updating and configuring our system.
chroot /mnt/arch /bin/bash
In case your main system is Arch, you can just use
arch-chroot if you have arch-install-scripts installed.
cd /mnt/archarm arch-chroot .
Updating the system and installing SSH
Once you are inside the chroot, the first thing you have to do is to change your root password issuing this command:
Next, you will have to edit the
/etc/pacman.conf file to disable the
CheckSpace option, as this causes problems when using Pacman from inside a chroot environment. Just comment it out and you will be able to upgrade your system with:
Pacman is Arch Linux’s package manager, and it is pretty awesome. If you are not familiar with it, you can always check the man pages or look for some info in the community wiki. The line above will fetch an updated package list and try to upgrade all installed programs.
We will proceed now to install and configure SSH. First of all, we have to make sure that it is installed
pacman -S openssh
Next, we will make sure that nobody can connect as root using ssh. To do this, open
/etc/ssh/sshd_config with your favourite console editor and change this:
To further improve the security of your ssh connections it would be better to change the listening port from 22 to some random number. Nevertheless, we will left this as is for simplicity.
Of course, after the above, if we don’t create an user we won’t be able to access our Raspberry Pi via SSH, so let’s get to it:
useradd -m -g users -G wheel -s /bin/bash [username] passwd [username]
Once we have our user prepared, we are ready to enable the ssh daemon:
systemctl enable sshd.service
But this is worthless if we can’t determine the IP of our Raspberry Pi, for this reason, we will assign it an static IP address. To do so, we will use netctl, but since the process is perfectly explained in the wiki, we are not going to explain it further.
Once everything is properly configured, you can exit the chroot and unmount the SD.
exit umount -l /dev/sdb2 sync
If you did everything right, you should now be able to insert your card on the Raspberry Pi, power it up, and try to connect to it through ssh:
Once you check that the connection works, it would be a good idea to create a pair of ssh keys, so that you can authenticate without entering your password. You can find more information about this here.