Bootstrap Arch on Raspberry Pi with only a Wifi dongle

Installing Arch on the Raspberry Pi is rather simple and well documented. There is an offline step, where you copy a base system on the SD card. Then, you place the card in the Raspberry Pi, boot it and you log into that new system somehow, to finish the configuration and start customizing. “Somehow” is either: you plug a keyboard and a screen to the Raspberry Pi and work within the console, or: you plug the Raspberry Pi to your router/computer through an Ethernet cable and log in over SSH. But what if all you have is a Wifi dongle?

Install Arch Linux on the SD Card

Let’s start with the basics. Download the Arch image for the Raspberry Pi and plug the SD card to your computer. You can follow the official installation instructions (under the “Installation” tab), but I propose a slightly different way of doing. I mount the boot partition at the right place before extracting, so that there is no need to move the boot files afterwards. For the sake of completeness, here is the modified procedure:

  1. Start fdisk to partition the SD card:
  2. At the fdisk prompt, delete old partitions and create a new one:
    • Type o. This will clear out any partitions on the drive.
    • Type p to list partitions. There should be no partitions left.
    • Type n, then p 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.
    • Type t, then c to set the first partition to type W95 FAT32 (LBA).
    • Type n, then p for primary, 2 for the second partition on the drive, and then press ENTER twice to accept the default first and last sector.
    • Write the partition table and exit by typing w.
  3. Create the file systems
  4. Mount the filesystems in the same hierarchy as they should be on the Pi
  5. Extract the base system
  6. Do not unmount yet!

Installing Required Packages

Moving on to something more interesting. We are going to prepare the system offline, so that it connects to the wifi network when booting. We will use netctl, which is already installed, but we will also need wpa_supplicant to access secure networks. Unfortunately, this package isn’t included by default and we must install it. For this, we need to configure pacman to operate on the SD card and use the proper mirrors and architecture. The easiest is to tweak the pacman.conf file of the Raspberry Pi. In the below instructions, I mounted the Pi’s root partition onto /tmp/root. Change this if yours is different.

Then, edit the file to change all the necessary paths and options [full file here]:

 

Now you can use pacman to install wpa_supplicant, using the modified configuration file.

My dongle — an Edimax USB dongle — works out-of-the-box (8192cu). However, if your dongle needs extra drivers, you can install the corresponding packages too, as long as they do not have an install script.

Configuring netctl

Step 1: the easy part. Well… kind of… Go to root/etc/netctl and copy one of the example profiles that suits your need. I will name the profile MyNet, you can replace this if you wish.

Then, edit the file to configure the network, like you normally would. Note that, at the moment, the Wifi interface still receives the traditional name wlan0, instead of  a typical persistent name from systemd (e.g. wlp2s0).

Step 2: the tricky part. Kind of… We need to enable this configuration, which is usually just the matter of a netctl enable MyNet. But without systemd running, we need to do the work by hand. Change to root/etc/systemd/system. There, create the file netctl@MyNet.service and place the following content inside

Finally, activate the service at boot. This is done by creating a symlink inside the directory that lists all the dependencies for the multi-user target:

Note: It isn’t a failure that the link path starts with /etc and points to nowhere on our host system. The symlink must point to the path as it will be on the target.

Now, you can unmount the card and boot your Raspberry Pi.

Finding The Pi

Of course, the easiest way to find your Pi, would be to have a proper internal DNS resolver. The default hostname is alarmpi, and you then just need to boot the Pi, wait a little and

If all you get is a ssh: Could not resolve hostname alarmpi: Name or service not known even after some time, then you’ll have to find the Pi’s IP address manually. Several methods are helpful there.

If you can log into your router, just call

to get the list of connected devices.

Else, you could catch the DHCP discovery call, when the Pi is booting, by listening to your Wifi using e.g. Wireshark.
RaspWiresharkDiscover

Finally, you could scan your network with nmap, but you will have to be clever, as the Pi is rather silent by default (somehow avoids nmap host discoveries).

You’re now just a ssh alarm@192.168.10.79 away from having fun!

Featured Image Credits: Sergey Pozhilov / FreeImages.com and the Raspberry Pi Logo