Today I installed “minidlna” on my Rasperry Pi 3 Model B. At the moment I plan to store all my videos, pictures etc. on an external hard drive connected to the Pi and share the files in my internal network with it’s help. Later on I want to setup an automatic backup procedure for the files but this is another story 🙂 At the moment I just want to document what I have done to get the DLNA server up and running.
First I have installed “minidlna”:
root@raspberrypi:/home/pi# sudo apt-get install minidlna
Prepare a hard drive connected to the Pi
Than I have prepared a hard drive (with some example data) and connected it to one of the USB interfaces of the Pi. To assure that the mount point will not change on reboot, on connecting other hard drives in parallel, etc. I have done the following:
Retrieve the “UUID” of the hard drive:
root@raspberrypi:/home/pi# blkid .... /dev/sda1: UUID="7db942b8-19a0-4118-9aef-c217cbe7fc8a" TYPE="ext4" PARTUUID="0000f503-01" ....
Create the mount point:
root@raspberrypi:/home/pi# mkdir /media/dlna_drive root@raspberrypi:/home/pi# chmod 755 /media/dlna_drive/
Update /etc/fstab and use the meta data retrieved by blkid previously. I have added this at the end of the file:
... UUID=7db942b8-19a0-4118-9aef-c217cbe7fc8a /media/dlna_drive ext4 defaults,nofail,x-systemd.automount,x-systemd.device-timeout=5 0 0 ...
Unmount /def/sda1 (retrieved by bldkid previously) and mount the hard drive with the persistend mount point configuration:
root@raspberrypi:/home/pi# umount /dev/sda1 root@raspberrypi:/home/pi# mount -a
Edit /etc/minidlna.conf. The listing shows the changes/additions I have applied to the config:
media_dir=/media/dlna_drive/dlna/pictures media_dir=V,/media/dlna_drive/dlna/videos media_dir=A,/media/dlna_drive/dlna/music log_dir=/var/log friendly_name=RoadrunnerMedia inotify=yes notify_interval=300
Add the following to /etc/sysctl.conf:
Check if it hase been applied:
root@raspberrypi:/home/pi# sudo /sbin/sysctl -p net.ipv4.ip_forward = 1 fs.inotify.max_user_watches = 65536 root@raspberrypi:/home/pi#
Restart “minidlna” so the config changes apply:
service minidlna restart
Automaticaly spin down the hard drive
As external hard drives on Raspbian (Linux) doesn’t spin down automaticaly during idle times we have to manage this. If you browse the www you will find information about hdparm, hd-idle and sdparm. However which one will work depends on your hard drive. For me hd-idle did the job.
First of all to build hd-idle we need to install these packages:
root@raspberrypi:/var/log# apt-get install build-essential debhelper
Than we need to get latest hd-idle from sourceforge:
root@raspberrypi:/var/log# cd /home/pi/ root@raspberrypi:/home/pi# wget http://sourceforge.net/projects/hd-idle/files/hd-idle-1.05.tgz
Unpack downloaded tar ball:
root@raspberrypi:/home/pi# tar -xvf hd-idle-1.05.tgz && cd hd-idle
Compile hd-idle and install it:
root@raspberrypi:/home/pi/hd-idle# dpkg-buildpackage -rfakeroot root@raspberrypi:/home/pi/hd-idle# dpkg -i ../hd-idle_*.deb
Remove files downloaded/compiled during install procedure:
root@raspberrypi:/home/pi/hd-idle# cd ../ root@raspberrypi:/home/pi# rm -r hd-idle hd-idle_*
Test hd-idle by running from command line. You should see somthing like this (you can exit it with Ctrl+C):
root@raspberrypi:/home/pi# hd-idle -i 0 -a /media/dlna_drive/ -i 300 -d probing sda: reads: 273306, writes: 10 probing sda: reads: 273306, writes: 10 probing sda: reads: 273306, writes: 10
Enable hd-idle service by default and apply settings in this config file:
root@raspberrypi:/home/pi# vi /etc/default/hd-idle
Upate the config file mentioned above (the UUID has been retrieved earlier with blkid):
START_HD_IDLE=true HD_IDLE_OPTS="-i 0 -a /dev/disk/by-uuid/7db942b8-19a0-4118-9aef-c217cbe7fc8a -i 900 -l /var/log/hd-idle.log"
Restart hd-idle service:
root@raspberrypi:/home/pi# service hd-idle restart
Watch your hard drive. On no disk I/O it should spin down after 15 minutes.
Use “minidlna” server
On this photo I use BubbleUPnP client on my Android device to stream content (a picture in this case) from the “minidlna” server on the Pi to my Amazon Fire TV who acts as renderer: