Arch, Raspberry PI, MPD, DAC = Hi-Fi
Yesterday I setup a headless Raspberry PI Arch based MPD server. It was a breeze (for me) and I thought I’d like to share the procedure with you guys. If you intend to use a Debian image the guide below will not work without adapting the configuration for Debian – other guides cover this.
96Khz and 192Khz 24bit files work flawlessly.
Resources:
http://www.musicpd.org/
http://www.raspberrypi.org/downloads/
https://wiki.archlinux.org/
https://wiki.archlinux.org/index.php/Autofs
Hardware
- Raspberry PI Model B
- Edimax ew-7811un wireless usb dongle
- Powered USB hub (mine is 7 port logik brand)
- External USB Storage for music (or smb/nfs mount)
- External USB DAC (Mine is Cambridge Audio DacMagic Plus)
- 2 GB SD card (I use a 4 GB, which more than is needed)
For:
- Remotely controlled via smart phone
- Headless aka screenless
- Does not hurt too much budget wise
Against:
- Moderate command line profiency is needed
- Access to Linux command line is presumed
Guide
- Get Arch linux image here: http://www.raspberrypi.org/downloads/
- Write image to SD card:
- Linux
http://www.raspberrypi.org/documentation/installation/installing-images/linux.mdsudo dd if=ArchLinuxARM-<current-version>-rpi.img bs=1M of=/dev/mmcblk0u
- Windows:
http://www.raspberrypi.org/documentation/installation/installing-images/windows.md - Mac:
http://www.raspberrypi.org/documentation/installation/installing-images/mac.md
- Linux
- Before booting the Pi the first time it will be helpful to configure wireless using netctl so the machine can be accessed via ssh.
sudo mount /dev/mmcblk0p5 /mnt cd /mnt/etc/netctl sudo vi wlan0-pi-conf
Paste and adapt the following configuration to fit your needs:
Description='Wireless network for my MPD Pi' Interface=wlan0 Connection=wireless Security=wpa ESSID=<your-ssid> IP=dhcp Key=<your-wlan-password>
Save file and cd away from dir.
Activate profile:
sudo ln -s /usr/lib/systemd/system/netctl-auto@.service /mnt/etc/systemd/system/multi-user.target.wants/netctl-auto@wlan0.service sudo umount /mnt
- Transfer SD card to you PI and turn on power. Watch the wireless dongle to check for activity.
- Scan your network to identify with nmap (adjust ip-range to match your local network):
nmap -sP 192.168.0.1-20
- ssh to the alarmpi.
ssh -l root <alarmpi ip>
password is root. - Update system:
Adjust /etc/pacman.d/mirrorlist to a country near you.
Update system:
pacman -Syu reboot
ssh back in to system after reboot. - Install mpd and mpc:
pacman -S mpd mpc alsa-utils
Edit mpd.conf so it looks like this:
user "mpd" pid_file "/run/mpd/mpd.pid" db_file "/var/lib/mpd/mpd.db" state_file "/var/lib/mpd/mpdstate" playlist_directory "/var/lib/mpd/playlists" music_directory "/media" mixer_type "software" audio_output { type "alsa" name "Cambridge Audio USB Audio 2.0" device "hw:1,0" }
Create media dir
mkdir /media
You need to adjust audio_output variables to fit your external DAC and adjust music_directory to where you store your music.
Read mpd.conf man page for more information on the variables.
Since mpd will run as mpd change ownership of the mpd dirs:
chown -R mpd /var/lib/mpd systemctl enable mpd systemctl start mpd
Check for errors:
journalctl -xn
- I've found that autofs is the most reliable solution for removable storage:
pacman -S autofs echo "automount: files" >> /etc/nsswitch.conf echo "/- /etc/autofs/auto.rpi" >> /etc/autofs/auto.master echo "/media/musik -fstype=ext4,async,nodev,nosuid :/dev/sda1" >> /etc/autofs/auto.rpi
Enable autofs and cd to dir:
systemctl enable autofs && systemctl start autofs cd /media/musik df -h
- Set /etc/localtime and setup ntpd (adjust zoneinfo link to your needs):
rm /etc/localtime && ln -s /usr/share/zoneinfo/Europe/Copenhagen /etc/localtime systemctl enable systemd-timesyncd && systemctl start systemd-timesyncd
- Install mpdroid or similar app on your phone. Point the app to the ip of your rpi.
Bonus info:
You can add radio channel streams to mpd’s playlists. I’ve only tried m3u links.
Example for Danish Radio’s Jazz station:
wget http://live-icy.gss.dr.dk/A/A22H.mp3.m3u && mpc load A22H.mp3.m3u
Enjoy. If you have any questions please ask.