Now that I’ve got my Pi working a bit more efficiently it’s time to actually start putting it to use: a media server. This post will detail the initial steps in getting your Raspberry Pi serving media files from an external drive via DLNA.

Mount External Hard Drive
The first thing we need to do is get the external hard drive mounted and read-able. When you plug in your hard drive Debian will not do anything with it, so you have two options: mount it manually each time or setup Debian to automatically mount it for you. As I didn’t really want to ssh into the Pi every time I restart it, I opted for the latter.
I will only ever be using 1 external hard drive, which means that I can set up Debian to auto mount this hard drive on startup by adding a fstab entry. If you’re going to be using lots of different drives, I’d recommend you having a look at install ‘autofs’ which will automatically mount any drives you plug in. See here on how to set it up. I could have done this for my setup, but autofs runs a daemon in the background and I’d rather not waste the RAM/CPU on it.
The first thing you need to do is plug in your external hard drive (obviously), now we need to find out what it’s UDID is. This fairly easy to do:
sudo blkid
Which will return a list with all of the drives (partitions really) connected to the Pi. You should be able to easily recognise your hard drive as it will not be any of the items starting with /dev/mmcblk. Here’s an example of my drive:
/dev/sda1: LABEL="CHRIS HD" UUID="4956-13EB" TYPE="vfat"
There are two important bits of information here, the UDID and partition type. With this information we can change the fstab file and add the hard drive to it, but first we need to create a directory for the hard drive to mount to. The following commands will create a directory, and then set the permissions so that we can read it without problems:
sudo mkdir -p /media/ExternalHd sudo chmod 755 /media/ExternalHd
Now we can edit the fstab file:
sudo nano /etc/fstab
Then add the following to the bottom of the file (replacing the UDID with TYPE with whatever blkid returned, and the mount location with whatever you created above):
UUID=4956-13EB /media/ExternalHd vfat defaults 0 0
Now if you call ‘sudo mount -a’ the hard drive should be mounted! Your drive will also be mounted every time the Pi boots.
MiniDLNA
The next step is to now install a media server. I have chosen MiniDLNA as it’s lightweight and works well with large libraries. Luckily MiniDLNA is available for Debian Wheezy!
Install and Setup MiniDLNA
First thing we need to do is install it:
sudo apt-get install minidlna
The next step is to set it up to your needs by editing it’s configuration file:
sudo nano /etc/minidlna.conf
I’m not going to write about every option here, but I’ll list some of the modifications I have made:
# Change the Media Dir's to point to the external hard drive, obviously change these to match your directory layout media_dir=A,/media/ExternalHd/Media/Music media_dir=V,/media/ExternalHd/Media/Video media_dir=P,/media/ExternalHd/Media/Photos # Change db_dir so that the database is saved across reboots db_dir=/home/pi/.minidlna # Uncomment log_dir for now in case we hit problems log_dir=/var/log # Inotify doesn't seem to work with this kernel inotify=no
Finally you can start MiniDLNA now (and also on boot) by running:
# Start MiniDLNA at boot sudo update-rc.d minidlna defaults # Start MiniDLNA now sudo service minidlna start
MiniDLNA will now begin indexing all of your media files. The more files you have the longer this takes, on my machine with 12000 media files it takes about 15 minutes. Luckily, as we changed the config to make MiniDLNA save it’s database to /home this only happens once.
If you’ve given MiniDLNA enough time to complete it’s indexing you’ll be ready to start serving media files. If you find that something isn’t working, you can check the log by running:
less /var/log/minidlna.log
If everything is working well I’d recommend re-commenting out the log_dir variable in the MiniDLNA config, as it does write out a lot of log information which may affect performance.
Next Steps
There are a number of improvements we can make to this setup for performance and power-saving which I’ll detail in a later post. For now though, enjoy your new DLNA media server!
I’m trying to follow your instructions but when i’ve added the line to the fstab file and try and mount the hard drive by typing “sudo mount -a”, a message returns saying “mount: mount point /media/ExternalHd does not exist”.
I have definitely created the directory /media/ExternalHd because i can cd to it.
Any ideas where i’ve gone wrong?
Hi,
have you try to play a Full HD 1080p mkv movie inside raspberry minidlna from a networked DLNA client?
I’m interested in performances issue on raspberry as dlan server when movie are streamed at 20Mbit/s.
Thanks.
Hi, I followed your tutorial and its been very useful however the server is showing on my clients as raspberrypi: root and not the name I assinged in the config file.
Any help?
Not sure. The trouble with the Pi is that everything is working off one USB port internally (Ethernet, USB, etc). I’ll give it a try though.
Weird. What devices are you using to connect with?
How has this turned out? My pi came in today, and after fighting tooth and nail to get minidlna working properly on my dd-wrt router, i’m about ready to give up and use this, but wanted to check if there have been any stumbles you’ve run into the last 3 weeks since writing this. Thanks
The Pi has been coping fine with everything I’ve thrown at it. My media isn’t exactly high bit-rate though (low bit-rate 720p mostly) so YMMV.
Yeah, I think the largest bitrate stuff are ~8mbps h264′s. Have you run into issues with minidlna not detecting or freezing on certain files, or has it been smooth that way as well?
I haven’t added anything to my library since this post (keep forgetting to get stuff).
It’s been pretty smooth on all of my files, there have been a few occasions where it’s stuttered but I’m 99% sure that’s my crappy home network.
Ok i found out where i’d gone wrong with mounting the usb but i’ve hit another snag. I’ve got wheezy on my pi and i don’t know if this is causing me problems. When i try and install the dependancies for miniDLNA i get the following:
E: Package ‘libavformat52′ has no installation candidateE: Package ‘libavcodec52′ has no installation candidateE: Unable to locate package libavutil50E: Unable to locate package libx264-118E: Unable to locate package libavutil49
Is this because of wheezy?
BTW, i changed the source to wheezy when following you instruction:
echo ”deb http://www.deb-multimedia.org squeeze main non-free” | sudo tee -a /etc/apt/sources.list
So i added more sources to the sources.list and managed to sole all of the dependancy problems before trying to install minidlna but:
pi@raspberrypi ~/Desktop $ sudo dpkg -i minidlna-1.0.24-1-arm.debSelecting previously unselected package minidlna.(Reading database … 58195 files and directories currently installed.)Unpacking minidlna (from minidlna-1.0.24-1-arm.deb) …dpkg: dependency problems prevent configuration of minidlna: minidlna depends on libjpeg62; however: Package libjpeg62 is not installed. minidlna depends on sqlite3; however: Package sqlite3 is not installed. minidlna depends on libavformat52; however: Package libavformat52 is not installed.dpkg: error processing minidlna (–install): dependency problems – leaving unconfiguredErrors were encountered while processing: minidlna
this happened!
I don’t really understand this. it says that package sqlite3 is not installed but i thought it was from your earlier instructions.
Also, libjpeg62 isn’t mentioned anywhere in your instructions but it appears to be an issue – when i try installing the libraries on their own i get:
pi@raspberrypi ~/Desktop $ sudo apt-get install sqlite3 libavformat52 libjpeg62Reading package lists… DoneBuilding dependency tree Reading state information… DoneYou might want to run ‘apt-get -f install’ to correct these:The following packages have unmet dependencies: libavformat52 : Depends: libavcodec52 (>= 5:0.7.13) but it is not going to be installed Depends: libavutil50 (>= 5:0.7.13) but it is not going to be installed Depends: libjack-jackd2-0 (>= 1.9.5~dfsg-14) but it is not going to be installed or libjack-0.116 Depends: libx264-118 (>= 3:0.118.2085+git8a62835) but it is not going to be installed sqlite3 : Depends: libsqlite3-0 (= 3.7.13-1) but 3.7.12.1-1 is to be installedE: Unmet dependencies. Try ‘apt-get -f install’ with no packages (or specify a solution).
Help! i was a noob 5 days ago…
Winodws 7 Meida Player, iPhone 4S and PS3
This doesnt work anymore
Great post. One addition which might be useful to people stumbling on your post – minidlna can now be installed with a simple “sudo apt-get install minidlna” if you have the latest Wheezy Debian image. Note – if you try installing with deb-multimedia in the apt sources, you might end up with an Invalid Function or something similar when you try to run it.
did you run ‘sudo minidlna -R’
I had a similar issue and I realized I forgot to do that (it says to in minidlna.conf). Hope that helps.
So where’s Part 2?
Thanks…I use to unmount the drive everytime from raspi if I wanted to watch any video,
Now I can just use this media server to stream it.
It would be great if you could specify how can we watch these over internet and also how to add password, if possible
database path not accessible: /home/pi/.minidlna
Thanks for the post. Helped me with miniDLNA installation. And, I have got inotify feature working too. Just need to append max_user_watches=1000000 (some high number) in /etc/syscont.conf
Sorry, /etc/sysctl.conf
when you made your directory did you call it “p” like he did? try “sudo mount -a” again but change a to p