Send
Close Add comments:
(status displays here)
Got it! This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
Windows file sharing to Linux using cifs and fstab
1. Windows file sharing to Linux using cifs and fstab
Here one way to share Windows folders with a Linux machine is presented.
Warning: These instructions are for a test/development machine for which you are the only user aside from system process users.
Note: You may need to resolve Windows sharing and security issues, which are beyond the scope of this page.
2. Windows shares
Share the Windows folder (and subfolders and files).
3. SMB/CIFS
The following should already be installed.
The following Linux command(s) to install SMB/CIFS for accessing Windows shares.
sudo yum -y install cifs-utils
4. Local mount point
A local mount point is needed. This is usually in the folder
/media which should already exist.
For historical reasons, the local mount point is called
AX8-DATA which shares to Windows machine
AX8 and share name
DATA. I tend to use the
DATA share name on Windows machines, but, on the Liunx side, the names need to be distinct. This, in this case,
AX8-DATA is used from the Linux side for this share.
The local mount point will be
/media/AX8-DATA.
The following Linux command(s) create the local mount point folder
/media/AX8-DATA and assign permissions and ownership.
sudo mkdir /media//AX8-DATA
sudo chmod -R 777 /media/AX8-DATA
sudo chown -R robin:rmsgroup /media/AX8-DATA
sudo chgrp rmsgroup /media/AX8-DATA
5. Mount the Windows share at the mount point
The following Linux command(s) access the Windows share DATA on machine AX8.
sudo mount.cifs \\\\AX8\\DATA /media/AX8-DATA -o user=robin,pass=omitted
Note that double backslashes are needed for the command line mount.
6. List the folders files on the Windows share
The following Linux command(s) list the folders and files on the root of the Windows share.
ls -ls /media/AX8-DATA
Note: If you list the contents and the share is not mounted, no error is issued but a total of
0 is displayed.
7. Unmount the drive
The following Linux command(s) unmount the mounted drive
/media/AX8-DATA.
sudo umount /media/AX8-DATA
8. Determine mounted drives
The following Linux command(s) see all mounted drives.
df -h
On
2019-08-09 the output was as follows.
... omitted ...
\\AX8\DATA 466G 439G 27G 95% /media/AX8-DATA
The mounted Windows share should be visible in the output.
9. Remounting drives
When modifying and testing the boot drive mounts it can be useful to remount the drives.
The following Linux command(s) remount any drives in
fstab that might have changed.
sudo mount -av
On
2019-08-09 the output was as follows.
/ : ignored
/boot : already mounted
/boot/efi : already mounted
/home : already mounted
swap : ignored
10. Mount the Windows share at boot
The above only mounts the Windows share during the current session.
To mount the Windows share at boot the
fstab file needs to be modified.
Be very careful when modifying the
fstab file.
The following Linux command(s) edit the boot time drive mount file
fstab.
sudo nano /etc/fstab
Then make the following changes in the editor at the end of the
fstab file.
\\AX8\DATA /media/AX8-DATA cifs user=robin,pass=omitted,uid=5000,gid=6000file_mode=0777,dir_mode=0777 0 0 -O _netdev
The last option, "
-O _netdev", causes the drive not to be mounted until after the network connection - which is required for access to the remote drive on the local network.
Note: The _netdev parameter is supposed to work, but it did not work for me.
Make sure that
/media/AX8-DATA has been unmounted and remount the drives.
The following Linux command(s) remount any drives in
fstab that might have changed.
sudo mount -av
On
2019-08-09 the output was as follows.
/ : ignored
/boot : already mounted
/boot/efi : already mounted
/home : already mounted
swap : ignored
mount.cifs kernel mount options: ip=192.168.100.131,unc=\\AX8\DATA,uid=5000,gid=6000,user=robin,pass=********
/media/AX8-DATA : successfully mounted
On the next reboot, the share should be avail
able - assuming that Windows machine is available in the same manner as when the share was created and tested.