Installing ArchLinux on Raspberry Pi for headless audio

distributor-logo-archlinux-1

Since I’m re-doing a fresh install of a SD card on my Raspberry Pi, I thought I’d document the process as I go, in case it is useful for other people (or for my future reference in the most likely case we’re I’ll screw my current SD). I”ve chosen to use ArchLinux over Raspbian because it boots faster and has a smaller footprint. Since I’m mainly interested in using the Raspberry pi headless – without any screen or keyboard attached – it makes sense to have a reduced system to start with. On my current SD, it takes about 10 seconds to boot into the app of my choice, that’s way better than bringing any of my computer back from sleep and firing the equivalent app.

Important note 1: As always, this is heavily time dependent and I can’t guarantee the exactness of this post at any other future dates.

Important note 2: When you changes files on the Rpi and need to reboot, don’t plug the power out. You have a lot of chances files where not committed to the SD yet and all your edits will be lost

1 – Build a SD card

The steps are explained over here, in the installation tab. It’s the pretty standard “download the image and do a SD card dump” procedure. Under linux, use dd. With Windows, you will need Win32DiskImager. Once the image is done, remove it from you computer, stick it into the Rpi’s SD slot and boot it up. The image is setup to use DHCP, so if you you can simply power the Rpi connected to an ethernet cable and – provided you can find its ip –  you can directly ssh to it. Otherwise, you will need to connect it to a screen and keyboard and login that way. The default username/password of the image is ‘root’ / ‘root’. The default hostname is ‘alarmpi’.

2 – Setup the package manager

Since you will need to install some additional libraries / packages, it’s a good idea to setup archlinux’s package manager, cutely named ‘pacman’. You can find information about the process over here (look for update system). You can update the system too if you want, nothing wrong with getting the latest while we’re setting up.
The steps I’ve followed are:

  1. Create a pacman key:

    # pacman-key –init

  2. Update the system (this will take a while):

    # pacman -Syu

  3. Reboot

    # reboot –reboot

3 – Adding packages

Now you need to find and install packages that are missing. You can look for packages through keywords using

# pacman -Ss keyword

And install them using

# pacman -S keyword

In my case I ended needing was sdl, alsa and jack:

# pacman -S sdl
# pacman -S alsa-utils
# pacman -S jack

4 – Testing usb midi/audio

In theory, you don’t really need to execute this step (since everything should work smoothly) but I always like to double check things:

Connect a USB audio device then type

# aplay -l

You should see an entry both for the internal audio device (bcm2835) and USB audio.

card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 2: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0

Then plug in a MIDI device and see if alsa recognises it:

#  aconnect -o

client 14: ‘Midi Through’ [type=kernel]
0 ‘Midi Through Port-0’
client 20: ‘Launchpad’ [type=kernel]
0 ‘Launchpad MIDI 1’

5 – Removing the default pi audio output

Since the built-in audio out of the raspberry pi is only good for deaf people, it makes sense to remove it. Raspbian has a sysem that makes any usb audio the default one but arch linux doesn’t. Since we want it to work with anything we would plug into it, we’ll just get rid of the bcm2835 so it doesn’t get in our way. To do so, edit the file /etc/modules-load.d/raspberrypi.conf and remove / comment the bcm2835 related modules (bcm2708-rng, snd-bcm2835)

6 – Autobooting

If we want to use our raspberry pi as a headless sound device, it’d be nice to get it to start some programs automatically at boot time. So far, the easiest way I’ve found is to use crontab.

Crontab has a special syntax that allow some command to be executed at boot time. So we’ll create a shell script in our root folder and get cron to execute it everytime we restart the Rpi. If we want to change the start sequence later, we simply need to update the shell script.

Start by editing root’s crontab:

# crontab -e

And add the following line:

@reboot /root/autostart.sh > /root/autostart.log 2>&1

which tells to execute a shell script – autostart.sh – located in the root home and to log all output from it into autostart.log

Now go in the root folder (cd /root) and create autostart.sh containing, for example, the following:

echo “hello world”
exit 0

Make sure the autostart.sh is executable by

# chmod a+x autostart.sh

And reboot the rpi:

# reboot –reboot

When you reconnect to the Rpi, the root folder should now have a file autostart.log containing

hello world

Bingo ! Now we can start any favorite program to start at boot time !

1 comments

  1. Thanks for the very good step-by-step manual. It saved my day. Very easy to handle, especially for beginners (8 hours linux) like me. These helpful basics are hardly to find in the net (maybe too simple for advanced linux- users to write it in so detailed).

Leave a Reply

Your email address will not be published. Required fields are marked *