Monday, January 16, 2012

Turning FreeNAS into DLNA/UPnP media server with MediaTomb

Recently I got an Android phone and were looking for options how to access all my pictures, music and movies stored in my local server. I quickly learned that my first bet, just to access network disk shares would be quite inconvinient. Maybe I didn't try hard enough finding the right apps, but I found something better. There is a DLNA/UPnP server called MediaTomb. It servers out all your music, movies and pictures into your LAN. You can access it with any compadible client, for Android there are multiple apps, but a free one I'm using right now is UPnPlay. If you happen to have Playstation 3, then you can access your movies/music stored on your server too. Even your TV might directly support it (if it has ethernet port or builtin WiFi).

I'll go over the installation procedure for MediaTomb how I did it. I won't cover the absolute basics (like how to get Putty) so when you're feeling a bit lost, reading through my last article about how I installed BitTorrent client may help.
Read the full story ...

Just in case, I need to mention that however you use these instructions here, it is solely your responsibility to keep your data safe. You may loose you data. So, take precautions when working with disks that alreay have data on it.


Have a FreeNAS 8.0.2 server (later versions may be ok too) all set up and connected to internet. I suggest you to have backup. It is not very likely that you'll loose data, but better safe than sorry. Another thing is that when installing stuff with pkg_add under FreeNAS, one can't simply do pkg_delete and start the procedure over again. On every restart the pkg database is reset with no trace of the packages you've installed. Files are still there, but since FreeNAS rebuilds /etc and /var after restart, some installed files may get lost if you're not careful.

Installing and configuring.

Log into your FreeNAS server with SSH to install MediaTomb.

[toomas@saikano ~]$ su
[toomas@saikano ~]# mount -uw /
[toomas@saikano ~]# pkg_add -r mediatomb
[toomas@saikano ~]# cp /usr/local/etc/rc.d/mediatomb /conf/base/etc/rc.d/
[toomas@saikano ~]# ee /conf/base/etc/rc.conf
--- add the following lines and save ---
[toomas@saikano ~]# ee /etc/rc.conf
--- add the same lines as you added to /conf/base/etc/rc.conf ---

EDIT: Based on one comment the mediatomb startup script might be installed into /usr/local/etc/rc.d/ instead of /etc/rc.d/. If so, just use that path instead when cp failed.

Set mediatomb_mtuser and mediatomb_mtgroup to match your system. These are the permissions used to run the daemon. The user www comes with FreeNAS and I just use it so I wouldn't have to create separate user mediatomb (my Transmission uses www user too). The group users is something I use for all users who can access the shares. This way I find it a bit easier to manage file permissions.


is something that doesn't exist yet. It doesn't matter where it is, but I like to have it in a folder that is shared out with Samba. To create the config you need to run MediaTomb once to generate the default config.xml. Then you can move it to another location for daemon and configure it. In case you get an idea that its fine to run MediaTomb under root privileges for simplicity, DON'T!

[toomas@saikano ~]# mediatomb
Press CTRL+C (after a few seconds)
[toomas@saikano ~]# mv ~/.mediatomb /mnt/precious/shared/
[toomas@saikano ~]# cd /mnt/precious/shared/.mediatomb/
[toomas@saikano ...]# chown -R www:users .
[toomas@saikano ...]# chmod -R 775 .
[toomas@saikano ...]# ee config.xml

Now you've got the configuration open. It is in a standard XML format and documented here. It is kind of magic and takes a lot of time to get properly configured. The problem is that not all clients support all the media formats. Maybe I'll write more about it later, but for now you need to set only a few parameters to make the config usable. Note that lines starting with ADD or CHANGE are comments and should not be copied to the config file!

# CHANGE name which you'll see in your UPnP client

# CHANGE home where the internal database will be stored

# ADD autoscan directories after import tag. I share out the
# whole shared folder which has subfolders for music/movies/etc
<import hidden-files="no">
<directory location="/mnt/precious/shared" mode="timed" interval="3600" level="full" recursive="yes" hidden-files="no"/>

Time to restart. When the server boots up, it mediatomb should start automatically. You can check it from shell with ps ax | grep mediatomb.

The log goes to /var/log/mediatomb.log which you should check. I found a lot of warnings there, most of them complaining about encoding. You can safely ignore them, but when you can't see or play some file on your client, you can check the log if there are any errors about it.

Using it

In general it should be very easy. Just open your DLNA/UPnP client and it should automatically see your server.

For Android I use UPnPlay or a free version of BubbleUPnP. They both play have playlists and can play music. BubbleUPnP let's you browse pictures too inside the app. Both of them redirect video playback to video player app which you need to install separately. I use MX Video Player since it's free and can even play 720p HD vids without a problem on my XPERIA Ray. BubbleUPnP has much better interface, but free version has 16 item playlist limitation.

If you have a Playstation 3 it should detect the server automatically, but probably it won't play most of the videos, because it is very picky about file formats. You need to do a lot of configuring in MediaTomb to get things working, google for it. I don't have PS3 any more so I can't check it out.

Windows Media Player should support UPnP too and so does Winamp and Foobar2000, but they need separate plugins. There are rumors about VLC supporting it too, but I haven't seen a working one yet.

And lastly, your MediaTomb has a web interface too. Unless you've changed the port, you can access it from


  1. Thanks Toomas - I was wondering when FreeNAS would get around to reinstituting a uPnP server - now I don't care. These instructions worked perfectly.

  2. Thanks Toomas for these instructions. All seems to work apart from I am having problems with /etc/rc.conf retaining the mediatomb changes - after reboot the file returns to its orginal state. Any idea how I can ensure the changes are retained?

  3. Thanks for noticing! I forgot the part that you actually need to edit both "/conf/base/etc/rc.conf" and "/etc/rc.conf". I hope that solves the problem. I'll update the instructions too.

  4. I get error
    freenas root: /etc/rc: WARNING: failed to start mediatomb
    can not create /var/log/mediatomb.log

    any ideas

  5. 0k got it running I had to create this file to get it to run on freenas 8.04

  6. does not work for x64,

    cp /usr/local/etc/rc.d/mediatomb /conf/base/etc/rc.d/
    cp: /usr/local/etc/rc.d/mediatomb: No such file or directory

    1. In fact I have x64 too. It seemes that mediatomb startup script was installed into /etc/rc.d/ and not /usr/local/etc/rc.d/ on your system. Thanks for mentioning, updated article.

  7. 2-04-20 00:13:27 INFO: Configuration check succeeded.
    2012-04-20 00:13:27 ERROR: Error while accessing sqlite database file (/mnt/Seagte/.mediatomb/mediatomb.db): Permission denied

    what do i need to do here? i set the permissions earlier with the chown and chmod commands......any help?

    1. Strange. Maybe double check if mediatomb_mtuser is correct in your rc.conf and that what file permissions you have. If still in problem, you could try running it from root in foreground mode and start adding parameters to match your daemon starup script. This way you should pinpoint the problem. See #mediatomb --help.

  8. I had a problem with the log file too. It couldn't start the service because it was trying to write a log file to /var/mediatomb/meditomb.log.

    I added another configuration parameter and it fixed the problem:

  9. Excellent tutorial, thanks again! I did have one question, how would you go about restarting the mediatomb service, say after making an edit to the config.xml.

    I've tried using the "service mediatomb restart" but it creates a new instance of the service and loads a new config.xml from /root

    Thanks again!