In this guide we will learn how to Mount Windows Shares on Linux using autofs. CentOS 6.3 machine and a windows 7 machine will be used to perform this task.
A share folder is available on windows 7 machine named win-share. We will mount this share folder using autofs on CentOS.
Let’s get started.
`Windows PC Details :
Win7.broexperts.com |
|
IP Address | Â 192.168.0.201 |
Shared Folder | Â win-share |
Mount Point on Linux | Â /win-share/share |
Step-1
Open up terminal on Linux machine and enter the following command:
# yum install -y autofs cifs-utils
Command Output :
Loaded plugins: fastestmirror, presto
Loading mirror speeds from cached hostfile
* c6-media:
Setting up Install Process
Resolving Dependencies
–> Running transaction check
—> Package autofs.i686 1:5.0.5-54.el6 will be installed
—> Package cifs-utils.i686 0:4.8.1-10.el6 will be installed
–> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
autofs i686 1:5.0.5-54.el6 c6-media 492 k
cifs-utils i686 4.8.1-10.el6 c6-media 46 k
Transaction Summary
================================================================================
Install 2 Package(s)
Total download size: 537 k
Installed size: 3.1 M
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 537 k
——————————————————————————–
Total 55 MB/s | 537 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : 1:autofs-5.0.5-54.el6.i686 1/2
Installing : cifs-utils-4.8.1-10.el6.i686 2/2
Verifying : cifs-utils-4.8.1-10.el6.i686 1/2
Verifying : 1:autofs-5.0.5-54.el6.i686 2/2
Installed:
autofs.i686 1:5.0.5-54.el6 cifs-utils.i686 0:4.8.1-10.el6
Complete!
[root@w1 ~]#
Step-2
Now Edit /etc/auto.master file and add below entry after /misc /etc/auto.misc line
# vi /etc/auto.master
/win-mount /etc/auto.win-mount
This means we are going to mount some share folder at /win-mount and for the details read following file /etc/auto.win-mount.
Save & Exit
:wq
Step-3
Now create directory on Linux which we mentioned in auto.master file.
# mkdir /win-mount
Step-4
Create auto.win-mount file under /etc/ and add below line into this.
# vi /etc/auto.win-mount
Add following line
share -fstype=cifs,credentials=/etc/user-pass.txt ://192.168.0.201/win-share
This entry means, mount win-share as sub-folder of win-mount directory with the name of share. Which means “ls /win-mount/share” command will display the contents of //192.168.0.201/win-share
Save & Exit
:wq
Step-5
Now create credentials file and provide windows machine username and password to access windows shares from Linux
# vi /etc/user-pass.txt
username=administrator
password=Hello12
Save & Exit
:wq
Step-6
At last restart autofs service
# service autofs restart
Verify if windows shares are mounted on Linux.
# ls /win-mount/share
1 2 3 4 New Text Document.txt
Step-7
Verify mounted share using disk free command.
# df -kh
Filesystem Size Used Avail Use{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} Mounted on
/dev/mapper/VolGroup-lv_root
1.5G 704M 739M 49{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} /
tmpfs 250M 0 250M 0{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} /dev/shm
/dev/sda1 485M 38M 422M 9{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} /boot
/dev/sr0 3.5G 3.5G 0 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} /dvd
//192.168.0.201/win-share 8.0G 6.8G 1.2G 85{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} /win-mount/share
Everything looks perfect, hope its all clear, if you need any further help please use comment section.