Turning Your Headless Linux Machine into a DLNA Media Server

We have had a Sony Bravia KDL40HX750 TV for a while now. It’s a great TV and can stream media from a compliant DLNA media server. I was doing this with Windows Media Player from my dev PC but given that my dev machine is usually turned off after 9PM it wasn’t used much. So, given that my My mini-ITX file server had been running nicely for a week or so I figured it could become the new media server for the house. Here’s how I got it working.

1. Mount an External HDD

The first problem was to mount an external USB disk drive to hold the media. And I wanted it to mount to the same point every time it was unplugged and plugged back in. This was fairly simple. Firstly, we need to work out the UUID of the USB drive we want to use. Run:

sudo blkid

And you should see something like that shown below. Our USB drive is on the bottom line,

/dev/md1: UUID="a20f7307-fb20-4c92-95d2-db222778af8f" TYPE="swap"
/dev/md0: UUID="c4c0ea5f-0613-4acc-8fa5-4d5968802771" TYPE="ext4"
/dev/sdc1: UUID="AE884FDE884FA425" TYPE="ntfs"

Once you know the UUID open up /etc/fstab in your text editor of choice and add an entry that looks something like this:

UUID=AE884FDE884FA425 /media/mediadrive ntfs defaults 0 0

Save those changes. Then create a mount point for your mediadrive using something like:

sudo mkdir /media/mediadrive/

Then reboot your machine and you should find that fstab mounts your USB drive to /media/mediadrive

2. Install and configure minidlna

There’s a number of DLNA compliant media servers for Linux. I chose minidlna because it was small and seemed to just work. Install it with:

sudo apt-get install minidlna

Then open the minidlna.conf file with:

sudo nano /etc/minidlna.conf

And configure to suit. I left most settings as is but you’ll need to set the path to your media drive, the network interface, and give your media server a name for devices to use when they connect to it. Here’s what those settings look like:

media_dir=/media/mediadrive
network_interface=p4p1
listening_ip=192.168.2.3
friendly_name=EinsteinJR

I note that there’s a web interface to manage minidlna but I haven’t taken a look at that.

Save the config changes and then restart minidlna with:

sudo service minidlna restart

3. Refresh Your Media LIbrary

By default minidlna refreshes your medial library every 895 seconds (controlled by the notify_interval setting in the conf file). However, if you’re impatient you can force a refresh with:

sudo minidlna -R
sudo service minidlna restart

Alternatively you can force the database refresh using:

sudo service minidlna force-reload

Once your library is refreshed you should see your new server available from your media device and be able to view your movies or listen to your music.

This entry was posted in Gadgets, linux on by .

About markn

Mark is the owner and founder of Timesheets MTS Software, an mISV that develops and markets employee timesheet and time clock software. He's also a mechanical engineer, father of four, and a lifelong lover of gadgets.