Wednesday, August 12, 2015

Linux FIle & Media Server

I had several external usb hardisk. I need to bring them along with my laptop when needed. I though why not create a file server, so that i can still access it anywhere at home. Utilizing one of the cubieboard, i create this file server.

Samba Server
sudo apt-get install samba cifs-utils ntfs-3g dosfstools

add these lines at the end of /etc/samba/smb.conf
[media]
 path = /media
 public = yes
 writable = yes
 comment = smb share
 printable = no
 guest ok = yes
 read only = no
 directory mask = 0777


Network File Server
sudo apt-get install nfs-kernel-server nfs-common

add these lines at the end of  /etc/exports
/media       10.1.1.0/255.255.255.0(rw,sync,no_subtree_check,no_all_squash,no_root_squash)

FTP TFTP
sudo apt-get install ftp ftpd tftp tftpd
for easy acces, lets create symlinks to share folder
sudo ln -s /media ~/.

MEDIA SERVERS
Debian wheezy come up with rygel media server, a part of gnome project. This enable to share your media files trough UPnP/DLNA protocol. You can play it in UPnP/DLNA player such as XBOX, Playstation, Windows media player or other UPnP/DLNA player on your gadget.
sudo apt-get install rygel
Add your media folder (replace below path) in this line at /etc/rygel.conf,
....
[MediaExport]
...
uris=@MUSIC@;@VIDEOS@;@PICTURES@;/media//mp3/;/media/movies/
...
Add rygel to rc.local to enable it at boot time, i use nohup to keep the application run and dump output to /tmp/rygel.log, change this log file path as you need
nohup rygel >> /tmp/rygel.log 2 >> /tmp/rygel.log & 

DISKMOUNT
Create script to mount the disk catagorized as it's label
#-------------------------------------------------------
#!/bin/bash
for i in /dev/disk/by-label/*
do
   a=${i:19} 

   #put your unmounted label disk list in this line
   if [ "$a" == "debian6" ] || [ "$a" == "debian7" ];then
     echo "not mounting $a"

   else
     if ! [ -e "/media/$a" ];then
       echo "crate dir /media/$a"
       mkdir /media/$a -vp
       chmod 0777 /media/$a
     fi
     echo "checking media"
     fsck -vy $i
     echo "mount $a"
     mount $i /media/$a -v
   fi
done

#-------------------------------------------

Call The script from /etc/rc/local, and wait until finished before call others like rygel
./diskmount &&
nohup rygel >> /tmp/rygel.log 2 >> rygel.log &

Mount SMB
mount -t cifs //10.1.1.60/media/data /media/data -o user=me,password=key,rw

Mount NFS
mount -t nfs 10.1.1.60:/media/data /media/data

No comments:

Post a Comment