Selasa, Desember 02, 2014

How to Build DLNA Server using Raspberry Pi & Time Capsule

Basically, you can build a DLNA server just using Raspberry Pi and external hard drive which contains your multimedia contents (movies, music, and pictures). Just plug the external hard drive to the Pi’s USB port, and you can just use Raspbmc OS or install other package which support DLNA server like minidlna.

My previous setup was using Raspberry Pi + Raspbian + minidlna + external USB hard drive, it’s working great. But there is some limitation when I use this setup:
  • Raspberry Pi does not use gigabit ethernet, it uses 100Mbps ethernet. So theoritically, the maximum transfer speed is around 12.5 MB/s when you’re copying content from your PC to Raspberry Pi and vice versa.
  • Raspbian use ext4 filesystem natively. So when you use other filesystem such as NTFS for your external hard drive, the read/write performance is degraded significantly. Based on my experience, when I use ext4 partition I can achieve transfer speed up to around 9 MB/s when copying large file from my Mac to Raspberry Pi. The speed drops to around 3 MB/s when I use NTFS filesystem.
  • I use Mac and I need my external hard drive also accessible when I plug it directly into my Mac. So for this reason, if I use ext4 for my external hard drive, it will be inaccessible by my Mac (there are several third party software such as Paragon ExtFS which support read/write operation to ext4 filesystem. But just imagine somehow your external hard drive failed working. It will be a nightmare to rescue your data while your Mac does not support ext4 natively)
  • I intend to use my external hard drive to store not only my multimedia collection, but other documents and data as well. So the data transfer operation between my Mac and Raspberry will be done quite frequently. Considering the Raspberry Pi’s maximum transfer rate is only around 9MB/s, it’s not suitable for day-to-day operation.

I decided to use my Time Capsule to store my documents and multimedia collections. I can plug my external hard drive to my Time Capsule’s USB port to give me additional storage. There’s some advantages when I use this setup:
  • I take benefit from Time Capsule’s gigabit ethernet for faster transfer rate, and Raspberry Pi’s capability to provide DLNA server from Time Capsule internal and external storage. Transfer rate is much faster compared to Raspberry Pi. Based on my experience, I can transfer file to Time Capsule’s internal hard drive with speed up to 45 MB/s, where copying file to external hard drive (plugged into Time Capsule’s USB port) only get speed around 30 MB/s (I guess it’s because Time Capsule use USB 2.0 port). 
  • Time Capsule uses HFS+ filesystem, so the external hard drive need to be formatted into HFS+ filesystem to be recognized by Time Capsule. However, HFS+ is used and supported by Mac natively. Therefore, I can directly plug my external hard drive to my Mac without any dependency to Time Capsule (Consider if I use ext4 filesystem on my hard drive, I have dependency to my Raspberry Pi for transferring file, or to third party software such as Paragon ExtFS)

Setup & Installation
For my setup, I use Raspbian for my Raspberry Pi and minidlna as DLNA media server. I assume you are already familiar with Raspbian and how to install and configure packages.

~ step 1: hardware setup ~
  1. Ensure your Mac and Raspberry Pi are connected to your Time Capsule. Connect your external hard drive to Time Capsule via its USB port (if any).
  2. Ensure you have already known your Time Capsule and Raspberry Pi IP address. To determine Time Capsule’s IP address, you can use AirPort Utility tools (accessible via Applications->Utilities->Airport Utility). In this case, my Time Capsule IP address is:, while my Raspberry Pi is

~ step 2: minidlna installation ~
  1. Make sure your package repositories are up to date by running following command:
    sudo apt-get update

  2. Install minidlna package using following command:
    sudo apt-get install minidlna

~ step 3: other package installation ~
To be able to read Time Capsule storage from Raspberry Pi, you need to install cifs-utils package using following command:

sudo apt-get install cifs-utils

Basically, Time Capsule support both CIFS and AFP protocol. You can install afpfs-ng and afpfs-ng-utils package if you choose to connect to Time Capsule via AFP protocol. But based on my experience, this packages is still buggy and unstable on my Raspberry Pi. I recommend to use CIFS instead.

~ step 4: create mount point ~
  1. Create a directory as a mount point for your Time Capsule storage. In this example I create a new directory under /home/pi/media
    mkdir /home/pi/media
  2. Time Capsule creates a mount point with the same name when you add new user. It also has /Data/ mount point which is shared to all Time Capsule user. In this example, my Time Capsule user name is amphie, and I store my Movie collection on /Data/Movies (yes, all Time Capsule users can access this directory).

    To mount this folder to /home/pi/media, run following command:
    sudo mount -t cifs -o username=amphie,password=xxxxxx,sec=ntlm // /home/pi/media/

    To check whether it’s already mounted, run following command:

    mount -v

    You will see the result like this:
    /dev/root on / type ext4 (rw,noatime,data=ordered)
    devtmpfs on /dev type devtmpfs (rw,relatime,size=219764k,nr_inodes=54941,mode=755)
    tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=44788k,mode=755)
    tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
    proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
    sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
    tmpfs on /run/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=89560k)
    devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
    /dev/mmcblk0p1 on /boot type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro)
    // on /home/pi/media type cifs (rw,relatime,vers=1.0,sec=ntlm,cache=strict,username=amphie,uid=0,noforceuid,gid=0,noforcegid,addr=,file_mode=0755,dir_mode=0755,nounix,serverino,rsize=16384,wsize=64172,actimeo=1)
  3. To make Time Capsule storage automatically mounted to your Raspberry Pi, edit /etc/fstab file using following command:
    sudo vi /etc/fstab

    and add following lines:
    // /home/pi/media/ cifs username=amphie,password=xxxx,sec=ntlm 0 0

    save and exit vi.
When you connect external USB hard drive to Time Capsule, it will create a new mount point with the same name as its partition label. So for example, if you have two partition with label: Documents and Music, Time Capsule will create two mount points: /Documents/ and /Music/ which are accessible by all Time Capsule users (besides their own private folder and /Data/ mount point).

Each mount point is linked to /Shared/ folder on each partition. So don’t get surprised if you open any mount point and found nothing there. Any folders and files outside /Shared/ folder on your partition will not be accessible via Time Capsule. It’s only accessible when you plug it directly via your Mac.

You can mount other Time Capsule mount points to your Raspberry Pi using the steps above as well.

~ step 5: minidlna configuration ~
  1. Open minidlna configuration file which is located on /etc/minidlna.conf:
    sudo vi /etc/minidlna.conf

    and add/update following lines to add /home/pi/media directory to minidlna library:

  2. Open sysctl.conf for editing using following command:
    sudo vi /etc/sysctl.conf

    and add following lines at the bottom of the file:
    fs.inotify.max_user_watches = 100000

  3. Rebuild minidlna database and restart the minidlna application:
    sudo service minidlna stop 
    sudo service minidlna rescan

That's it. Now you should be able to stream your multimedia content via your favourite DLNA client.

1 komentar:

  1. Finally a guide that worked for me, very straightforward! I'm a noob at linux, thank you very much!