Home Streaming Server

I am making a DLNA Server to be able to stream audio, video and pictures within my house. This article will go over the details of what I have done for my system. I hope some of you can duplicate this if you need to, as well as comment on improving the server.

There are quite a few concepts in this article, so certain sections can be used on their own. For example, I will add SSH to the DLNA server so I can manage it from other systems. Samba will be installed so files can be moved from other systems on the network.

Hardware

For a DLNA server, you do not need much, unless you plan on streaming to quite a few devices at once. I plan on streaming to maybe only two televisions at the same time, but there could be more.

I found a Lenovo Thinkcentre M73 tiny business desktop. It has the following pertinent specs:

  • Intel Core i3 (2.9GHz)
  • 4 GB DDR3 RAM (I will upgrade to 10 GB)
  • 500 GB HDD
  • USB 3.0
  • Gigabit Ethernet

Within the BIOS, I can enable the device to work without a keyboard. I also enabled the device to power on after a power failure, so if the power goes out, I do not need to turn it back on manually. I installed Lubuntu to use fewer resources, so more can be available for streaming content.

I definitely like the Core i3 as a starting point for the server. I did not feel comfortable using a Pentium or Celeron. A slower processor may work fine, but I would prefer to have fast, non-buffering streaming.

Since the system only came with 2-2 GB RAM chips, I replaced one with an 8 GB memory chip to upgrade it. Since the system is DDR3, an 8 GB SIMM is only about $35.

I liked the USB 3.0 port so an external USB HDD can get fast access.

The external hard drive is a bit of different beast. I found an 8TB external drive on clearance at Walmart that is an Xbox Game Hub drive. The speed on the drive is about 160 MB/s using USB 3.0. This should be adequate for streaming, since HD only requires about 1.5 Mb/s. I’m looking for higher speed to move files from other systems quickly.

Cost wise, the refurbished Lenovo system and came with a one-year warranty for $125 from Amazon. The RAM chip was $35. The external HDD was $89. That makes $249 for my DLNA server.

Lubuntu

From ‘Lubuntu.me’, I downloaded Lubuntu 20.04 64-bit for the Operating System (OS). I installed it on the internal drive as normal, overwriting Windows 10 Pro. Of course, I made an ISO file and wrote down the Product Key if I need to install it elsewhere.

I enabled the automatic login when I set up my user and password. This way, when the system reboots for any reason, it will restart everything and log in and be ready to go. I formatted the internal and external drive as EXT4 for a little more speed performance.

The only bad thing about the system is that it has no HDMI port, only a DisplayPort. I plan on not hooking it up to a monitor of any type, or keyboard or mouse, once everything is completely installed. Once I have everything set up, I should not need a monitor.

Once installed and rebooted, I performed a system update:

sudo apt update && sudo apt upgrade -y

Within the Operating System, disable power management. It would not be good to have the system shut down when not being used. Disable the Screen Saver, so resources aren’t wasted for it. No need for a screen saver when you aren’t using a monitor. You may need to install GParted to manage external drive partitions and formatting. Disable Wi-Fi, unless you plan on using Wi-Fi instead of a direct connect set up. Install VLC if needed to include codecs which could be helpful, Lubuntu 20.04 comes with VLC installed. We can install extra codecs with:

sudo apt install ubuntu-restricted-extras -y

When you install the extra codecs, you are asked to accept the EULA and license agreement.

If you wanted, you could uninstall unneeded applications to free up space on the internal drive.

NOTE: If you wanted, you could set the IP4 Address manually, so it does not change. If the IP Address would change, it would not affect the DLNA service from a client’s viewpoint. The Samba and SSH servers need a known IP Address from the clients.

This is a basic setup for the Operating System. Now we can move on to setting up an external drive.

External Shared Drive

Using an external drive is not as simple as plugging it in and moving on. It must be mounted or the permissions will fail.

NOTE: This is a very important step. If the drive that you are sharing and using to store streaming files, make sure it is mounted. There are many ways to accomplish this task, but the way I will do it is an easy GUI based way.

Open a Terminal and install the Gnome Disk Utilities with ‘sudo apt install gnome-disk-ultility -y’. Once the app is installed, start the disk utility program with the command ‘sudo gnome-disks’.

Once the app starts, select your external drive in the left pane. Click on the icon with the two gears just below the graphical template of the selected drive. Choose ‘Edit Mount Options’ from the drop-down list. In the next window, shown in Figure 1, turn on the option to mount the drive. Set the options to be like that in Figure 1. Make note of the line ‘Identify As’. Set the value to ‘by-label’ to use the label name you gave your drive. Once everything is set, select the ‘OK’ button to make the changes.

Figure01.jpg

Figure 1

Reboot for the settings to take effect.

Now that the external drive is properly mounted, we can install the Samba Server to be able to change the shared files remotely on the network.

Samba Server

Keep in mind that Samba is only being used to set up a network share for the external drive. The share will allow me to manage the shared files to stream. I can add, remove or change the files on the shared drive. Of course, these files are the ones being streamed.

From a terminal, you should have already updated the system. We can now install ‘tasksel’ to use to install Samba. Execute the following commands:

sudo apt install tasksel
sudo tasksel install samba-server

Next, you need to create, or use, an existing account. If you create a new account for Samba, it must also exist in the OS ‘passwd’ file. If you want to create a new account, use the ‘useradd’ command. I suggest just using the account that you normally use.

To add a user to Samba, perform the command:

sudo smbpasswd -a <username>

You will be prompted for a password, may as well use your regular password, and then you’re prompted to confirm it.

If you have a firewall enabled, you need to open a port for Samba with the command:

sudo ufw allow samba

We now need to add the share to the Samba configuration file. My external drive is ‘/mnt/Theatre/DLNA’. My drive name is ‘Theatre’ with a root folder called ‘DLNA’. The ‘DLNA’ folder is being shared for access by other users on the network. Within the ‘DLNA’ folder are the three folders that will be used for streaming: ‘Movies’, ‘Audio’ and ‘Pics’.

NOTE: Remember that the folder names are case-sensitive throughout this section.

Create a folder that will be shared and then you’ll need to modify the permissions with:

sudo chmod 777 /mnt/Theatre/DLNA

We need to modify the configuration file for Samba. Open the file ‘/etc/samba/smb.conf’ with your favorite text editor and add the following to the bottom:

[DLNA]
path = /mnt/Theatre/DLNA
browsable = yes
create mask = 0660
directory mask = 0771
writable = yes
guest ok = yes

The Share name is placed in brackets, in my case [DLNA]. You can change this as you need for your system. The ‘path’ should also be changed to match your folder share.

In a terminal, run the command ‘sudo systemctl restart smbd’ to restart the service. You can use the command ‘sudo systemctl enable smbd’ to make sure the service automatically restarts at boot up.

You may need to restart the system just to make sure everything takes effect.

From a Windows system, you need to right-click on ‘This PC’ and select ‘Map Network Drive’. Select a Drive letter to map the share to over the network. Under ‘Folder’ type in ‘\192.168.1.45DLNA’. It is best to use the IP Address of the Samba Server and then the share name. You can choose to ‘Reconnect at sign-in’ if you want. Definitely check the box for ‘Connect using different credentials’, otherwise it uses your Windows name and password for the Samba share.

From a Linux system, open the File Manager and select ‘Network’. The Samba Server should appear. Double-click the Samba Server. Double-click on the share you want to open (DLNA in my case). You will be prompted for authentication information. Select to connect as a ‘Registered User’. Enter your username and password that was added to Samba. Select one of the options ‘Forget password immediately’, Remember password until you logout’ or ‘Remember forever’. As long as you got the username and password correct, you should connect just fine.

MiniDLNA

We now need to set up the streaming service. The procedure is not as involved as Samba, but there are configuration settings that can be a little tricky.

The MiniDLNA Server manages sending a file list to DLNA clients. Most smart TVs are DLNA compatible. If not, ROKU definitely is compatible. Within ROKU is an app call ‘ROKU Media Player’. If you do not have the app on your menu, then you need to install it. For Firestick users, you can use the VLC or Nova Video Player. Each device has other apps that work, but these I know do work.

To start installation, run the command:

sudo apt install minidlna

Once installed, we can configure the various folders. Remember my three folders within DLNA: ‘Movies’, ‘Audio’ and ‘Pics’. We will set up these three streaming folders for network devices.

You will need to edit the file ‘/etc/minidlna.conf’. For each streaming folder, you need to add a line. Each line has three designations:

  1. A – audio
  2. V – video
  3. P – pictures

You can use ‘PV’ for a folder with both pictures and video, but not often used.

The three lines I would add to my configuration file are:

media_dir=A,/mnt/Theatre/DLNA/Audio
media_dir=V,/mnt/Theatre/DLNA/Movies
media_dir=P,/mnt/Theatre/DLNA/Pics

Within the configuration file, make sure there is a line for ‘inotify=yes’. Remove the comment (#) from the line ‘# db_dir=/var/cache/minidlna’ to enable the database file to be on the internal drive. It would be good to remove the comment for the line ‘#log_dir=/var/log’. To specify a friendly name for the DLNA Server, remove the comment for ‘# friendly_name= ’ and add a name with no spaces. You can also change the line ‘# max_connections=50’ to be 250 or more and remove the comment (#).

NOTE: The ‘inotify=yes’ allows the DLNA database to be automatically updated when files are added to the specified folders.

You will need to add your user account to the group ‘minidlna’. Also, for Samba, add the ‘minidlna’ group to the ‘sambashare’ group.

We will also need to increase the ‘inotify.max_user_watches’ from around 35,000 to 100,000. To do this, edit the file ‘/etc/sysctl.d/90-inotify.conf’, with ‘sudo’ privileges, and add the line:

fs.inotify.max_user_watches = 100000

Save and close the file. The file will handle changing the value when the system is rebooted. You can make a change to the system without rebooting with the command:

sysctl fs.inotify.max_user_watches=100000

We can set the ‘minidlna’ service to autostart with the OS by enabling the service:

sudo systemctl enable minidlna

Once you have moved files into their proper folders you can refresh the database with the command ‘minidnlad -r’ From a client system that is accessing the files, the updated database is not available until you exit and reload the application you are using to stream.

NOTE: If a device gives an error that no files are found, then you need to check the owner of the files and change them to ‘minidlna’. You can also open ‘/etc/minidlna.conf’ and add a line ‘user=<username>’. Make the ‘<username>’ match the files. It’s supposed to default to ‘root’ if the line is commmented or doesn’t exist, but it doesn’t always work.

If there is a firewall enabled, you need to open port 8200 for streaming.

SSH

We can copy files to the server using samba and stream the files using minidlna, but we need to be able to run programs on the server. Such as updating the software or updating the minidlna database. This is where SSH comes into play.

We could use RDP, but there isn’t a need to be able to manage the server graphically.

Make sure you have your system up-to-date before proceeding. To install SSH, perform the following command:

sudo apt install openssh-server -y

SSH is now installed and should be running. Execute the command ‘sudo systemctl status ssh’ and it should show it is ‘running’ and ‘active’.

Next, you need to enable the service to start automatically when the system starts with the command: ‘sudo systemctl enable ssh’.

A firewall on the Linux OS can block SSH so we need to open that port. Use the command ‘sudo ufw allow ssh’.

At this point, I can SSH into my DLNA-Server from an SSH Client.

From a Linux system, install the SSH Client with the command: ‘sudo apt install openssh-client’. From Windows 10, there should be a client already.

From a Terminal, or Command Line, use the command ‘ssh [email protected]’. In my case it is ‘ssh [email protected]’. After executing the command for the first time, you should be prompted that you need to authenticate the server and client. Type ‘yes’ and press ENTER. You should then be prompted to enter the password for the user you specified and see a prompt that is from the DLNA-Server. You can issue commands to the server, such as ‘minidlnad -r’ to update the database of files. Once your server is running properly, be aware that some system updates may cause the DLNA service to stop until you perform a reboot. A reboot causes the database to be reconstructed from scratch. I suggest to not perform systems updates unless it is necessary.

Type ‘exit’ to close the SSH connection.

Folder Art

Within each folder, you can place a JPG file and name it ‘cover.jpg’ or ‘Cover.jpg’. Some systems, like Roku Media Player, will replace the simple folder icon with the image you placed in the folder. Sub-folders can also have their own image as well.

The DLNA system will automatically find new files and folders, but image files are another story. To fully update the whole database, you need to clean it all out and have it generate a new database. The following script is what I use. I called it ‘refresh.sh’:

#!/bin/sh
# Stop MINIDLNA
systemctl stop minidlna #/etc/init.d/minidlna.init stop
# Delete /tmp/ database files(Database and Art)
rm -rvf /tmp/minidlna/*
# Start Service and Rebuild MINIDNA database
minidlnad -R
# Start and Show MINIDLNA status
systemctl start minidlna
systemctl status minidlna
#Force the rebuild just in case
minidlnad -r

Make sure to perform the command ‘chmod +x refresh.sh’ to make the file executable. To run the script, you can SSH into the DLNA server and type ‘sudo ./refresh.sh’. I placed the file in the user’s Home folder that I use to SSH into the server.

Troubleshooting

There is a lot that can go wrong with the minidlna service. Keep an eye on the log file at ‘/var/log/minidlna.log’. If you see an error writing to the database, you can delete the database file at ‘/var/cache/minidlna/files.db’. If this does not fix the problem, then also delete the ‘/tmp/minidlna’ folder contents with the command ‘rm -rvf /tmp/minidlna*’. The command will delete all files and folders within the ‘/tmp/minidlna’ folder. Once the databases are deleted, it should automatically generate a new one. It may be best just to use the script mentioned above.

Check the log often. When the database is generated and corrupted video files are found, a list is generated in the log file. You will need to delete the corrupted files or fix them, if you can.

Again, do not perform system updates. If you do, reboot and let the database be recreated. Depending on the number of files you have, the recreation process could take a few minutes.

Conclusion

At this point, your DLNA Server should be set up and ready to go once you have placed files in the necessary folders and rebuilt the database.

Having a DLNA Server can make it very nice and handy for a streaming theater experience in your home.

Please do comment if you have any suggestions to make the server better.

NOTE: I thought about KODI and others that present a nice background image and such, but those get way too involved. They require a special naming convention for files. I am trying to make this easy and painless for long-term use. Also, be aware that some of the ‘better’ DLNA Server software is requiring payment for some services.

Posted by Linux Admin