I’ve had my Raspberry Pi for a few weeks now, but work is keeping me busy (in a good way) so I’ve only just found time to put this together.
It’s an approximate overview of the steps I took to set mine up for use as:
- A cheap and efficient general purpose Linux box;
- Specialising the above for audio streaming use, both;
- Playing audio from the Pi itself; and
- Streaming audio to the Pi from a separate Windows or Linux box (e.g. a laptop that you wish to be able to roam your house with, without being limited to laptop speakers. Essentially a poor man’s AirDAC).
- Specialising the above for audio streaming use, both;
If you can’t use vim just substitute nano in for vim in all commands that use it. Or your favourite editor. And skip any steps you don’t want. It’s not an authoritative guide, more like a recipe scribbled on the back of an envelope in the hope that one or two of the less obvious steps might save others some time.
I haven’t (yet) included steps for changing the default user name and password, or for setting up SSH keys, so the recipe assumes you are running the Pi on a trusted LAN. But these steps are no different on the Pi as they are from on any other Linux system anyway, so if you don’t already know how to, Google is your friend.
Setup for efficient Headless Operation
- Download the Debian image from https://www.raspberrypi.org/downloads/
- Flash it to your SD card.
- Boot up the Raspberry Pi.
-
Log in, start SSH, and enable it on boot:
sudo service ssh start; sudo update-rc.d ssh defaults
- If you wish, you can now disconnect the keyboard and screen that you used to get this far and continue using SSH from your laptop/desktop/phone. Use
ifconfig
to view the Pi’s IP address. -
Update the system:
sudo apt-get update; sudo apt-get upgrade; sudo apt-get dist-upgrade
-
Install Byobu:
sudo apt-get install byobu
-
Make Byobu start at login –
byobu-config
– toggle the bottom option.
-
Start Byobu now:
byobu
-
Install Vim:
sudo apt-get install vim
-
Edit
/boot/config.txt
–sudo vim /boot/config.txt
– adding these lines:
hdmi_force_hotplug=1 disable_overscan=1
The latter was required in order for my Pi to fill the entire screen (Iiyama ProLite B2712HDS). The former ensures that I don’t have to reboot it in order to use a screen if/when I plug one in (since most of the time it is headless). See http://elinux.org/RPi_config.txt for more options.
-
Delete the swap partition using:
sudo fdisk -uc /dev/mmcblk0
Then delete the root partition and recreate it using the same start location, but allowing it to occupy the entire card. See http://elsmorian.com/post/23366148056/basic-raspberry-pi-setup?438b7020 for more detailed instructions.
-
Having saved the partition changes, reboot:
sudo reboot
-
Log back in once rebooted and resize the root filesystem to occupy the entire partition (i.e. the entire card, sans boot):
sudo resize2fs /dev/mmcblk0p2
-
Create a swapfile:
sudo dd if=/dev/zero of=/var/swapfile bs=1M count=128 sudo mkswap /var/swapfile sudo swapon /var/swapfile
Edit fstab to turn off access time writes and to enable use of the swap file on boot –
sudo vim /etc/fstab
– delete the line starting with a hash (#), and paste in its place:
/dev/mmcblk0p2 / ext4 defaults,noatime,nodiratime 0 0 /var/swapfile none swap sw 0 0
Then reboot to make the changes take effect:
sudo reboot
-
The Pi’s 256MB RAM is shared between the CPU and GPU, by default 50:50. Since we are using it headless the GPU is unused. We can therefore change this allocation giving more RAM to the CPU. To view the current CPU allocation:
free
To steal some memory back from the GPU (look at what other *.elf files you have in
/boot
to see your other options):cd /boot sudo cp arm192_start.elf start.elf sudo sync sudo sync sudo reboot
To view the new CPU allocation:
free
-
Change the hostname:
sudo vim /etc/hostname sudo vim /etc/hosts
(in the hosts file replace raspberry with your chosen hostname).
-
Install molly-guard to prevent accidental power operations:
sudo apt-get install molly-guard
Configure molly-guard to always check (as we are using Byobu it will not detect the SSH session, which is what the default configuration tries to do) –
sudo vim /etc/molly-guard/rc
– uncomment this line:
ALWAYS_QUERY_HOSTNAME=true
Setup as an Audio Server
-
The kernel does not load the onboard sound driver by default, so force it to:
sudo modprobe snd-bcm2835
-
To ensure the module is loaded on every boot, do –
sudo vim /etc/modules
– adding the line
snd-bcm2835
-
Install ALSA:
sudo apt-get install alsa
-
Test the soundcard:
speaker-test -c 2 -t wav
-
Install VLC:
sudo apt-get install vlc
-
Stream some audio:
wget http://www.example.com/radiostation.pls; cvlc playlist.pls
-
Install Pulseaudio:
sudo apt-get install pulseaudio pulseaudio-module-zeroconf
-
Configure Pulseaudio to accept audio from remote clients –
sudo vim /etc/pulse/default.pa
– adding these lines:
load-module module-native-protocol-tcp auth-anonymous=1 load-module module-zeroconf-publish
-
If you have a USB soundcard and you want to use it as th default device –
sudo vi /etc/modprobe.d/alsa-base.conf
– replace
options snd-usb-audio index=-2
with
options snd-usb-audio index=0
-
Start Pulseaudio
pulseaudio --start
If you wish for Pulseaudio to always be available from boot without logging in and manually starting it, take a look at http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/SystemWide/
-
To stream sound via the server from a Linux client if zeroconf is not working, do:
pacmd load-module module-tunnel-sink server=
To stream sound from Windows you will need Virtual Audio Cable and LineInCode – use LineInCode to cat the sound from the virtual microphone provided by VAC into an SSH session which in turn pipes the sound to pacat on the Pi –
linco.exe -B 16 -C 2 -R 44100 | ssh.exe "cat - | pacat --playback"
– you’ll find this more convenient if you have already setup passwordless login from the Windows box to the Pi. Automate this as a script that runs on start-up if you wish, and to switch between local speakers and Pi-Fi just toggle the default sound device in Windows between the virtual speakers provided by VAC and your local speakers.
-
Consider buying a case from https://www.modmypi.com/. I haven’t yet, but am tempted.