Mount Volume from NAS through SMB

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Mount Volume from NAS through SMB Mon May 05, 2014 1:14 pm • by Woohoo
Hi all,

I used to have some rules to mount a NAS shared Folder through AFP. It first checks if the Volume is available:
Code: Select all
if [ -d "/Volumes/Resources" ]; then exit 1; else exit 0; fi


if not, it mounts it:
Code: Select all
tell application "Finder"
   try
      mount volume "afp://User:Password@NAS._afpovertcp._tcp.local/Sharename"
   end try
end tell


This worked for me for a very long time. But not anymore.

How can I change these scripts (especially the second one) to mount a SMB volume.
The reason for it is that, don't ask me why, my iMac has a lot of trouble mounting AFP volumes, and no issue at all mounting SMB volumes. I use a Synology NAS, and my iMac is running OSX 10.9.2.
The fact that Apple is moving form AFP to SMB, as of OSX Mavericks, is another reason I want to change my rules.
I googled a lot about mounting SMB through Terminal, but I couldn't find a solution that really works.
FWIW, I'm not a terminal pro ...
Woohoo
 
Posts: 10
Joined: Sat May 11, 2013 11:13 am

Re: Mount Volume from NAS through SMB Mon May 05, 2014 2:48 pm • by Mr_Noodle
This is a bit outside of Hazel so you might want to try a more general forum on some other site. I do suggest you test your script outside of Hazel though.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Mount Volume from NAS through SMB Wed May 07, 2014 8:44 pm • by Smudge
Woohoo, I might be able to help out here. There are a few things to be aware of.

First, make sure you have updated your Synology to the latest DSM. The last few updates have specifically addressed AFP mounting issues.

Second, OSX Mavericks doesn't like it when there are other mounts in the /Volumes/ directory that it isn't directly controlling via Directory Services. Whenever you reboot, it clears out the /Volumes directory. This means the /Volumes/Resources mountpoint holder (the empty directory) doesn't exist and so your mount command will fail. If you insist on it being in this location, you should adjust your first script to create the directory if it doesn't exist. Here is what it should be (but keep reading for a better option)
Code: Select all
if [ -d "/Volumes/Resources" ];
  then exit 1;
  else mkdir /Volumes/Resources && exit 1 || exit 0;
fi


So, you should move your Resources mountpoint to a different location. For example, a subfolder within your own home folder. If you have multiple user accounts on your Mac and you want all users to be able to access the mount, don't mount it in your home dir as they won't have access. You should mount it at /Users/Shared/Resources since everyone has access to /Users/Shared/.

One side issue here is that the mounted volume icon will not appear on the Desktop. If you want it there, make an alias of it from the /Users/Shared/ folder onto your desktop.


Finally, a good option for this scenario is to stop using your scripts and configure the mount using the OSX automount system. If you attempt to access the directory where the share is mounted and it isn't, the automount will automatically mount it for you! (aren't computers amazing?!?)

To do this, you will need to be a bit more comfortable with Terminal and the command line. I'll assume that you are not and will be using some simplified commands and editors.

I will assume that your computer is only for you and you don't have multiple user accounts. So instead of the share being mounted in the /Users/Shared/ folder, we will mount it into your own home directory (and I'm assuming your username is 'Woohoo')

Create an empty folder named 'Resources' in your home folder.
Code: Select all
cd ~
mkdir Resources


Now create an automount map file for your network share. Since it needs to be done with the root user, we will use sudo. When you run the command, it will ask for your password.
Code: Select all
sudo nano /etc/auto_synology

This creates a new file and places you into the nano text editor. Simply copy/paste the following line, which is a simple example of mounting the Synology public share as a guest user. Obviously this will only work if you have your Synology 'public' share available to guest users.
Code: Select all
/Users/Woohoo/Resources afp://;AUTH=No%20User%20Authent@NAS._afpovertcp._tcp.local/public


If you have set up your Synology with users and passwords, you will want to use this line instead. Substitute the username:password part as necessary.
Code: Select all
/Users/Woohoo/Resources afp://username:password@NAS._afpovertcp._tcp.local/public


Once you have pasted one of the above lines, press control+x to exit out of nano. When you do, it will ask if you want to save the file. Answer Y and it will then ask for the file to save, which it will already have '/etc/auto_synology' added in for you so just press Return.

Now we will need to edit the automount master file to tell it about your new map file.
Code: Select all
sudo nano /etc/auto_master


It will probably look like this
Code: Select all
#
# Automounter master map
#
+auto_master      # Use directory service
/net         -hosts      -nobrowse,hidefromfinder,nosuid
/home         auto_home   -nobrowse,hidefromfinder
/Network/Servers   -fstab
/-         -static


Simply add the following to just above the +auto_master line.
Code: Select all
/-         auto_synology


So the completed file should look like this
Code: Select all
#
# Automounter master map
#
/-         auto_synology
+auto_master      # Use directory service
/net         -hosts      -nobrowse,hidefromfinder,nosuid
/home         auto_home   -nobrowse,hidefromfinder
/Network/Servers   -fstab
/-         -static


Like before, press control+x to exit/save

Now tell automount to reload the configuration.
Code: Select all
sudo automount -cv


Run the mount command to see the list of mounted shares.
Code: Select all
mount


If everything was done correctly, you should see the automount map entry and the public mounted share onto your home/Resources folder.

Code: Select all
map auto_synology on /Users/Woohoo/Resources (autofs, automounted, nobrowse)
//Woohoo@NAS._afpovertcp._tcp.local/public on /Users/Woohoo/Resources (afpfs, nodev, nosuid, automounted, nobrowse, mounted by Woohoo)


Switch back to the Finder, go into your home dir and open the Resources folder. Hopefully you see the files from your Synology public share.

Now go disable your previous mounting scripts :)

I hope this helps.
Smudge
 
Posts: 34
Joined: Mon Jul 15, 2013 10:44 pm

Re: Mount Volume from NAS through SMB Thu May 08, 2014 3:43 am • by Woohoo
Smudge,

Thank you very much.
That is a very thorough reply and I really enjoyed reading it, and learned something about how OSX treats its mounted volumes.
But all I see and read is a solution for mounting AFP shares.
The problem I have, is that the AFP file service from Synology (DSM 5 with all latest updates) drops every now and then, and that I can't rely on them. So I was looking for a solution like you described, but one that mounts SMB drives.
Just changing AFP to SMB in the scripts you provided won't do the trick.
Woohoo
 
Posts: 10
Joined: Sat May 11, 2013 11:13 am

Re: Mount Volume from NAS through SMB Thu May 08, 2014 4:33 am • by Smudge
Might want to dig into why AFP is dropping on your Synology, perhaps call Synology support. I have multiple Syn boxes with dozens of Macs constantly accessing them and haven't had that kind of problem.

By using automounter instead of your current method, OSX is keeping the mount connected and you shouldn't see it drop. If it does, automounter will reconnect and you might see a slight pause in access but it won't be a complete drop like you are seeing now.


However, if you still want to switch, the method is the same whether you want to use SMB or something even more robust like NFS. automounter supports all of the common file types.

You would just need to change the auto_synology map file to the following
Code: Select all
/Users/Woohoo/Resources smb://username:password@NAS._smb._tcp.local/public


It might not resolve the _smb._tcp.local service name to the IP properly though. It depends on your DNS configuration of your network. If your Synology has a static IP, use that instead.
Code: Select all
/Users/Woohoo/Resources smb://username:password@192.168.1.3/public



P.S. Just a bit more FYI. Hazel uses the OSX Spotlight metadata system for a lot of its checks (like if the file is a movie or audio) but that metadata will not be available to files on the Synology. If you have any Hazel rules using these types of checks, you will run into problems.
Smudge
 
Posts: 34
Joined: Mon Jul 15, 2013 10:44 pm

Re: Mount Volume from NAS through SMB Thu May 08, 2014 12:32 pm • by Woohoo
Smudge

Thank you so much for your clear explanation, and addition to your previous reply.
I certainly will contact Synology Support about the dropping of AFS.
Woohoo
 
Posts: 10
Joined: Sat May 11, 2013 11:13 am

Re: Mount Volume from NAS through SMB Fri May 09, 2014 3:19 pm • by Mr_Noodle
Thanks Smudge for the very detailed post.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Mount Volume from NAS through SMB Sun Oct 26, 2014 8:07 pm • by DLK
Hello,

I am trying to mount an afp shared drive for all users in a mac. I am able to mount it by each user separately. This means that if the mac is turned on, just the first user connected get access to the network drive in the specific mount point. If switch of user occurs the new one logged in receives an alert of "No sufficient Permissions" or something like that.

I have to unmount from the first logged user in order to give access to the second user. Thus switching between users accessing the same shared drive is not possible.

I tried to mount it in the Shared folder, but there it is worse; Neither of both users have access to the mounted drive. I think is something in the permissions of the mount point folder. But I cannot find the correct permissions until now.

Someone of you have experienced something like this?

Thank you for reading me.
DLK
 
Posts: 1
Joined: Sun Oct 26, 2014 7:54 pm


Return to Support