Friday, January 3, 2014

MK802+ as a home server (Part 4) : a permanent mount and SMB server for the home network

So , If you've been following the other posts of the series , you'll know that now we've so far installed a debian server with a webmin web ui on it.

In this post, i intend to setup a permanent mount of a Flash Drive and a shared folder from inside this flash drive to be accessed by a windows client. The fixed drive is going to be also used as a scratch disk for the transmission-daemon later, in order not to use the SD that has the system for the same purpose.

I assume that you're connected to the device using SSH with the root account. I use putty for that purpose as i am working from a windows machine

Flash drive at a fixed Mount:

I. [Optional ] Formatting the flash drive as XFS

Since i intend to use the flash drive for samba , after some research , i found that XFS filesystem is the most recommended for file server. To format the flash drive with XFS , you can use webmin  or install the xfsprogs package and continue using ssh.

to list the connected devices use the command

fdisk -l

your flash disk should be shown as /dev/sda (can be also shown as /dev/sdb or sdc according to the number of usb connected drives)

of course to use xfs file format i will install xfsprogs package, if it wasn't already installed
apt-get install xfsProgs

and to create the xfs partition i used the command
mkfs.xfs -f /dev/sda


anyway , now I want to mount it. So,  I create a mount point (an empty folder which will be replaced by the disk content when the disk is mounted) :
mkdir /mnt/DownloadDisk

to test the mounting
mount /dev/sda /mnt/DownloadDisk

II. Choosing the fixed mount point



Now the most important part is making it a fixed mount

First of all , we ought to know that linux mounts are stored in the /etc/fstab file , we need to edit that file in order to have our mount work on each boot of the system. Before we do any editing we should have a backup. You can use the cp (copy) command to make a backup

cd /etc
cp fstab fstab.BAK

The next step is editing the fstab file. we do so by the following command:
vi /etc/fstab


Add this line at the end of the file (press "a" to enter the editing mode) . You should replace sda with identifier of your drive

/dev/sda     /mnt/DownloadDisk    auto     defaults            0       0   


When you're done, press , then ":" , then write "wq" (for write and quit) and finally . This will save the file.

Now that you've finished editing the fstab file , reboot the device , and make sure that you can access the drive by

cd /mnt/DownloadDisk

If you want to understand the fstab file structure , go here

SMB server setup:
In this part i intend to use samba server to enable a folder on the fixed mount to be available for reading by the windows machine. All i need is to setup a directory in which all the completed downloads will be moved and hence be shared to the other machines in my network.

considering you're the root , enter the following command from your ssh client

apt-get install samba 

Next step will be setting up a windows share. For this part , I will use webmin's module for samba management
Installation:
1- Open the webmin interface 
2- Go next to webmin-> webmin configuration -> webmin modules
3- Choose "Standard module" , press the button and choose "samba"
4- Click on the "Install Module" button

If you did everything correctly you should have a similar interface (webmin => Unused modules => Samba Windows FileSharing):


before proceeding , i created a directory inside the mounted volume to work as the share
mkdir /mnt/DownloadDisk/Downloads
We need to create a user name to be used from the other windows machines , instead of using the root password.. All the following steps can be performed easily with webmin (users and groups module) , i just want to do it using the terminal as a personal preference.

To create a group
groupadd DownloadsAccess

so in the terminal , create a user , replace username by the name you user name you want to add:
adduser username

add the user to the group
usermod -a -G GROUPNAME USERNAME

so my command will look like

usermod -a -G DownloadsAccess username


We need to give access to the group on the created Donwloads directory
So i modify group ownership of the folder

chgrp DownloadsAccess Downloads


Then i assign the folder's group write and read access permission
chmod -R g+rw /mnt/DownloadDisk/Downloads/


now we have to make samba aware of our user:

smbpasswd -a username

It will prompt for a password , you can enter the password that you're going to use for this user name when connecting from other machines.

1- Next will be to add a share with the "Create a new file share" link

2- In the create file share window, add the user group to the valid user.

3- Up to now i have a read file access on whatever files put in \\MyServer\Downloads , which is the goal of this section.

Here is a test from my windows machine where i could connect to the drive:




This step actually concludes the post

Read more:
http://lwn.net/Articles/476263/

No comments:

Post a Comment

I'd like to read your comments

Popular