Aug 302017
 

In my last post, I had promised to come back with a guide on setting up your Pi as a media server. It has been some time now, but here it follows.

Before we begin, how about some insight to media servers and certain technology standard called DLNA?

We all have a lots of media lying around in various storage devices and we(some of us at least) still use the stone age methods of transferring media to our media players(USB stick to use on smart TV, phones, tablets etc.). How good it would be if we were able to access our media right from its source without getting up from the chair!!

Enter media servers. These are a bit of software running on a network connected computer, which organise, and share your media to anyone connected on to the network. To unify the way these network connected devices access media, a certification standard was formulated by various electronics giants like Sony. The basic idea behind formulating this standard was to ensure that media can be accessed across various platforms with ease. So the media content might be on a windows based server but it could be accessed by DLNA compliant devices which could range from a smart TV with proprietary operating system, or a android based mobile phone(android was just in making back then but the standard was platform independent so could be adopted at a later stage easily) or even a linux based computer. More information on DLNA of Digital Living Network Alliance can be found here.

Anyway, if you are following this guide, it means you are a potential candidate to setup media server on your home network. This guide is specific to Raspbian OS and the prerequisites are to have a Raspberry Pi which is connected to your network(via wired network preferably) and your HDDs with the media folders mounted to an accessible folder. You can follow the guides in my previous posts here and here for that.

Let’s begin!!

Login to you pi via SSH. Remember we are running the device headless since we want to conserve the processing power. In case you are still using desktop, you can launch terminal from the desktop.

First ensure that your Raspbian installation is up-to-date. Run the following commands for that.

sudo apt-get update

sudo apt-get upgrade

Next install minidlna using:

sudo apt-get install minidlna

Once installed, backup the minidlna configuration file using:

sudo cp /etc/minidlna.conf /etc/backup_minidlna.conf

Open the minidlna configuration file in nano for editing using:

sudo nano /etc/minidlna.conf

(you can use sudo leafpad /etc/minidlna.conf to open in leafpad in case you are working on desktop instead of terminal)

In the configuration file, find(using up/dn arrow keys) db_dir and set its value to :

db_dir=/home/pi/.minidlna

Remember, most of these settings are commented out using #. Remove the # to uncomment them and make them usable.

Set minidlna media directories to point at the directories which hold your media as follows:

media_dir=V, /media/WD/movies

Here “V” stands for Videos. For specifying aa audio directory, use “A” and “P” for photos . The above line in the configuration file will specify that one of the media directory to scan for video files only is located /media/WD/movies. I have used WD since I have mounted one of my HDD at /media/WD and the “movies” is a folder in that HDD which contains movies. You will certainly have a different configuration so check your setup and edit this line accordingly.

If you are specifying media_dir=V, /XXX/XXXX/XXX, the server will only serve video files to the network. If you do not specify “V”, it will search for all media contents in music, photos, videos. So the line can also be :

media_dir=/media/WD/movies

You can have multiple configuration lines here. But I suggest you organise the media properly before sharing else your media devices will show you a lot of directories and you will find it difficult to locate specific media in them.

In friendly_name suggest a recognisable name. Mine is :

friendly_name=Raspberry Pi MiniDLNA

You can have anything you like.

Uncomment out the inotify=yes so that the server keeps on searching for new media, whenever you add new files.

Now click ctrl+x.. It will as whether to save the file. Select yes. Then run the following commands.

sudo service minidlna restart

sudo service minidlna force-reload

To ensure minidlna service starts at reboot run the command:

sudo update-rc.d minidlna defaults

No go for a reboot once using:

sudo reboot

If you have done everything right, upon reboot you should be able to see your media server on you DLNA compliant devices, or DLNA media player softwares.

Do ping me in case you have trouble.

Jul 232017
 

It’s a very common thing to have multiple hard drives in our possession these days. With all the data and media that we have with us, the inbuilt storage in our computers prove insufficient. External HDDs also provide easy portability for the media. But we always face an issue when we want to share our media or even the HDD space with others in our own home or on our internal network. One solution is to attach the HDD to the computer and configure it as a shared drive. But that would require a computer which is running 24×7 so that the drives are available at any given time to anyone. Not an ideal solution.

Another method is to configure a NAS or Network Attached Storage. NAS is basically a storage attached to a network device(typically a server, but can also be a dedicated controller) which is connected to a network and runs 24X7. You do get NAS devices in market but these devices are typically as costly as a single 2TB drive and are normally beneficial for higher speed transfers. The NAS configuration which I plan to discuss here, will give you transfer speeds of about 4-5 mbps over local network and should be suitable for home/home office networks. And we use a versatile computer which has very low footprint in terms of space and power consumption. The Raspberry Pi is one of the best suited computer board for this project.

Before you go further you need:

  • A Pi with Raspbian installed and connected over you local network. Use this tutorial for the same.
  • A powered USB hub sufficient to power your HDDs. Buy here based on number of HDDs you have

Warning : Do not attempt to power up your HDDs via the Raspberry Pi USB ports since the pi can handle only about 2.5 amps of current through it and may burn out in case overloaded.

So let’s get started.

(Note : This guide has been drafted based on my installation experience, which was further assisted by the guides available at howtogeek.com and instructables.com . Any errors during the installation, you can leave me a note or you can check the guides on their websites. Both websites listed different methods and I couldn’t get mine configured using them individually. But I succeeded when I followed both the guides together)

  • Connect your HDDs to the USB hub and connect the Hub to one of the USB ports on the Pi.
  • Open up shell via SSH( or terminal in case you have connected the keyboard/mouse and screen to your Pi)
  • Run the commands sudo apt-get update and sudo apt-get upgrade to update your Pi installation and repositories.
  • If your HDDs are NTFS format, you will need to run the following command in terminal.

sudo apt-get install ntfs-3g

This will get you Pi ready to understand the ntfs format on your HDDs.

Next step is to identify your drives

  • Type ls –l /dev/disk/by-uuid
  • The output of this command will be similar to below:

clip_image001

  • Here sda1, sdb1, sdc1 denotes the external HDDs. The number will vary as per the HDDs connected by you. We are interested in the 16 digit hexadecimal UUID against each of these. Note down the 16 digit codes and the corresponding HDD identifiers. eg. sda1 – 1C0CA2830CA25812 in the example above.
  • Next run code ls –l /dev/disk/by-label
  • The output will be something like this:

clip_image002

  • As you can see, my labels are Transcend, Storite and WD for sda1, sdb1 and sdc1 respectively. These are the actual labels which you have given to the HDDs. Note these down and match them with the UUID. So in my case it will be sda1 – 1C0CA2830CA25812 – Transcend.
  • Now that we have identified the HDDs, we need to mount these drives. But before that we create a location to mount these drives.
  • Run code sudo mkdir /media/DRIVE_NAME . eg. for my transcend drive, I created directory using sudo mkdir /media/transcend
  • Do this for all the drives that your have connected.
  • Next, mount each drive with the following command for each instance:

sudo mount -t ntfs-3g -o uid=pi,gid=pi /dev/sdxx /media/DRIVE_NAME

  • Where sdxx is sda1, sdb1, sdc1 etc and DRIVE_NAME is the corresponding mount point which you created earlier. So for my transcend drive the command will be:

sudo mount -t ntfs-3g -o uid=pi,gid=pi /dev/sda1 /media/transcend

  • Do this for all the drives.
  • If you have fat32 or ext4 drives, suitably modify the command:
  • ntfs-3g for NTFS drives
  • vfat for FAT32 drives
  • ext4 for ext4 drives
  • The drives should mount everytime we reboot. So we need to add it to startup script.
  • Run sudo cp /etc/fstab /etc/backup_fstab
  • Then run sudo nano /etc/fstab
  • Add the following correspondint to each drive

/dev/sda1 /media/transcend auto noatime 0 0

Use the correct drive identified sdxx and the corresponding correct DRIVE_NAME for each HDD.

  • Restart the Pi using sudo reboot
  • Next step is to install samba.
  • Run sudo apt-get samba samba-common-bin
  • Once installed, backup the samba configuration file before proceeding:

sudo cp /etc/samba/smb.conf /etc/samba/backup_smb.conf

  • Run sudo nano /etc/samba/smb.conf
  • In the configuration file that opens up, ensure that the workgroup is your local workgroup for your network. Ideally its WORKGROUP for windows. Modify it if you are using something else.
  • In the Authentication section, enter security = user to enable verification
  • Now scroll to the bottom of the file and add your drives as follows:

clip_image003

  • Here valid user = @pi is the username I selected. You may select anything you want eg. valid users = @josh .
  • You may also choose to share specific folders inside the HDD instead of the entire HDD. Modify path if that is the case. The read only attribute specifies the modification rights and the no flag specifies that the users on network can read as well as write to the shared drive/folder.
  • Save using ctrl+X, say yes and hit enter.
  • Run sudo /etc/init.d/samba restart
  • Add user to give access to the shared drive
  • sudo useradd josh -m -G users
  • sudo passwd josh
  • You will be prompted to enter a password twice.
  • Next enter the command sudo smbpasswd –a josh
  • Create password on prompt
  • Restart samba using sudo service smbd restart
  • The HDDs should be visible to you on other computers on your network. You can configure it as a network drive. You will need to specify username and password once for access.

Next time, we will see how to configure DLNA server on your Pi to share the media files to your DLNA compliant devices.

%d bloggers like this: