Multimedia File Server DLNA/UPnP

Have you ever wanted to watch movies, listen to the music or watching your picture collection on your TV or smartphone without a need to connect your laptop to the tv set? Maybe you have PS3 and you always dreamt of having access to those resources with PS3?
Of course you can always find a software for your laptop, but wouldn’t it be cooler to have your whole multimeda library just waiting for you in your network, ready whenever you want to use it and consuming only a fraction of electric power of what your laptop/desktop usually consumes?

You didn’t buy RPi just to watch beautiful full HD movies ;) you can do with it nearly everything so why not changing it to your multimedia file server. With our help it is VERY easy! Just follow the steps below and you can enjoy it :)

Update list of packages…

sudo apt-get update

…and upgrade packages

sudo apt-get upgrade

When asked:

After this operation, xxx kB of additional disk space will be used.
Do you want to continue [Y/n]?

Confirm with Y.

It can take a lot of time to complete this step so be patient :)

Now it is time to install minidlna, our DLNA server software.

sudo apt-get install minidlna

Again, when asked:
After this operation, XXX MB of additional disk space will be used.
Do you want to continue [Y/n]?

Confirm with Y

minidlna will be now downloaded and installed. It may take some time…

When it is done installing we need to make sure that we have anything to be shared :) I assume you have USB drive connected to RPi – in order to have it available for mindlna, we need to make sure it is mounted in specific/defined folder in file system.
As you may already know /etc/fstab file contains information about your file systems that are mounted during boot time. You will NOT see here your USB drive

cat /etc/fstab

So let’s add it – first we need to identify device ID by executing

sudo blkid

/dev/mmcblk0p1: SEC_TYPE="msdos" UUID="C522-EA52" TYPE="vfat"

/dev/mmcblk0p2: UUID="62ba9ec9-47d9-4421-aaee-71dd6c0f3707" TYPE="ext4"

/dev/sda1: LABEL="My_Passport" UUID="4E1AEA7B1AEA6007" TYPE="ntfs"

Above you can see the last line describing my USB drive. I strongly recommend that name of the disk do NOT contain any spaces (you can change it in Windows and, of course, without disconnecting it from RPi using ntfslabel from the ntfs-3g package in case of ntfs file system disk).

We need to make sure that there is a directory to have disk mounted to. Let’s create directory then and set proper privileges:

sudo mkdir -p /media/MyDisk sudo chmod 755 /media/HardDrive

Now we can edit /etc/fstab file. The easiest way to do that (for ‘Windows People’) is to use nano editor, but you can use anything else (like vi). Below you can see final file with new line highlighted:

proc /proc proc defaults 0 0

/dev/mmcblk0p1 /boot vfat defaults 0 2

/dev/mmcblk0p2 / ext4 defaults,noatime 0 1

UUID="4E1AEA7B1AEA6007" /media/MyDisk ntfs defaults,mask=000 0 0

# a swapfile is not a swap partition, so no using swapon|off from here on, use dphys-swapfile swap[on|off] for that

UUID and type (ntfs) is the same as we got from blkid command. All fields are tab separated. I have added mask option to make sure that disk files are mounted with full privileges.

Now we need to identify directories that will be sources for Pictures, Video files and Music files. Let’s have a look at disk content:

[email protected] ~ $ cd /media/MyDisk [email protected] /media/MyDisk $ ls -l total 4340

drwxrwxrwx 1 root root 4096 Nov 3 06:27 Extras drwxrwxrwx 1 root root 4096 Mar 3 10:10 Movies drwxrwxrwx 1 root root 4096 Nov 3 06:27 Locale drwxrwxrwx 1 root root 53248 Mar 3 10:10 Music drwxrwxrwx 1 root root 0 Nov 3 06:27 My Passport Apps for Mac drwxrwxrwx 1 root root 0 Feb 22 19:35 RECYCLER

drwxrwxrwx 1 root root 4096 Dec 12 20:51 System Volume Information drwxrwxrwx 1 root root 4096 Nov 3 06:27 User Manuals drwxrwxrwx 1 root root 4096 Nov 3 06:27 WD Apps for Windows

-rwxrwxrwx 2 root root 4223936 Jun 13 2012 WD Apps Setup.exe drwxrwxrwx 1 root root 126976 Mar 3 11:05 Pictures

Ok, so directories’ names, which I use for keeping media files are self explanatory. Now you need to tell minidlna where your files are – you do that by editing minidlna configuration file: /etc/minidlna.conf

There are a few lines to be modified:

1. Media directory(-ies) media_dir – drectory with your media files. You can specify what type of media there is or not. If you do, it will make navigation in your ‘client’ device a bit more smart/user friendly. Since I have dedicated directories for different types of files I will specify what is where:

media_dir=A,/media/MyDisk/Music media_dir=P,/media/MyDisk/Pictures media_dir=V,/media/MyDisk/Movies

2. Database location db_dir – where minidlna database files will be kept.

db_dir=/home/pi/minidlna

3. Log files location log_dir – here just un-comment the line:

log_dir=/var/log

4. Provide server name – it will be visible in your clients:

friendly_name=Raspberry

Save the file.

What we did not do yet is we did not create minidlna db directory.

mkdir /home/pi/minidlna chmod 777 /home/pi/minidlna

After doing all this modification force minidlna database recreation by running:

sudo service minidlna force-reload

You can check the log for more information/progress on db building:

cat /var/log/minidlna.log

You can also check if minidla is currently running:

sudo service minidlna status

If your minidlna does not start automatically with the system, run:

sudo update-rc.d minidlna defaults

If you’ve done everything right, it should be working now :)

Continue reading here: Raspberry Pi 2 & Lightberry = <3

Was this article helpful?

0 0