Why miniDLNA? Well first let’s start with the fact that there are a lot of DLNA type servers out there. That do things quite differently. I wanted one that was reliable. My secondary concern was that I wanted one that didn’t try to do everything. I didn’t need web interfaces or transcoding. miniDLNA does just the sharing. What your device does with the data is up to it. It gives a good guarantee that it will work with the majority of devices.
A quick rundown on DLNA. It’s a working group built with a primary purpose of connecting various media devices to share your legal content while maintaining some semblance of protecting copyright holders.
Finally a note. To get miniDLNA working it requires considerable amount of packages to be installed to CentOS. I live by the “lean is mean” mentality and would not recommend installing this on a production machine that has other purposes. A fresh box would be ideal, but my own home linux machine is pretty cluttered.
Assumptions
- You have a location called /data/stuff that will be used to store the media files
- That your server is called www at the domain example.com or www.example.com.
- That, once again, you’ll have a user named bob that has sudoers privileges and that will be used to do all the work.
Pre-Installation
miniDLNA requires the RPMForge repository for Cent. There are quite a few required dependencies. First, if you don’t already have it. Install the RPM and it’s DAG key. The DAG key sometimes likes to turn — into – when you copy paste it. If it fails makes sure you have two dashes.
[root@dlna ~]$ sudo rpm -Uvh http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
[root@dlna ~]$ sudo rpm –import http://apt.sw.be/RPM-GPG-KEY.dag.txt
Next install the required dependencies. If this is a live machine some of these you may already have. If this step fails you may need to install the EPEL repository for Cent. Refer to my previous blog CentOS 6.2 and Netatalk to find out how.
[root@dlna ~]$ sudo yum install {flac,libogg,libid3tag,libexif,sqlite,ffmpeg,libvorbis,libjpeg}-devel gcc
Next we need to get the source and make it. As of now the current source is 1.0.24. If it’s different change lines 2, 3, 4 accordingly.
[root@dlna ~]$ wget http://sourceforge.net/projects/minidlna/files/latest/download
[root@dlna ~]$ tar -xf minidlna_1.0.24_src.tar.gz
[root@dlna ~]$ cd minidlna-1.0.24
[root@dlna minidlna-1.0.24]$ make
Installation
Now that we have minidlna made and ready to go we have to install it.
[root@dlna minidlna-1.0.24]$ sudo cp minidlna /usr/sbin/
[root@dlna minidlna-1.0.24]$ sudo cp minidlna.conf /etc/
Next we want to create the init.d script. I’m not an expert at writing these scripts so I borrowed from a link below and modified. If you notice something wrong or can be improved please feel free to comment.
[root@dlna minidlna-1.0.24]$ sudo vi /etc/init.d/minidlna
Enter in all the preceding text into the file and save.
#! /bin/sh
# chkconfig: 345 99 10# description: Fedora Startup/shutdown script for MiniDLNA daemon
# If you have chkconfig, simply:
# chkconfig –add minildna
# Proper init scripts on Linux systems normally require setting lock
# and pid files under /var/run as well as reacting to network
# settings, so you should treat this with care.
## EDIT FROM HERE
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Installation details
MINIDLNA=”/usr/sbin/minidlna”
ARGS=”/etc/minidlna.conf”
# Where to keep a log file
MINIDLNA_LOG=”/var/log/minidlna.log”
# Where the PID & Lockfile lives
PID_FILE=”/var/run/minidlna.pid”
LOCKFILE=”/var/lock/subsys/minidlna”
RETVAL=0
## STOP EDITING HERE
# The path that is to be used for the script
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
set -e
# Only start if we can find the minidlna.conf.
test -x $MINIDLNA || exit 0
# Parse command line parameters.
case $1 in
start)
echo -n “Starting MiniDLNA: “
$MINIDLNA -f $ARGS -P $PID_FILE >> $MINIDLNA_LOG 2>&1
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $LOCKFILE
echo_success
echo
;;
stop)
echo -n “Stopping MiniDLNA: “
RETVAL=$?
for pidf in `/bin/ls $PID_FILE 2>/dev/null`; do
if [ -s $pidf ]; then
kill `cat $pidf` >/dev/null 2>&1
RETVAL=$?
[ $RETVAL -eq 0 ] && echo_success
[ $RETVAL -ne 0 ] && echo_failure
fi
rm -rf $PIF_FILE
[ $RETVAL -eq 0 ] && rm -f $LOCKFILE
done
echo
;;
restart|reload|force-reload)
echo “Restarting MiniDLNA: “
$0 stop
sleep 2
$0 start
;;
*)
# Print help
echo “Usage: /etc/init.d/minidlna {start|stop|restart|reload|force-reload}”
exit 1
;;
esac
exit $RETVAL
After that file is created we need to set the proper permissions for the file.
[root@dlna init.d]$ sudo chmod 755 /etc/init.d/minidlna
Setup and Starting
Last we need to open up the proper ports in iptables, edit the config file and turn on the server. Open up iptables and add. Again be careful here with copying. the — in front of state and dport can be lost. Just double check before you save iptables.
[root@dlna minidlna-1.0.24]$ sudo vi /etc/sysconfig/iptables
-A INPUT -m state –state NEW -m tcp -p tcp –dport 1900 -j ACCEPT
-A INPUT -m state –state NEW -m udp -p udp –dport 1900 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 8200 -j ACCEPT
One thing to note here is that it is critical to have a port open for the presentation url. Some DLNA players require it in order to play. One of note is the Xbox 360. Without it your server will not show up.
Next is to edit the minidlna config file.
[root@dlna minidlna-1.0.24]$ sudo vi /etc/minidlna.conf
media_dir=/data/stuff
friendly_name=Whatever you want
presentation_url=http://www.example.com:8200
There are a few more settings you can tweak, but these 3 are the main ones to get up and running as quickly as possible. The file is well commented and you should be able to figure out any other changes you may need to make.
The last thing to do is restart iptables and to turn on minidlna.
[root@dlna minidlna-1.0.24]$ sudo service iptables restart
[root@dlna minidlna-1.0.24]$ sudo service minidlna start
[root@dlna minidlna-1.0.24]$ sudo chkconfig minidlna on
You should have a working findable, through uPnP, media server. If you have a lot of files is does take time for it to build it’s a database but you can always check it by pointing a web browser at http://www.example.com:8200