macOS: How to mount a SMB share from the command line A small guide explaining how to mount a UNC/SMB share between a macOS environment and other mac/win/linux systems and access it from the command-line.

macOS: How to mount a SMB share from the command line

Today I had to build one of my Electron-based apps for macOS, so that it could be installed and executed on macOS. If you know Electron, you most likely know that its native multi-platform capabilities are great: you just have to run the builder from the same OS you want to build your executable installer for; in case you don't, well... you can make amend by reading this post or just skip such topic entirely, since it's not what we'll be talking about in this post.

Anyway, I don't own a macOS, therefore I use a Virtual Machine with macOS Mojave (aka 10.14) to deal with such kind of tasks: I just launch the VM, clone (or update) my Electron project with GitHub and use NPM or YARN to build (or update) the node_modules folder: once done, I can build it with electron-builder or some similar tools. Pretty easy, isn't it?

However, today I managed to further improve such technique by finding a way to entirely avoid the GitHub clone/download/NPM part, thus saving a valuable amount of disk space on my VM: I was able to do that by using a SMB share from my Windows host PC to the macOS VM... Which brings us to the main topic of this article.

What I am about to describe below is a UNC/SMB share between Windows and macOS, but the same procedure can also be used (with very minor differences) to connect any kind of SMB share.

Creating the UNC/SMB Share

The first thing I did was to share my /Projects/ root folder using a standard Windows UNC share: I assigned read and write permissions to a protected user (let's call it User) with a strong password (for example, Pass).

Mounting the SMB Share

Right after that I switched to the macOS VM and used the mount_smbfs command (a shortcut for mount -t smbfs) to mount the share to the /Volumes/Projects folder in the following way:

... and that's it! Once done, I was able to navigate to the /Volumes/Projects/ folder and execute the electron-builder command-line tool from the macOS terminal without having to locally clone/download all my projects.

Common errors

As we can see, I had to create the /Volumes/ and /Mount/Projects/ folders first, in order to avoid the following error message:

mount_smbfs: could not find mount point /Volumes/Projects: No such file or directory

It's worth nothing that you might also catch the following (misleading) error message:

mount_smbfs: mount error: /Volumes/Projects: File exists

Such error message might let us think that A) there is already a non-empty folder on that location, or B) we have already mounted a share there: right?

Well, it might definitely be the case, and the first thing we should do is to check for both of these scenarios... However, that same error message can also occur if that share has been mounted elsewhere: this can easily happen if you've already done these steps in the past, maybe using a different folder than /Volumes/Project.

Luckily enough, you can easily check which devices are mounted by using the df command: the system will show you a list of active shares, with both the SMB share name (host/folder) and the local mounting point: with these info, you'll be able to quickly check if there's an active mount point for that share and unmount it accordingly (or just use it instead!).

Conclusion

That's pretty much it: I definitely hope that this post will help those system administrators and/or IT developers who are looking for a quick and easy guide to perform these mounting steps from macOS!

 

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

2 Comments on “macOS: How to mount a SMB share from the command line A small guide explaining how to mount a UNC/SMB share between a macOS environment and other mac/win/linux systems and access it from the command-line.

  1. You may want to let people know that your suggestion won’t work at all because you need root permission to create a directory under /Volumes.

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.