"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects." (Robert A. Heinlein)

Thursday, 7 May 2015

Setting up a DLNA media server on the Raspberry Pi


My first though about how to use the Raspberry Pi has been to set-up a always-on, low-power, home-server. There are not many services that could be really useful at home but, among them, a DLNA compatible server is the one that more interested me.

Mounting the USB drive

In order to be a useful server, especially a media server, the Raspberry first needed some bigger disk than the system 8 GB micro SD. I so selected as main storage for Raspberry a old 3.5” IDE USB drive. No problems from the electrical power side since the drive it's externally powered.
Mounting a USB drive on the Raspberry is just a basic exercise of CLI Linux: after getting the device name with the lsusb command the disk can be mounted with a simple command:
sudo mkdir /media/usbdisk
sudo mount /dev/sda /media/usbdisk
the mount command automatically recognized the XFS file system the disk was formatted with (I used it, before, attached to the NAS). In order to make the disk permanently mounted I added the following line to the /etc/fstab file
/dev/sda1 /media/usbdisk xfs rw,defaults 0 0


Mounting network drives

Most of my multimedia files are hosted on my 1TB NAS disk so it looked natural to me to give the raspberry access to my NAS shares. Years passed since the first time I mounted a network disk on Linux and I never came into big problems. This time I was surprised to see the same command to work on my desktop Linux and fail on the Raspberry (with error code 5). After some looking in the 'Net and even more trial-and-error I discovered that I needed to add the security directive (sec=ntlm) to my mount options even the share was password-less and mounted as guest. At last here are my mount lines in fstab file:
//192.168.0.110/public /media/public cifs guest,uid=1000,iocharset=utf8,file_mode=0777,dir_mode=0777,sec=ntlm 0 0
//192.168.0.110/sh_maxx /media/nas cifs uid=1000,credentials=/home/pi/.smbcredentials,iocharset=utf8,sec=ntlm,file_mode=0777,dir_mode=0777 0 0

Installing minidlna


At last I installed minidlna, a light-weight DLNA server, following one of the many to-do available on the 'net. Installation as been just matter of an apt-get command:
sudo apt-get install minidlna
then I edited its global configuration file …
sudo vi /etc/minidlna.conf
… by adding media folders to be served
media_dir=V,/media/usbdisk/Movies
media_dir=V,/media/public/Video
media_dir=V,/media/nas/Movies
media_dir=P,/media/public/Pictures
media_dir=A,/media/public/MP3
last but not least I restarted minidlna service and forced it to reload
sudo service minidlna restart
sudo service minidlna force-reload

Conclusion

I tested my Raspberry server both from my cellphone (Mediahouse) and from my (DLNA compatible) DTVB decoder with good results. Movies and music are played both smoothly. Some movie aren't correctly played but I suppose this is because of unsupported codecs player-side.