Installing MediaTomb UPnP streaming server on WD MyBook World Edition

By following these instructions you might mess up your mybook device. I won't take any responsibilities for damages nor even a guarantee that it fits your needs or you won't lose all data and even the manufacturer's warranty on your device. Even if your NAS turns into a giantic fireball burning your house - I won't be there to hold your hand. So if you don't have at least intermediate linux knowledge you should ask someone more experienced to assist you.

Contents

Description

Recently I looked for an UPnP streaming device, like the Terratec Noxon iRadio. As I store all media files on the mybook NAS device I wanted to play my songs directly from it. Googling around I found Martin Hinner's instructions on gaining shell access to the mybook. After I noticed that the mybook linux includes the GNU C Compiler gcc, I got MediaTomb - an open source UPnP server. Here you will find the necessary steps to compile and use it on your NAS device turning the mybook into a full compliant streaming server implementing the UPnP 1.0 specifications.

Step-by-step instructions

1. Enable shell access on the mybook device via ssh
To login to your mybook you have to enable ssh access on it. You will find instructions how to achive this at http://martin.hinner.info/mybook/sshaccess.php. As documented the root password will be reset to '' during this process. You should change that:

[jpk@MYBOOK /]$ su -
 Password:
[root@MYBOOK ~]# passwd root
 Changing password for root
 Enter the new password (minimum of 5, maximum of 8 characters)
 Please use a combination of upper and lower case letters and numbers.
 Enter new password:
 Re-enter new password:
 Password changed.
Please visit the links section for more information.

2. Recommended: Disable Mionet service
I had no use for the Mionet service so I decided to disable it to save some of the 32mb RAM of the device. You may safely skip this step if you use the service.
There are several ways to turn off the Mionet service - here's one:

[root@MYBOOK ~]# /etc/init.d/mionet.sh stop
  Stoping mionet
  Shutting down monitorCVM:
  Shutting down changeNotifySocket:
  Shutting down MioNet:
  Verify: Now monitorCVM is Not running
  Verify: Now changeNotify is Not running
  Verify: Now Mionet is Not running

[root@MYBOOK ~]# cp -p /etc/init.d/post_network_start.sh /etc/init.d/post_network_start.sh.ORIG
[root@MYBOOK ~]# vi /etc/init.d/post_network_start.sh
Here you should change line 17 from
		$SCRIPTS_PATH/mionet.sh start
to
		#$SCRIPTS_PATH/mionet.sh start
and line 25 from
		$SCRIPTS_PATH/mionet.sh stop
to
		#$SCRIPTS_PATH/mionet.sh stop

3. Installing MediaTomb
First you will have to add a user and a group as well as a home directory for mediatomb to store databases, logs and pidfile:

[root@MYBOOK ~]# addgroup mediatomb
[root@MYBOOK ~]# adduser -g "mediatomb upnp service" -G mediatomb -h /var/mediatomb -s /bin/false mediatomb
[root@MYBOOK ~]# passwd -l mediatomb
[root@MYBOOK ~]# mkdir /var/mediatomb
[root@MYBOOK ~]# chown mediatomb:mediatomb /var/mediatomb

3a.) quick: Use the precompiled static binary
The MyBook WEII is equipped with a ~200Mhz ARM926EJ cpu and 32mb RAM which means that compiling MediaTomb and all necessary libs took a serious amount of time. If you want to save time and headaches, you could use my precompiled binary. It is a static built, so you won't have to deal with any libs. I used the strip command to remove debug info. The server resides under /opt/mediatomb. A startscript to use at boot time is included as /opt/mediatomb/bin/upnp.sh and linked to /etc/init.d/S60upnp.sh and /etc/init.d/K50upnp.sh.

To download and install MediaTomb, login to your mybook as root user and type:

[root@MYBOOK ~]# wget http://www.jpkessler.de/mybookupnp/mediatomb-0.10.0-mybook-static.tar.gz -q -O - | tar xzvf - -C /
Now you're ready to continue with step 4 Configure MediaTomb. Fyi, MediaTomb was compiled as follows:
[root@MYBOOK ~]# ./configure --prefix=/opt/mediatomb --enable-static \
				  --enable-mrreg-service --enable-protocolinfo-extension \
				  --enable-sqlite3 --enable-libjs --enable-id3lib
[root@MYBOOK ~]# make
[root@MYBOOK ~]# make install
[root@MYBOOK ~]# strip /opt/mediatomb/bin/mediatomb
You can find the software here or on this mirror for offline installation.

3b.) expert: Compile MediaTomb and prerequisite packages
Be prepared for long compilation times - get yourself a coffee and do anything else than accessing large amount of data stored on your mybook. Because of limited cpu and ram there won't be much resources left for samba. You will need the following prerequisite software packages:

and compile them:
[root@MYBOOK ~]# wget <package-url>
[root@MYBOOK ~]# gzip -cd <package>.tar.gz | tar -xf -
[root@MYBOOK ~]# cd <package>
[root@MYBOOK ~]# ./configure
[root@MYBOOK ~]# make
[root@MYBOOK ~]# make install
Finally get the MediaTomb Source and compile it:
[root@MYBOOK ~]# wget http://downloads.sourceforge.net/mediatomb/mediatomb-0.10.0.tar.gz
[root@MYBOOK ~]# gzip -cd mediatomb-0.10.0.tar.gz | tar -xf -
[root@MYBOOK ~]# cd mediatomb-0.10.0
[root@MYBOOK ~]# ./configure 	--prefix=/opt/mediatomb \
				--enable-sqlite3 --enable-libjs \
				--enable-id3lib --enable-libexif \
				--enable-mrreg-service --enable-protocolinfo-extension
[root@MYBOOK ~]# make
[root@MYBOOK ~]# make install
[root@MYBOOK ~]# strip /opt/mediatomb/bin/mediatomb
The last command is optional and removes debug info from the binary to save some space. You will find more detailed informations on compiling MediaTomb at the MediaTomb homepage.

4. Configure MediaTomb
To create an initial configuration file, call MediaTomb and wait until you see:

[root@MYBOOK ~]# /opt/mediatomb/bin/mediatomb --home=/var/mediatomb
 2007-09-24 02:02:35    INFO: Configuration check succeeded.
 2007-09-24 02:02:35    INFO: Initialized port: 49152
 2007-09-24 02:02:35    INFO: Server bound to: 192.168.1.18
 2007-09-24 02:02:37    INFO: MediaTomb Web UI can be reached by following this link:
 2007-09-24 02:02:37    INFO: http://192.168.1.18:49152/
Now you should find a basic configuration file under /var/mediatomb/.mediatomb/config.xml. This example config file uses ISO-8859-15 (german) encodings for metadata, playlists and scripting. Change it to whatever fits your needs. In any case you should change the <udn> statement which represents a unique network id for your UPnP service.
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://mediatomb.cc/0.10.0/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://mediatomb.cc/0.10.0/config http://mediatomb.cc/0.10.0/config.xsd">
  <server>
    <ui enabled="yes">
      <accounts enabled="no" session-timeout="30"/>
      <items-per-page default="100">
        <option>25</option>
        <option>50</option>
        <option>100</option>
        <option>200</option>
      </items-per-page>
    </ui>
    <name>MediaTomb</name>
    <udn>uuid:b9b787bc-8993-4ee6-bcb8-00554dd24cf5</udn>
    <home>/var/mediatomb/.mediatomb</home>
    <webroot>/opt/mediatomb/share/mediatomb/web</webroot>
    <storage driver="sqlite3">
      <database-file>mediatomb.db</database-file>
    </storage>
  </server>
  <import hidden-files="no">
    <filesystem-charset>ISO-8859-15</filesystem-charset>
    <metadata-charset>ISO-8859-15</metadata-charset>
    <playlist-charset>ISO-8859-15</playlist-charset>
    <scripting script-charset="ISO-8859-15">
      <common-script>/opt/mediatomb/share/mediatomb/js/common.js</common-script>
      <playlist-script>/opt/mediatomb/share/mediatomb/js/playlists.js</playlist-script>
      <virtual-layout type="builtin">
        <import-script>/opt/mediatomb/share/mediatomb/js/import.js</import-script>
      </virtual-layout>
    </scripting>
    <mappings>
      <extension-mimetype ignore-unknown="no">
        <map from="mp3" to="audio/mpeg"/>
        <map from="ogg" to="application/ogg"/>
        <map from="asf" to="video/x-ms-asf"/>
        <map from="asx" to="video/x-ms-asf"/>
        <map from="wma" to="audio/x-ms-wma"/>
        <map from="wax" to="audio/x-ms-wax"/>
        <map from="wmv" to="video/x-ms-wmv"/>
        <map from="wvx" to="video/x-ms-wvx"/>
        <map from="wm" to="video/x-ms-wm"/>
        <map from="wmx" to="video/x-ms-wmx"/>
        <map from="m3u" to="audio/x-mpegurl"/>
        <map from="pls" to="audio/x-scpls"/>
      </extension-mimetype>
      <mimetype-upnpclass>
        <map from="audio/*" to="object.item.audioItem.musicTrack"/>
        <map from="application/ogg" to="object.item.audioItem.musicTrack"/>
        <map from="video/*" to="object.item.videoItem"/>
        <map from="image/*" to="object.item.imageItem"/>
      </mimetype-upnpclass>
      <mimetype-contenttype>
        <treat mimetype="audio/mpeg" as="mp3"/>
        <treat mimetype="application/ogg" as="ogg"/>
        <treat mimetype="audio/x-flac" as="flac"/>
        <treat mimetype="image/jpeg" as="jpg"/>
        <treat mimetype="audio/x-mpegurl" as="playlist"/>
        <treat mimetype="audio/x-scpls" as="playlist"/>
      </mimetype-contenttype>
    </mappings>
  </import>
</config>

5. Import your media files
Unfortunately strange ID3Tags have broken my database multiple times. For that reason I chose not to use the autoscan options and to import my media files manually. I also make backups with tar before I import 'untrusted media'.

[root@MYBOOK ~]# cd /var/mediatomb; tar zcfv mediatomb-db-`hostname`-`date +%Y%m%d-%H%M%S`.tar.gz .mediatomb; cd -
[root@MYBOOK ~]# ln -s /shares/internal/media/music /music
[root@MYBOOK ~]# /opt/mediatomb/bin/mediatomb --home=/var/mediatomb --config=/var/mediatomb/.mediatomb/config.xml --add /music
The leds will stop blinking when the process is finished. Alternatively you can check MediaTomb's activity via the Web GUI or the top command.

6. Check that everything is working
Check that MediaTomb is running an listening on the network:

[root@STORAGE001 ~]# ps -aef|grep mediatomb
 root     11795     1  0 15:54 ?        00:00:00 /opt/mediatomb/bin/mediatomb --daemon --home /var/mediatomb --config /var/mediatomb/.mediatomb/config.xml
 ...
[root@STORAGE001 ~]# lsof|egrep "^mediatomb.*(TCP|UDP)"
 mediatomb 11795     root    6u     IPv4      97431                UDP *:1900		  <---- UPnP service
 mediatomb 11795     root    4u     IPv4      97429                TCP *:49152 (LISTEN)	  <---- WebInterface
...
Probably the most accurate test will be the most simple one - just turn on your streaming client. The MediaTomb server should be automatically found by your device.

7. Enable automatic startup
I use the following script in /etc/init.d to start MediaTomb at system bootup:

#!/bin/sh

case "$1" in

        start)          [ -z "`/bin/netstat -rn|/bin/grep ^239.0.0.0`" ] && /sbin/route add -net 239.0.0.0 netmask 255.0.0.0 eth0 ;
                        [ -z "`/sbin/ifconfig eth0|/bin/grep 'ALLMULTI MULTICAST'`" ] && /sbin/ifconfig eth0 allmulti multicast ;
                        /opt/mediatomb/bin/mediatomb --daemon --home /var/mediatomb \
                                --user mediatomb --group mediatomb \
                                --config /var/mediatomb/.mediatomb/config.xml \
                                --pidfile /var/mediatomb/mediatomb.pid \
                                --logfile /var/mediatomb/mediatomb.log ;;

        stop)           /usr/bin/pkill mediatomb ;;

        restart)        $0 stop ; $0 start ;;

        *)              echo "Usage `basename $0` {start|stop}" >&2 ;
                        exit 1 ;;
esac
exit $?

Security

If you are on an insecure network you should consider the following: If you choose to ignore this, consider

Related links


http://www.jpkessler.de/mybookupnp/index.html 2007 by Jan Peter Kessler mediatomb(AT)jpkessler(DOT)de