Create a Permanent SMB Mount in OSX (Updated)

Creating an permanent SMB mount in OSX is not so easy. Maybe some day Apple will make it a little bit easier, but if this is something you’re looking to do, check out the solutions below. If you have any tips, make sure to share it in the comments!

There’s a couple of few options for creating a permanent mount in OSX. Unfortunately option #1 did not work for me (I’m running OSX 10.8) (see update below!).

Mavericks users, please use Option 4 (see update below)!

Option 1

The first option is to modify the /etc/auto_master (sudo vi /etc/auto_master) file and add the following line:

/- auto_smb -nosuid

Then, I created an /etc/auto_smb (sudo vi /etc/auto_smb) file that contained the following:

/Volumes/mount_point -fstype=smbfs,soft ://user:pass@smbserver/share

Next, run the following command to update your settings:

sudo automount -vc

A few notes:

  • The soft parameter specifies OSX to not halt on failure to connect to the SMB server during boot.
  • When entering the password, it’s better to URL encode it as some special characters will cause the automount to fail silently.
  • This option didn’t work for me after I ran the sudo automount -vc command :-) (I got a “Host is Down” error when trying to cd to the mount point) (see update below!).
  • nosuid parameter in the /etc/auto_master file prevents OSX from mounting the resource as readonly by root (see update below!).

Option 2

The second option is the vifs command. Again using the terminal type in sudo vifs and then insert the following line:

smbserver:/share /Volumes/mount_point url automounted,soft,url==cifs://user:pass@smbserver/share

Then run sudo automount -vc and then cd to your mount point and it should connect.

Option 3

This option is courtesy of a Guest commenter (thanks, whoever you are!):

  1. Connect to your network drive (finder > go > connect to server)
  2. Enter the infos for your login to your network drive and tick the ‘remember in keychain’
  3. Open system settings > users > login items
  4. Drag the icon for your network drive from your desktop to the startup items.

If you use this option, make sure you read my comment below.

Option 4 (Mavericks users)

Modify the /etc/auto_master (sudo vi /etc/auto_master) file and add the following line:

/- auto_smb -nosuid

Create a folder on your system to place your mount in:

sudo mkdir /mnt

Create an /etc/auto_smb (sudo vi /etc/auto_smb) file that contains the following:

/mnt/mount_point -fstype=smbfs,soft ://user:pass@smbserver/share

Next, run the following command to update your settings:

sudo automount -vc

A few notes:

  • The soft parameter specifies OSX to not halt on failure to connect to the SMB server during boot.
  • When entering the password, it’s better to URL encode it as some special characters will cause the automount to fail silently.
  • nosuid parameter in the /etc/auto_master file prevents OSX from mounting the resource as readonly by root (see update below!).

Update 08-24-2012: Option #1 above actually works. The underlying issue is that in my situation, I need to go through Active Directory to authenticate. If this is the case, use the following syntax in your /etc/auto_smb file:

/Volumes/mount_point -fstype=smbfs,soft ://DOMAIN\;user:pass@smbserver/share

Note that you’ll have to escape the semicolon (;). Also, if you’re connecting to a hidden share (i.e. a $ share), you’ll need to escape that too:

/Volumes/mount_point -fstype=smbfs,soft ://DOMAIN\;user:pass@smbserver/share\$

Update 04-26-2013: As a commenter indicated below, you may want to chmod the auto_smb file to 600. If you’ve run into the issue where root is the only one allowed to read/write to the mount, doing this will set the necessary permissions for the SMB share (particularly when your system reboots). I will verify this when I get the chance. Thanks Jeremy!

Update 07-01-2013: Ok, well looked into this more and I think I finally found a solution to the issue where root is the only one allowed to read/write to the mount. I first tried Jeremy’s recommendation, however, his suggestion did NOT work for me. It’s important to note that you should still chmod the auto_smb file to 600 so that the file is only readable by root. This provides an extra security layer especially if you’re specifying a password to access your SMB mount. Anyway, I really wanted to figure out a solution, so I did a little bit more research and found this link. What one user recommends is to use the -nosuid option in your auto_master file:

/- auto_smb -nosuid

Now, after you save the file, make sure you run:

sudo automount -vc

The last command is required for this to work. Once I did that and I rebooted, the SMB shares were immediately available (i.e. they were NOT owned by root)!

Update 01-13-2014: Looks like Apple has done some changes to Mavericks that affect the /Volumes folder, which will directly affect users attempting to use the above instructions. According to Alex R, Mavericks won’t allow any other folders in the /Volumes folder, for reasons unknown. The fix is to simply use a mount point at a different location. In Alex R’s case, instead of using /Volumes, try using /mnt instead. I have yet to verify this as I haven’t installed Mavericks yet but it sure looks like Alex R figured it out. Thanks Alex R!

See blogspot.com

Tagged with: , , , , ,
Posted in Apple, Articles
  • Doc. Caliban

    Hello,

    Thank you for this!

    I am having an issue due to my share name having a space in it. I have tried replacing the space with %20 but it will still not mount. Any ideas?

    • http://www.dforge.net/ ronaldcs

      Try escaping the space by putting a backslash in front of it, for example:

      /mount_point -fstype=smbfs,soft ://user:pass@smbserver/share name

  • Stompel

    Hi

    I know i m late heheehe.
    i tried the first option.
    It mounts but doesnt show me any of my data?
    My automaster look slike this at the mo:

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

    /hosts -hosts -nobrowse,hidefromfinder,nosuid

    Is there something wrong here?

    • http://www.dforge.net/ ronaldcs

      Hmm I don’t see anything wrong here, but I suspect it’s something in your auto_smb file.

  • Jeremy

    I can confirm the auto_smb method works in mountain lion however I ran into an issue preventing deletion of files or creation of folders after the initial reboot. I found on another site where they set permissions on auto_smb to 600 and this appeared to be the missing link in the setup for my purposes.

  • crocell

    “Maybe some day Apple will make it a little bit easier”

    Why dont you try this :

    - connect to your network drive (finder > go > connect to server)

    - enter the infos for your login to your network drive and tick the ‘remember in keychain’

    - open system settings > users > login items

    - drag the icon for your network drive from your desktop to the startup items.

    • http://www.dforge.net/ ronaldcs

      Hi, thank you for the suggestion! Note, however, the main issue with this is if the resource isn’t immediately available when your system boots, an error will pop up indicating that the resource cannot be connected to, at which point, there’s no option to attempt to reconnect to the resource (i.e. you’re dead in the water again). This scenario will particularly be evident with wireless-only computers such as the Macbook Pro Retina. However, I think this will work for a bulk of the users out there, particularly those with wired connections.

      With the automount method, errors are done silently and if the mount is not connected, when an application attempts to write to the mount, it will automatically be mounted.

      Again, thanks for sharing!

  • Fgaumond

    Hi, that’s sounds like a great solution, but I’m not able to access my drives, it says “Too many users”, but when I use “connect to server” with the same credentials and network path it worked, any ideas ?

    Thanks

    • http://www.dforge.net/ ronaldcs

      Hi! You may want to ensure you URL encode (http://meyerweb.com/eric/tools/dencoder/) your password, especially if you have special characters in it. I ran into that error before and the “Too many users” problem was because my password wasn’t URL encoded. Let us know how it goes!

      • Fgaumond

        You are totally right ! I needed to encode my password. I should have noticed…

        Really great solution !

        I hope that Apple will improve that in future releases, otherwise we are all glad that you are here to help us figure that out !

        Thanks a lot for your solution, I’ve lost a lot of time trying to figure out how to acheive that.

      • Fgaumond

        The only weird thing, is that my applications (like Word or Excel) are not able to access the drives (either in read or write). But I can read and write in the finder..

        I’ve done the sudo 600 on the auto_smb file.

        Anyone has experience that kind of behavour ?

        • http://www.dforge.net/ ronaldcs

          Hmm I have not experienced that. Do you access the file via the mount point? For example, I use an IDE (PHP Storm) to modify my development files. I access the mount point in the Volumes folder (i.e. /Volumes/MYSERVER/c/inetpub). Is this how you’re connecting to your file from Excel?

          • Fgaumond

            It seams working fine now… I didn’t do anything, but it’s working.. Maybe a reboot does it.

            Thanks again man, you’re a genius !

  • Stephen Silbert

    I’m using the option 1. Though I specify -nosuid the smb share is still owned by root:wheel. And it’s mounted (autofs, nosuid, auto mounted, nobrowse). The “nobrowse” is a real deal breaker! I’ve played with mount and mount_smbfs and seem to get the same results. If I login to the share using the finder it works fine but dragging the share into login items (option 3 above) doesn’t work as you describe for these wireless laptops. I’m beginning to suspect the configuration of the share but any help is welcome.

    • http://www.dforge.net/ ronaldcs

      Hmm did you try:

      sudo chmod 600 /etc/auto_smb
      sudo automount -vc

      Then try rebooting?

      • Stephen Silbert

        Yup. I’m going to try a different smb share and see what happens. Thanks for the quick reply.

  • MC

    I was delighted to find this several months ago to automagically allow Crashplan to backup my Mac to a NAS drive at home, but alas…

    It would seem that OS 10.9 Mavericks includes updates that Apple made to the networking stack which results in Option 1 failing to work now. Based on some other research, I’ve tried shifting from smb to cifs and some other things, but the drive still reports as “mountpoint unavailable” when I automount is run. Bummer.

    If anyone else ferrets out an update to this, I would appreciate it!

    • http://www.dforge.net/ ronaldcs

      That’s unfortunate. I was hoping this wouldn’t break in Mavericks, but thank you for the heads up. I’ll be installing Mavericks soon; I’ll need to upgrade Parallels first. Maybe someone will come up with a fix by then!

      • http://noldorin.com/ Alex R

        Regrettably this is happening for me too on OS X 10.9.1 (latest)… I’d just stumbled across your blog and thought I’d found a wonderful solution! Will post back if I somehow manage to resolve this.

        • http://www.dforge.net/ ronaldcs

          Just purchased Parallels 9 so I’ll be making the upgrade to OSX 10.9 sometime this week. Hopefully we’ll figure it out :-).

      • http://noldorin.com/ Alex R

        Okay, so there’s some really informative stuff on this subject over at
        https://discussions.apple.com/message/23650970#23650970. Basically, it turns out to be a bad idea to use /Volumes for automount points, since it’s Finder’s own mount point, which it manages as it sees fit. Indeed, you should find that if you mkdir in /Volumes before running automount, it works, but then the directory disappears after rebooting, which is no surprise really if Finder considers itself the owner and manager of the /Volumes dir.

        Now, the solution for me was creating a /mnt root directory and using that; i.e. in my auto_smb file having something like:

        /mnt/Home-Share-A -fstype=smbfs,soft smb://admin@Home-Share-A/

        Since /mnt is not expected to be used by anything else on OS X, the mounting and unmounting seems to work perfectly there, and the mountpoint dir never gets deleted.

        Hope that helps!

  • http://about.me/michaelkaufman Michael Kaufman AIA

    I hate admitting it, but I have wandered out of my area of knowledge and have to ask for an assist. I can access terminal but actually doing any of the actions (particularly for Mavericks, option 4) is way beyond my comfort zone. Some simple (aka step-by-step) instructions would be tremendously appreciated!

    • http://www.dforge.net/ ronaldcs

      Hi Michael,

      Have you ever worked within the terminal before? All of the commands in Option 4 will need to be done in the Terminal App.

      • http://about.me/michaelkaufman Michael Kaufman AIA

        I have used the terminal… but only by following step-by-step directions (think “Terminal for Dummies”).
        That being said, I believe that I have gotten to the end of the instructions in step 4. After entering the “sudo automount -vc” command, I received the following:
        automount: /net updated
        automount: /home updated
        automount: no unmounts

        Now, if that is all what’s meant to be… what next?

        • http://www.dforge.net/ ronaldcs

          Hi Michael,

          That list should also include your SMB mount(s). Did you do the following:

          1. Open a terminal and type sudo vi /etc/auto_master

          2. Go to the end of the file by using the arrow keys.

          3. Type the letter i. At this point, you’re in “INSERT” mode, which should be indicated at the bottom of the terminal window.

          4. Insert a new line with /- auto_smb -nosuid

          5. Hit the “esc” key and then type :wq

          6. Now you’re going to create the auto_smb file, so type in sudo mkdir /mnt/share

          7. Now sudo vi /etc/auto_smb

          8. Type the letter i again, then type /mnt/share -fstype=smbfs,soft ://user:pass@smbserver/share

          9. Hit the “esc” key and then type :wq

          10. Lastly, sudo automount -vc

          Hope this helps,

          Ron

  • Martin Jönsson

    So, I’ve done the mount according to the Mavericks instructions, but I’m having some problems. For one, the mount seems to automatically mount as root only, meaning I have to do “sudo umount” and then navigate to it, in the terminal, as a user before I can even access it. Also, it fails to automount when iTunes is trying to access the library files I have stored on it. Instead, iTunes simply fails, reverts to the default library location and complains when it can’t find any files. (I have my library files locally on my computer, and the “media” storage on my NAS.)

    This solution seems to work only sometimes, and especially breaks on reboots. It works perfectly when merely sleeping the computer, however, as I never have any problems reconnecting once I’ve fixed all the errors from bootup.

    Any ideas?

    • http://www.dforge.net/ ronaldcs

      Not sure why it would break after boot/reboot. What do you have to do in order to get it to work after you reboot? Are you on wireless?

      • Martin Jönsson

        I am on wifi, yes. I haven’t done any rigorous testing, but it seems I have to unmount it as root, then do a “cd” into the directory as a user, in order for the share to mount properly.

        I’ve used a similar method before, using automount but with AFP instead. I’ve reverted to that, and I’m going to do some testing. Hopefully that will be more stable.

        • http://www.dforge.net/ ronaldcs

          Understood. Maybe it has something to do with OSX attempting to mount before a wifi connection is established. And if you haven’t already tried, make sure you have the -nosuid flag in your auto_master file and that you created the mount in a directory other than Volumes. Good luck!

Flattr this
Popular Posts
Recent Comments