Skip to main content

Raspberry Pi DLNA Media Server

Stream media from your Raspberry Pi to tablets, consoles, and other devices using MiniDLNA.

Hardware

  • Raspberry Pi (preferably running Raspbian)
  • Stonking great USB hard drive full of music, movies, and other goodies. 

Why this rocks

  • Because you won't have to lug around your stonking great hard drive all over your house.
  • Because you'll have access to your media library from all devices.
  • Because the Raspberry Pi runs silent. No fan noises.

Assumed knowledge

  • You know how to access the terminal on your Raspberry Pi, either through the GUI, or through SSH on a remote machine.
  • Your Raspberry Pi can connect to your home network.
  • You have plugged your USB drive into your Raspberry Pi.  

Step: Auto-mount your External USB drive

Raspbian's window system might already auto-mount your USB drive. I.e. an icon for the drive might appear on your desktop. Take it from me though, this can cause a lot of hassle later as the window system tends to mount the drive after the media service is started, which means DLNA can't find the drive.

You want to configure Raspbian to auto-mount the drive before its window system starts. In short, this involves:

Creating a directory as a mount point, usually something like sudo mkdir /mnt/HDD

Finding the partition ID you want to mount with sudo blkid

Adding an entry to the /etc/fstab file with sudo pico /etc/fstab

Because I have an NTFS drive, I added the following line to my /etc/fstab file

PARTUUID=5dd83921-01 /mnt/HDD ntfs-3g defaults,nls=utf8,nofail,comments=x-gvfs-show 0 0

Your configuration will almost certainly be different. I thoroughly recommend this article for more information on fstab, although I didn't follow it exactly.

The official documentation is very useful too.

Step: Install MiniDLNA

In terminal:

sudo apt install minidlna

Step: Edit /etc/minidlna.conf

This is the standard location of MiniDLNA's configuration settings. To edit them, you can use:

sudo pico /etc/minidlna.conf

All you need is 2 settings:

1. Set user

user=pi

Why? Because your HDD is likely mounted under the default user account, 'pi', it's easiest to run MiniDLNA as the same user.

(The created account minidlna doesn't have access to external drives.)

2. Specify files and folders

Unfortunately, this means that you'll need to create a writeable location for the database and log files. So in a terminal, create a directory in your home folder. e.g.:

mkdir /home/pi/minidlna

and change db_dir and log_dir in minidlna.conf to use it.

Next, set the media folders in the config file. They will most likely be at paths like:

/mnt/HDD/Music

Tip: If you have multiple folders, just specify the smallest folder at this stage to make testing easier.

Test manual start

In terminal:

minidlnad

Crank up a media player on another device connected to the same network (e.g. VLC). 

Step: Configure Autostart

This is the hardest part.

MiniDLNA used to start at boot, but Raspbian now uses a different method to auto-start (systemd instead of init) and MiniDLNA has not adapted its startup scripts.

You don't want to have to manually start MiniDLNA every time you start your Raspberry Pi, so we need to write a systemd service for it and get it to run automatically.

Create the service file, give it the correct permissions, and edit it:

sudo touch /etc/systemd/system/minidlna.service
sudo chmod a+rx /etc/systemd/system/minidlna.service
sudo pico|leafpad /etc/systemd/system/minidlna.service

Here's what's in mine: ('#' denotes comments and can be omitted)

[Unit]
Description=minidlna, DLNA/UPNP-AV media server
RequiresMountsFor=/mnt/HDD

[Service]
Type=simple
# The -S flag runs minidlnad for systemd
ExecStart=/usr/sbin/minidlnad -S
# Run as default user 'pi'
User=pi

[Install]
WantedBy=multi-user.target

Every time you edit a systemctl service you need to reload it:

sudo systemctl daemon-reload

Test systemctl service start

Stop all minidlna processes and test starting via systemd:

sudo killall minidlna
sudo systemctl restart minidlna.service

Wait for a while, and you should be able to access your media library again. Now you can enable the service to be processed at startup:

sudo systemctl enable minidlna.service

Reboot, and MiniDLNA should auto-start!

Appendix

Useful systemctl commands

  • [sudo] systemctl start|stop|restart <minidlna.service>
  • [sudo] systemctl enable|disable <minidlna.service> (enable/disable autostart)
  • [sudo] systemctl status <minidlna.service> (useful troubleshooting information).

Further Reading

Comments

  1. I had an error after "sudo systemctl restart minidlna.service" which seemed to indicate that the PID file could opened to be written to. Any thoughts?

    ReplyDelete
    Replies
    1. Try changing the owner of the PID file with the 'chown' command. In the example above, I would change the owner to user 'pi'. Or delete the PID file altogether and let it be created again by your new configuration.

      Delete
  2. Thanks for your prompt reply. I could not find minidlna.pid. Changing ownership of minidlna.service did not help either. Following the instructions again (using copy and paste) I noticed that after "killall ..." I got "no process found". I tried the restart command and got no message but checking status revealed the same error regarding .pid. I then deleted minidlna.service, rebooted and discovered that minidlna was running anyway - I believe this is because there is an entry for it in init.d. As I am not skilled in Unix and the service is working I am happy to leave as it is. However if you wish to pursue in case your post needs to be changed I can supply daemon and minidlna log files if you email me and will be happy to try any changes you suggest. Thanks.

    ReplyDelete
    Replies
    1. What's most important is that you got it working for yourself. Well done! On my Raspbian-Pi, systemd replaced start-stop-daemon (init.d) so I had to work out how to get minidlna working with systemd. If init.d is not broken for you, don't fix it.

      Delete
  3. OK. Thanks for the help and post.

    ReplyDelete

Post a Comment

Popular posts from this blog

Transcode to PSP using Handbrake

Source: Handbrake 0.9.9.5530 64-bit edition Target: (Phat) Playstation Portable PSP-1000 , System Software: 6.60 Many internet articles on how to transcode video to PSP using Handbrake have not worked for me. Even the most helpful are incomplete. I hope this post will help fill in the blanks. There is no longer any PSP preset for Handbrake, but from what I can gather, the preset had only limited success as the x264 encoder would change syntax and settings between versions. Other presets that may have worked before, like 'iPod' and 'Apple-Universal' now do not. Here is what worked for me, step by step:

Scatterbox - build an Android Tor Socks Proxy Server

Cloak your location and create a firewall bypass device with a smartphone. 🕵Uses the Tor network . Does not require root. 1 - from Google Play, download and install: Orbot Orweb browser Socks Server Ultimate (Optional)

Dismissing Racism

Whenever white people kill people of colour, as in 2021's anti-Asian shootings in Atlanta Georgia , this sort of counter-commentary appears: "Since the killing of six Asian women who worked in massage parlors in Atlanta, the media has amplified the false narrative that “white supremacy” is to blame.  ... official crime stats show that white people are significantly underrepresented in terms of the violent crime threat they pose to Asians."  ... citing FBI statistics , whereas whites comprise 62% of the population, they committed 24% of crimes against Asians in 2018.  In comparison, blacks, who comprise 13% of the population, committed 27.5% of all violent crimes against Asian Americans in 2018.  So clearly, white people do not represent the biggest crime threat to Asian Americans." Not only is this an attack on the media and its imagined agenda, it also implies that Asians can't tell who's assaulting them.