I have come to a very good place with my media server setup using my Raspberry Pi. The whole thing is accessible using the network, over a wide range of devices which is ideal for me and the other people living in my house.
If you don’t need to see any of the installation, the following software is running on the server: Samba, Minidlna, Deluge & Deluge-Web and NTFS-3G.
The combination of all of this software allows me to access my media and files on pretty much any device I would want to. This is a great combination of software to run on your Pi if you’re not doing anything with it.
So let’s begin with the install!
I’m using the latest build of Raspian, the download and install of that is pretty simple, instructions here.
Unless you can hold your media on the SD card your Pi’s OS is installed on, you’ll need some kind of external storage. In my case, I’m using a 3TB external HDD.
We’ll need to mount this drive, I’ve already written a post on how to do this, check that out here.
Now we should involve Samba. Again, it’s a pretty simple install.
1 |
sudo apt-get install samba samba-common-bin |
Once it installs you should already see signs of it working. If you’re on windows, make sure network sharing is on, and browse to the “network” folder. It should show up as “RASPBERRYPI” as seen in this image:
The only real tricky part is configuring it. Here is an untouched version of the samba config file. On your pi, it is found at:
1 |
/etc/samba/smb.conf |
There are only a few differences between the standard version and the version I’m using. The biggest one being the actual “Share” being used seen here:
1 2 3 4 5 6 7 8 9 10 |
[HDD_Share] comment = External HDD Share path = /media/USBHDD browseable = yes read only = no valid users = YOURUSER #IF ON A BASIC RASPBERRY PI, US THE USER "pi" only guest = no create mask = 0777 directory mask = 0777 public = no |
Basically, this shares the external HDD you just mounted to the network. You can insert this share anywhere in your document and it will work. Once you update your config file, you have to add your user to samba. If you haven’t done anything but install raspbian, your username on the pi should still be “pi” so the following should do the following:
1 |
sudo smbpasswd -a pi |
Enter your new samba password twice and then you’re good to go after restarting samba.
1 |
sudo /etc/init.d/samba restart |
In windows you can go to “network” option in My Computer and see your share.
If you’re like me though, you’re going to want multiple users for multiple shares. Samba only can only have users that are members of the system, so in order to add a new user to samba, you have to add a user to the Raspberry Pi. For example, let’s add the user ‘testuser’:
1 2 3 4 5 6 7 |
sudo mkdir /home/testuser/ sudo useradd -d /home/testuser -s /bin/false -r testuser sudo passwd testuser sudo chown testuser /home/testuser sudo chgrp users /home/testuser sudo smbpasswd -a testuser sudo /etc/init.d/samba restart |
I have written a bash script to do this automatically.
On the share level, the line of valid users =
should be set to whichever user you want to be able to use the share.
That’s pretty much it for Samba. I’m probably going to do a guide on accessing your shares via SSH tunneling when the need for me to do so arises. I’ll link that here if it ever happens. Now on to minidlna.
MiniDLNA is a very lightweight DLNA server. DLNA is a protocal specifically for streaming media to a huge array of devices from computers to iOS devices or gaming consoles or smart TV’s. I have spent quite a bit of time using minidlna, and have reached a configuration that works extremely well with the raspberry pi. The install is very easy, much like samba, it’s the configuration that is tricky.
1 |
sudo apt-get install minidlna |
The config file i’m using is found here. There Pi actually handles the streaming really really well, and there only a few things you need to change in the config file, and they are mostly aesthetic. The following lines are examples of media locations for each type of file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# If you want to restrict a media_dir to a specific content type, you can # prepend the directory name with a letter representing the type (A, P or V), # followed by a comma, as so: # * "A" for audio (eg. media_dir=A,/var/lib/minidlna/music) # * "P" for pictures (eg. media_dir=P,/var/lib/minidlna/pictures) # * "V" for video (eg. media_dir=V,/var/lib/minidlna/videos) # # WARNING: After changing this option, you need to rebuild the database. Either # run minidlna with the '-R' option, or delete the 'files.db' file # from the db_dir directory (see below). # On Debian, you can run, as root, 'service minidlna force-reload' instead. media_dir=A,/media/USBHDD/Documents/Media/Audio media_dir=P,/media/USBHDD/Documents/Media/Images/Photos media_dir=V,/media/USBHDD/Documents/Media/Video media_dir=/media/USBHDD/Documents/Media/ |
And changing this line will change the name of the DLNA server on the network:
1 2 |
# Name that the DLNA server presents to clients. friendly_name=Raspberry Pi DLNA |
That’s pretty much all there is to it.
You can stream the files all over the place, the following images show it being used on my kindle and another computer. I stream files to my xbox 360 all the time.
The last major component of this media server is Deluge, let’s proceed with that install.
Deluge is a torrent client for linux servers. The coolest part is it has a very good web based GUI for control. The install isn’t too straightforward, but there is no real specific configuration. The following commands will get things up and running.
1 2 3 4 5 6 7 8 |
sudo apt-get install python-software-properties sudo add-apt-repository 'deb http://ppa.launchpad.net/deluge-team/ppa/ubuntu precise main' sudo apt-get update sudo apt-get install -t precise deluge-common deluged deluge-web deluge-console sudo apt-get install -t precise libtorrent-rasterbar6 python-libtorrent sudo apt-get install screen deluged screen -d -m deluge-web |
And there you go! You can now torrent files directly into your Samba shares which is hugely useful and more secure, the following is me doing just that:
The last thing that needs to be done is run a few commands at boot, particularly mount the HDD and start deluge-web. The easiest way to do this crontab. First run:
1 |
sudo crontab -e |
Then add the following two lines:
1 2 |
sudo mount -t ntfs-3g /dev/sda1/ /media/USBHDD/ screen -d -m deluge-web |
So it looks like this:
And everything will start working upon boot!
Thank you very much for reading. If you have any questions, please leave a comment.