MacOS – Rename SMB Servers

macosmountNetworksmb

I have 2 SMB servers that I connect to on a daily basis. One is my development server and the other is my production server. Both of them are a little different in the folder structure.

When they are mounted, they take the names of the folder you are mounting. Both servers are mounted on the same folder name so its really hard to tell the difference.

Is it possible to change the name of a mounted SMB server? I would like to just have "Development" and "Live".

Best Answer

  1. auto_fs method

The two shares will be mounted automatically.

Please create a Share folder and two folders Development and Live inside of that in your User folder and change your auto_master with sudo nano /etc/auto_master to

/etc/auto_master

#
# Automounter master map
#
+auto_master                        # Use directory service
/-                                  auto_smb    -nosuid
/net                                -hosts      -nobrowse,hidefromfinder,nosuid
/home                               auto_home   -nobrowse,hidefromfinder
/Network/Servers                    -fstab
/-                                  -static

and create a file with sudo touch /etc/auto_smb and add with sudo nano /etc/auto_smb the content

/etc/auto_smb

/Users/username/Share/Development -fstype=smbfs,noowners,soft ://user:password@dev-server_ip/Shared_Folder
/Users/username/Share/Live -fstype=smbfs,noowners,soft ://user:password@prod-server_ip/Shared_Folder 

for AD-members

/Users/username/Share/Development -fstype=smbfs,noowners,soft ://DOMAIN\;user:password@dev-server_ip/Shared_Folder
/Users/username/Share/Live -fstype=smbfs,noowners,soft ://DOMAIN\;user:password@prod-server_ip/Shared_Folder  

Both files ("auto_master" & "auto_smb") need a trailing empty line

change the file root only readable:

sudo chown 600 /etc/auto_smb

enter sudo automount -vc in Terminal with the output:

$ sudo automount -vc
automount: /Users/username/Share/Development updated
automount: /Users/username/Share/Live updated
automount: /net updated
automount: /home updated
automount: no unmounts

Please regard the output: /Users/username/Share/Development or Live updated

(I've tested this with Mac OS X 10.10.1 (as client) & Windows Server 2012 R (Active Directory) in a VirtualLab. It worked without any problems and survived any restart. The following workarounds weren't necessary for me.)

If the shares aren't mounted with correct access rights (e.g. root only) you may have to unmount it with sudo umount /Users/.../sharesand remount it with `cd /User/.../shares.

An automatic approach with launchd is the following solution:

Create a script:

while ! mount | grep "map auto_smb on /Users/user/Share  
do  
        sleep 2  
done  

if ! mount | grep "mount .* mounted by user"  
then  
        sudo umount /Users/user/Share/Development
        sudo umount /Users/user/Share/Live
        sudo -u user cd /Users/user/Share/Development  
        sudo -u user cd /Users/user/Share/Live
fi  

(i don't know if line 1 in the script is correct)

and save it somewhere e.g. /Users/user/bin/remount.sh.

To call the script as a LaunchDaemon, you have to create a plist in /Library/LaunchDaemons similar to this:

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"     "http://www.apple.com/DTDs/PropertyList-1.0.dtd">  
<plist version="1.0">  
<dict>  
          <key>Label</key>  
          <string>com.organization.remount</string>  
          <key>ProgramArguments</key>  
          <array>  
                    <string>/Users/user/bin/remount.sh</string>  
          </array>  
          <key>RunAtLoad</key>  
          <true/>  
</dict>  
</plist>  

The string com.organization.remount is also the name you will have to give the file, with the extension plist: "com.organization.remount.plist".

The string /Users/user/bin/remount.sh is the path to where you saved your script.

2. Windows Server2008r2 command line-method (if you have admin rights and access to the servers)

really quick and dirty: net share <sharename=drive:path>

Example:
net share Live=C:\Data (on the production server)
net share Development=C:\Data (on the development server)