Setting up a Samba share on RaspberryPi for Networked Attached Storage

Follow the instructions below to set up a Samba share on Raspberry Pi, which can be read by both Windows and Linux platforms. In the following, I have an external HD attached at the root /media/Elements which I want to share on the network:

sudo apt-get update
sudo apt-get install samba

Edit the /etc/samba/smb.conf file to include information on your shared folders at the bottom of the file:
path = /media/Elements
writeable = yes
browseable = yes
valid users = pi

Now add a Samba password for the user pi:
sudo smbpasswd -a pi
sudo service samba restart

The share is now ready to access and can be added eg. as a network drive in Windows.

Setting up Media Player Daemon with a USB sound card and analogue speaker on the Cubox

This post describes how to wire up an analogue speaker connection (mini-jack) to your Cubox through an external USB sound card, and control play back of your music collection through client software on another networked device. The setup uses Media Player Daemon (MPD) on the server side, an analogue sound output device since the Cubox only has digital sound out (Dynamode 7 Channel USB 2.0 Sound Card (£2.89 incl. delivery) from Amazon (product link)) and Gnome Media Player Client on the client side to control your playlist etc. Audio playback in this case is handled by the Advanced Linux Sound Architecture (ALSA) project.

Install ALSA utils

sudo apt-get update
sudo apt-get install alsa-utils

Install Music Player Daemon

sudo apt-get install mpd sonata
sudo nano /etc/mpd.conf

Or use your favorite editor instead of nano to edit the config file. First set the server to your server IP (ie., not localhost or in my experience). Then you need to tell MPD where to find your music, the easiest way appears to be to mount your music dir within the MPD folder (to get the right permissions). Set the music directory to /var/lib/mpd/music/.

You will need to CHOWN the log file directory to avoid errors on startup:

sudo chown -R mpd /var/log/mpd/

Mount the root folder of your music collection:

sudo mount --bind /media/Elements/Music/ /var/lib/mpd/music/

(substitute /media/Elements/Music/ for your own music root path).

Configure MPD to use your USB sound card

When plugging in the USB sound card mentioned above and running dmesg the following output is given:

[321487.546702] usb 1-1.2: New USB device found, idVendor=0d8c, idProduct=000e
[321487.546723] usb 1-1.2: New USB device strings: Mfr=0, Product=1, SerialNumber=0
[321487.546739] usb 1-1.2: Product: Generic USB Audio Device
[321487.548578] usb 1-1.2: configuration #1 chosen from 1 choice
[321487.650097] input: CM109 USB driver as /devices/platform/orion-ehci.0/usb1/1-1/1-1.2/1-1.2:1.3/input/input3

To get a list of playback devices on your device and their names, use:

aplay -l

Which will give you something like this:

**** List of PLAYBACK Hardware Devices ****
card 0: mvi2s1 [mv_i2s1], device 0: CS42L51 CS42L51-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: default [Generic USB Audio Device ], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0

On my device, the “card 1” is the USB audio sound card, and we need to tell MPD this in the config file. First test that you can get sound output on the card with any sample wav file. “hw:1” tells aplay to use the “card 1” device from above:

aplay -D hw:1 /media/Elements/LRMonoPhase4.wav

Now edit /etc/mpd.conf and scroll down to the audio output section. Here you can add:

audio_output {
type "alsa"
name "My ALSA Device"
device "hw:1,0"
format "44100:16:2"
encoding "mp3" # if you're using a different encoding, you will have to change this

Fix distortion issue for mp3 playback

Playback of mp3 files will initially be distorted on the Cubox, as noted here. The solution below is taken from the same post, and requires you to compile and reinstall libmad:

sudo apt-get build-dep libmad
sudo apt-get install devscripts
apt-get source libmad
nano libmad-0.15.1b/debian/rules # add the line "CFLAGS +=-marm" after the first four comment lines
cd libmad-0.15.1b/
debuild -us -uc
cd ..
sudo dpkg -i libmad0_0.15.1b-4ubuntu1_armel.deb

And finally, restart the server. The server will by default listen on port 6600:

sudo mpd --kill
sudo mpd

Install Gnome Music Player Client

On your laptop (or from where ever you’re going to control your MPD server), install Gnome Music Player Client through the package manager. Connect to your MPD server and start playback!

Installing a Climax Digital (ITE Tech IT9135) USB DVB-T television tuner on the Cubox

The objective of this sub-project was to stream live TV channels from the Cubox to our mobile devices. The TVHeadEnd back-end is supported by the Cubox with no further drama (see instructions), the main challenge appeared to be finding a USB device that would install on the Cubox (and on the relatively dated kernel that comes with the Cubox XBMC installer, which I happen to be using). There are many relatively low cost standard definition TV tuners available on eBay and Amazon, I noticed the ClimaxDigital DTV200 USB2.0 tuner (£14 incl. delivery) from Amazon (product link) had a few success stories with Ubuntu Linux in the reviews and decided to give it a go.

When plugged in, lsusb outputs:

Bus 002 Device 008: ID 048d:9005 Integrated Technology Express, Inc.

which according to LinuxTV makes the device an ITE Tech IT9135, which has driver support from kernel 3.3 and upwards. Since this post is about kernel, there are a few things you need to do:

Download firmware (instructions from LinuxTV)

cd ~

Extract the file dvb-usb-it9135.fw to your home dir with your favourite archive tool. Then use the following command to extract the correct firmware file and place it in the correct location:

dd if=dvb-usb-it9135.fw ibs=1 skip=64 count=8128 of=dvb-usb-it9135-01.fw
sudo cp dvb-usb-it9135-01.fw /lib/firmware/

Get and compile V4L drivers (based on this LinuxTV page, this SolidRun forum post and this forum post)

For this step you should have the Linux sources available on your system before going forward.

cd ~
git clone git://
sudo apt-get install patchutils libproc-processtable-perl
zcat /proc/config.gz > /lib/modules/
cd /usr/src/linux-
make oldconfig
make prepare
make modules_prepare
cd ~/media_build
sudo make install

The V4L drivers should now be installed, and when you plug in your ClimaxDigital device and run dmesg you should get a bunch of messages telling you the firmware was loaded etc. Here is my output:

[   38.194934] usbcore: registered new interface driver dvb_usb_it913x
[   38.196702] it913x: Chip Version=01 Chip Type=9135
[   38.204693] it913x: Remote propriety (raw) mode
[   38.206702] it913x: Dual mode=0 Tuner Type=0
[   38.214702] usb 1-1.4: dvb_usb_v2: found a 'ITE 9135(9005) Generic' in cold $
[   38.214725] usb 1-1.4: firmware: requesting dvb-usb-it9135-01.fw
[   38.251965] usb 1-1.4: dvb_usb_v2: downloading firmware from file 'dvb-usb-i$
[   38.254708] it913x: FRM Starting Firmware Download
[   38.826689] it913x: FRM Firmware Download Completed - Resetting Device
[   38.866689] it913x: Chip Version=01 Chip Type=9135
[   38.868688] it913x: Firmware Version 204869120
[   38.948700] usb 1-1.4: dvb_usb_v2: found a 'ITE 9135(9005) Generic' in warm $
[   38.954629] usb 1-1.4: dvb_usb_v2: will use the device's hardware PID filter$
[   38.960324] DVB: registering new adapter (ITE 9135(9005) Generic)
[   39.021687] it913x-fe: ADF table value       :00
[   39.041686] it913x-fe: Crystal Frequency :12000000 Adc Frequency :20250000 A$
[   39.257688] it913x-fe: Tuner LNA type :38
[   39.505697] usb 1-1.4: DVB: registering adapter 0 frontend 0 (ITE 9135(9005)$
[   39.562901] Registered IR keymap rc-it913x-v2
[   39.563295] input: ITE 9135(9005) Generic as /devices/platform/orion-ehci.0/$
[   39.563490] rc0: ITE 9135(9005) Generic as /devices/platform/orion-ehci.0/us$
[   39.563511] usb 1-1.4: dvb_usb_v2: schedule remote query interval to 250 mse$
[   39.563531] usb 1-1.4: dvb_usb_v2: 'ITE 9135(9005) Generic' successfully ini$

In total, the source and compiled modules will take up around 440Mb of space.

Using this device with the TVHeadEnd back-end (and a wired aerial rather than the supplied mini aerial) I have been able to stream standard definition TV channels from the Cubox over our home wifi to Android devices using MX Player in combination with TVHGuide (not available on Google Play) which shows you the full electronic programme guide and directs the correct stream to MX Player.

Compiling MediaTomb UPnP server on the Cubox to stream DVD ISO files by chapter/section

A UPnP (Universal Plug-n-Play) server will announce its presence on your local network and allow media files to be streamed to any device running a UPnP browser/player (such as MediaHouse browser for Android, which I’m using). Out of the box, the MediaTomb UPnP server will stream most types of standard media files without problems, but there is no direct way of interacting with the DVD menu from the UPnP browser. While you can use an external program like VLC to stream the MPEG contents of an ISO, if you want to be able to play different sections of the ISO (for us that means mostly playing different episodes of television series) you will have to use MediaTomb’s scripting ability – which is inactive in the version you will get using apt-get.

The feature to activate is MediaTomb’s integrated JavaScript engine, which allows you to break down ISO files into different “virtual objects”, each representing a section (or language etc) of the ISO, which you can then play directly in your UPnP browser/player. To enable scripting, you need to compile MediaTomb with support for libjs. The instructions here are a combination of information found on Richard Appleby’s blog, Ebixio and a bit of trial-and-error:

sudo apt-get update
sudo apt-get build-dep mediatomb
cd ~
apt-get source mediatomb
nano mediatomb-0.12.0~svn2018/debian/rules
# or use your favorite editor. The version you just downloaded may also be different

In the file, search for MEDIATOMB_CONFIG_OPTIONS and change --disable-libjs to --enable-libjs. Change --disable-libdvdnav to --enable-libdvdnav and add --enable-libdvdread

You will also need a JavaScript interpreter for ARM (here SpiderMonkey which depends on libmozjs0d and libreadline5):

sudo apt-get install libreadline5
sudo wget
# from Launchpad

dpkg -i libmozjs0d_1.8.1.16+nobinonly-0ubuntu1_armel.deb
sudo wget
# from Launchpad

sudo dpkg -i spidermonkey-bin_1.8.1.16+nobinonly-0ubuntu1_armel.deb

You will also need the packages libmozjs-dev and libdvdnav-dev:

sudo nano /etc/apt/sources.list

Add this line to the bottom

deb squeeze/updates main

And continue with the packages:

sudo apt-get update
sudo apt-get install libmozjs-dev
sudo apt-get install libdvdnav-dev
# this will also install libdvdread-dev

Now, typing in sudo mediatomb-0.12.0~svn2018/.configure will go through all the compile options and everything should be fine at this point. The following will compile three .deb files which you can subsequently install (time for coffee at this point while your Cubox chews through the code):

cd mediatomb-0.12.0~svn2018
sudo dpkg-buildpackage -rfakeroot -us -uc

The following will prevent your custom MediaTomb from being overwritten when you update your software:

sudo su
echo mediatomb hold | dpkg --set-selections
echo mediatomb-common hold | dpkg --set-selections
echo mediatomb-daemon hold | dpkg --set-selections
echo libmozjs2d hold | dpkg --set-selections
echo libmozjs-dev hold | dpkg --set-selections

press Ctrl-D to exit super-user mode.

I then had to install some Firefox/IceWeasel components to continue (not sure why, you can try without and see what happens):

sudo apt-get install libjs-prototype iceweasel firefox
sudo apt-get -f install
sudo apt-get install firefox

Finally, install the three .deb packages created by the compile process earlier:

cd ..
sudo dpkg -i mediatomb*.deb

The last steps are to install the packages MediaTomb needs to read and understand the DVD structure:

sudo apt-get install libdvdread4
sudo apt-get install libdvdnav4

– and finally to tell the config file to parse DVD ISO images using the JavaScript engine (there is a sample script file with the MediaTomb distribution which works quite well, but you can also customise the script to suit your needs):

in ~/.mediatomb/config.xml replace:

<virtual-layout type="builtin"/>


<virtual-layout type="js">

Under the tag <mimetype-contenttype> add:

<treat mimetype="application/x-iso9660-image" as="dvd"/>

Start the program with mediatomb --daemon, use your browser to navigate to http://your.server.ip:49152 and use the web interface to add your media file directories. When this is done (can take a while for ISO files) you can happily stream all your content to your favorite UPnP browser.

An always-on home theatre PC (HTPC), media server, backup server and Network Attached Storage (NAS)

 — in less power than a good lightbulb?

This post (and indeed, this entire blog) came about when thinking about how to have an always-on server in my home that could satisfy a huge list of demands (below). Though there’s nothing revolutionary about putting all these bits together, this post might serve as inspiration for someone looking to do something similar – and just to let you know it’s possible!

My list of demands for the server were:

  • Always on, without any noise and with low power consumption (preferably less than 10W, that of a decent green light bulb)
  • Act as a fileserver on my home network (NAS) for Windows and Linux users
  • Constantly backup all my files from the NAS to a remote destination
  • Run a nice looking HTPC type software, such as XBMC, to be able to view our DVD collection (in ISO image format) on our LCD TV
  • Stream DVD ISO files from the NAS to any device on the network (laptops, game consoles, android phones, iPhones)
  • Play music through an attached Bose speaker (originally an MP3 dock, but which has an analogue [mini-jack] input)
  • Be able to stream live TV channels (FreeView in the UK) from aerial to the network
  • Not too expensive or laborious to build! (preferably less than £150)

Is there a way? Indeed there is. After spending a little time exploring types of “mini” computers available (including the GuruPlug, Raspberry Pi, Pandaboard, Cubox and others), I settled on the Cubox which has a decent processor (800MhZ), hardware MPEG decoding, a full 1GB of RAM and HDMI output (as well as a load of other features).

The server is now running smoothly with all open-source software:

  • Ubuntu 10.04 Linux OS (in a flavour with XBMC already installed by the Cubox developers)
  • Mediatomb UPnP server (for streaming DVD ISO movie files to other devices)
  • Crashplan remote backup solution (there is a free option with limited disk space, but paid plans are very reasonable)
  • Music Player Daemon to play MP3 files from the server on attached speakers
  • TVHeadEnd to serve live TV channels from aerial to the network

Apart from the Cubox itself, a couple of inexpensive bits were needed for my particular setup:

  • A DVB TV tuner: I’m using ClimaxDigital DTV200 USB2.0 tuner (£14 incl. delivery) from Amazon (product link)
  • An analogue sound output device (since the Cubox only has digital sound out): Dynamode 7 Channel USB 2.0 Sound Card (£2.89 incl. delivery) from Amazon (product link)
  • An external hard drive for storage (any one compatible with Linux will do, I’m using a Western Digital 2.0TB Elements drive, which is formatted with NTFS [windows])
  • A USB hub to connect everything up (since there’s only two USB slots in the Cubox)

Over the coming weeks, life allowing, I will be posting the sometimes dreadful hoops I had to jump through to get everything working, which mostly means compiling open source software directly on the Cubox and enabling various options that have been disabled in the repository versions. In the mean time, if you need instructions for any particular software listed above, feel free to leave a comment and I will post a quick-and-dirty guide which should get you through.

NOTE: The Music Player Daemon so far has only been tested with sound output over HDMI, since I’m waiting for the USB sound card to arrive in the post. 

Another NOTE: while Cubox does work reasonably well with XBMC (there are several installations to choose from, including GeexBox and XilkaX, see here), there does not seem to be much active development around XBMC for this device, and the current Ubuntu 10.04 based installation is somewhat unstable. If you want a device mainly for an XBMC HTPC, and you’re not really interested in porting XBMC yourself, you might be better off looking at Raspberry Pi which has had some support from the XBMC community.