Mounting Shared File Systems on Linux

Introduction

Business systems need to mount the disk of another machine onto the server, allowing the system to directly access data files, making data ETL processing more convenient.

Reference link:

Just a moment…

https://linuxize.com/post/how-to-mount-cifs-windows-share-on-linux/#:~:text=The%20password%20can%20also%20be%20provided%20on%20the,sudo%20mount%20-t%20cifs%20-o%20username%3D%3Cwin_share_user%3E%2Cpassword%3D%3Cwin_share_password%3E%20%2F%2FWIN_SHARE_IP%2F%3Cshare_name%3E%20%2Fmnt%2Fwin_share

Mounting Windows Shared Directory

Select the folder to be shared in the Windows server, right-click – Properties – Sharing (network sharing must be enabled).

Perform the mount operation on the Linux server:

# Create a mount directory
 mkdir /home/aml
# Mount - Method 1
 mount -t cifs -o username=@user, password=@password //IP/share_dir /home/aml
# Mount - Method 2
 mount -t cifs -v -o credentials=/var/pwd //IP/d/data/output /home/aml/                                                                                                                               Password for gmjjb,password=*****@//10.**.**.***/d/data/output:  ********

 # Verify
 df -h
 # Auto-mount
 vi /etc/fstab
 # Add the following content
 //IP/share_dir /home/aml cifs username=@user, password=@password 0 0
 # Or
 //IP/share_dir /home/aml cifs credentials=/var/pwd 0 0

 # Then give the directory read permissions
 # chown -R aml:aml /home/aml
 chmod -R 444 /home/aml

Most Linux distributions come with cifs or samba installed by default, you can check like this:

[root@FXQ-YWYY-57-81 ~]# rpm -qa | grep samba
 samba-common-4.11.12-3.p01.ky10.aarch64
 samba-client-4.11.12-3.p01.ky10.aarch64
 [root@FXQ-YWYY-57-81 ~]# rpm -qa | grep cifs
 cifs-utils-6.10-0.ky10.aarch64

Unmounting Shared Directory

umount /home/aml

Mounting NFS File System

# Create a shared directory
 mkdir /mnt/nfs
 # Mount
 mount -t nfs ip:/path/to/share /mnt/nfs
 # Verify 
 df -h
 # Auto-mount
 ip:/path/to/share /mnt/nfs nfs defaults 0 0
 
 # Unmount
 umount /mnt/nfs
[root@kylinV10arm162 ~]# mount -t cifs -o username=gmjjb,password=*****,vers=2.0 //10.**.**.***/d/data/output /home/aml/99
mount error(115): Operation now in progress
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) and kernel log messages (dmesg)

[root@kylinV10arm162 ~]# dmesg | grep mount
[    3.424827] XFS (dm-0): Ending clean mount
[    5.906981] audit: type=1130 audit(1717645025.410:51): pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=systemd-remount-fs comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
[    6.702559] XFS (vda2): Ending clean mount
[2777460.243716] No dialect specified on mount. Default has changed to a more secure dialect, SMB2.1 or later (e.g. SMB3), from CIFS (SMB1). To use the less secure SMB1 dialect to access old servers which do not support SMB3 (or SMB2.1) specify vers=1.0 on mount.
[2778936.002401] No dialect specified on mount. Default has changed to a more secure dialect, SMB2.1 or later (e.g. SMB3), from CIFS (SMB1). To use the less secure SMB1 dialect to access old servers which do not support SMB3 (or SMB2.1) specify vers=1.0 on mount.

Invalid argument

sudo mount -t cifs -v -o 'username=gmjjb,password=*****,vers=2.0' //10.**.**.***/d/data/output /home/aml/99/
mount.cifs kernel mount options: ip=10.**.**.***,unc=\\10.**.**.***\d,vers=2.0,user=gmjjb,prefixpath=data/output,pass=********
mount error(115): Operation now in progress
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) and kernel log messages (dmesg)
[root@kylinV10arm162 ~]# dmesg | grep mount
[    3.424827] XFS (dm-0): Ending clean mount
[    5.906981] audit: type=1130 audit(1717645025.410:51): pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=systemd-remount-fs comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
[    6.702559] XFS (vda2): Ending clean mount
[2777460.243716] No dialect specified on mount. Default has changed to a more secure dialect, SMB2.1 or later (e.g. SMB3), from CIFS (SMB1). To use the less secure SMB1 dialect to access old servers which do not support SMB3 (or SMB2.1) specify vers=1.0 on mount.
[2778936.002401] No dialect specified on mount. Default has changed to a more secure dialect, SMB2.1 or later (e.g. SMB3), from CIFS (SMB1). To use the less secure SMB1 dialect to access old servers which do not support SMB3 (or SMB2.1) specify vers=1.0 on mount.

# Check kernel logs
[root@kylinV10arm162 ~]# sudo mount -t cifs -v -o 'username=gmjjb,password=*****,vers=1.0' //10.**.**.***/d/data/output /home/aml/99/
mount.cifs kernel mount options: ip=10.**.**.***,unc=\\10.**.**.***\d,vers=1.0,user=gmjjb,prefixpath=data/output,pass=********
mount error(115): Operation now in progress
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) and kernel log messages (dmesg)

# Check if the ping works
ping ip can reach, but telnet ip 445 cannot reach, so the server cannot access the Windows server's shared directory port, the firewall needs to open the port, which requires the network administrator to enable it.

Mounting Errors and Troubleshooting

Permission Denied

[root@kylinV10arm162 ~]# mount -t cifs -v -o 'username=gmjjb,password=*****,sec=ntlmssp,vers=1.0' //10.**.**.***/d/data/output /mnt/99/
 mount.cifs kernel mount options: ip=10.**.**.***,unc=\\10.**.**.***\d,sec=ntlmssp,vers=1.0,user=gmjjb,prefixpath=data/output,pass=********
 mount error(13): Permission denied
 Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) and kernel log messages (dmesg)
  • Port 445 is open
  • The shared path has been confirmed to be correct<span>d/data/output</span>
  • Check if the user password is correct and if this user has access

No Such File or Directory

This is because the shared disk cannot be found

  • Confirm what disk is being shared, here the shared path is <span>d$/data/output</span> not <span>d/data/output</span>
[root@kylinV10arm162 ~]# cat /var/pwd_65 
 username=zgyyb
 password=*****
 vers=1.0
 [root@kylinV10arm162 ~]# mount -t cifs -v -o credentials=/var/pwd_65 //10.**.**.***/d/data/output /mnt/99/
 Credential formatted incorrectly: 1.0
 mount.cifs kernel mount options: ip=10.**.**.***,unc=\\10.**.**.***\d,user=zgyyb,prefixpath=data/output,pass=********
 mount error(2): No such file or directory
 Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) and kernel log messages (dmesg)

 # Check the shared directory disk, note that the disk is d$ not d
 [root@kylinV10arm162 ~]# smbclient -L //10.**.**.***/ -U zgyyb
 Enter SAMBA\zgyyb's password: 

     Sharename       Type      Comment
     ---------       ----      -------
     ADMIN$          Disk      Remote Management
     C$              Disk      Default Share
     D$              Disk      Default Share
     E盘            Disk      
     I$              Disk      Default Share
     IPC$            IPC       Remote IPC
 Reconnecting with SMB1 for workgroup listing.
 do_connect: Connection to 10.**.**.*** failed (Error NT_STATUS_IO_TIMEOUT)
 Unable to connect with SMB1 -- no workgroup available

 # Change the path to d$ and it will work
 [root@kylinV10arm162 ~]# mount -t cifs -v -o credentials=/var/pwd_65 //10.**.**.***/d$/data/output /mnt/99/
 Credential formatted incorrectly: 1.0
 mount.cifs kernel mount options: ip=10.**.**.***,unc=\\10.**.**.***\d$,user=zgyyb,prefixpath=data/output,pass=********
 [root@kylinV10arm162 ~]# df -h
 Filesystem                   Size  Used Avail Use% Mounted on
 devtmpfs                      32G     0   32G   0% /dev
 tmpfs                         32G  192K   32G   1% /dev/shm
 tmpfs                         32G  1.8G   30G   6% /run
 tmpfs                         32G     0   32G   0% /sys/fs/cgroup
 /dev/mapper/klas-root        483G   38G  446G   8% /
tmpfs                         32G  2.2M   32G   1% /tmp
 /dev/vda2                   1014M  222M  793M  22% /boot
 /dev/vda1                    599M  6.5M  593M   2% /boot/efi
 tmpfs                         6.3G     0  6.3G   0% /run/user/993
 tmpfs                         6.3G     0  6.3G   0% /run/user/0
 //10.**.**.*2/d/data/output  500G  395G  106G  79% /mnt/B9
 //10.**.**.***/d$/data/output  200G  169G   32G  85% /mnt/99
 [root@kylinV10arm162 ~]#

Conclusion

Mounting 99

mount -t cifs -v -o credentials=/var/pwd_65 //10.**.**.***/d$/data/output /mnt/99/

Mounting B9

mount -t cifs -v -o credentials=/var/pwd //10.**.**.*2/d/data/output /mnt/B9/

Unmounting

umount /mnt/99
umount /mnt/B9
# Mount 99
mount -t cifs -v -o credentials=/var/pwd_65 //10.**.**.***/d$/data/output /home/aml/99
# Mount B9
mount -t cifs -v -o credentials=/var/pwd //10.**.**.*2/d/data/output /home/aml/B9
# Direct Sales DS
mount -t cifs -v -o credentials=/var/pwd //10.**.**.*3/d/data/ds/ds/output /home/aml/DS

The passwords are stored in <span>/var/pwd</span> and <span>/var/pwd_65</span>.

Mounting Shared File Systems on Linux

The content of this article is my learning record, my knowledge level is limited, and it is only for record keeping~

Mounting Shared File Systems on LinuxMounting Shared File Systems on Linux

Leave a Comment