Monday, February 11, 2013

Mount Linux directory on Windows using Samba

I am writing this article for those who are interested in doing SAMBA share configuration between Linux and Windows machines. At the end of this article you will also find the steps to mount a Windows shared folder on Linux server using CIFS (common internet file system).

Samba Overview:
---------------
1. Uses Session Message Block (SMB) protocol.
2. The most typical reason to use Samba is to allow windows machine and linux machine to interact.
3. Simple to Complex configurations.
4. Easy to manage as there is one main Samba Configuration file /etc/samba/smb.conf

We are going to setup a Oracle Linux box so that certain directories and files are shared and we can control how they are shared weather it should be read only or read write. Then from the windows machine we can access that linux share and vice versa. You can also interact between two linux machines using Samba protocol.

Smb.conf layout:
----------------
There are 4 special sections in Samba configuration files as given below,

[global] Global Configuration Settings
[homes] Shares users home directories -> Any setting in home section will override the global settings.
[printers] Define shared printer access
[userdefined] This will be a user defined section

step1:
cd /u01
mkdir expdump
chmod 777 expdump/
chown -R oracle:oinstall /u01/expdump


step2: Example of a user defined section is as given below,
[expdump]
comment = Export Datapump dump location
path = /u01/expdump
available = yes
valid users = oracle

readonly = no
browsable = yes

public = yes
writable = yes


There are zillion (exaggerating) more parameters used for different settings like require passwords, limit by host, limit by time of day etc.

step3:
service smb restart --> Restart the samba service.
smbpasswd -a oracle ---> this will add new user for samba which is different from OS user oracle.

step4: Now you can go to windows server and map network drive for \\linuxservername\expdump share folder. This way the linux shared folder is accessible from windows machine and vice versa.

Installing Samba
Login in as root and query if the following rpm's are installed or not if the following packages are not available then firstly install them using rpm command,

#rpm -ivh

[root@egdodb samba]# rpm -qa | grep xinetd
xinetd-2.3.14-10.el5

[root@egdodb samba]# rpm -qa | grep samba
samba-common-3.0.33-3.7.el5
samba-3.0.33-3.7.el5
samba-common-3.0.33-3.7.el5
samba-client-3.0.33-3.7.el5
system-config-samba-1.2.41-3.el5

Configuring Samba:
------------------
You can configure samba by various ways, like manually updating the smb.conf file, using yast utility on suse linux, using SWAT Samba Web Admin Tool and using 'webmin' web based tool. The following is the manual way of updating the smb.conf file,

Update the smb.conf file manually and then run the 'testparm' command to validate the smb.conf file entries,

[root@egdodb samba]# testparm smb.conf

Load smb config files from smb.conf
Processing section "[homes]"
Processing section "[printers]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions

[global]
workgroup = MYGROUP
server string = Samba Server Version %v
passdb backend = tdbsam
cups options = raw

[homes]
comment = Home Directories
read only = No
browseable = No


Mounting Windows share on Linux server using CIFS

The following are the steps to mount a windows shared folder (\\filesrv\LOGDIR) on linux machine.

[root@egpodb01 tmp]# cd /tmp
[root@egpodb01 tmp]# mkdir logdump
[root@egpodb01 tmp]# chmod 777 logdump
[root@egpodb01 tmp]# mount -t cifs //filesrv/LOGDIR -o username=samimalik,password=***** /tmp/logdump
[root@egpodb01 tmp]# df -h /tmp/logdump/
Filesystem                Size    Used   Avail   Used%     Mounted on
//filesrv/LOGDIR     100G  50G    50G     50%        /tmp/expdump

For any further queries please don't hesitate to email me on samiappsdba@gmail.com