2

I have a Mac running Monterey connected to a network that has a NAS (Synology, DSM 7.0.1-42218) that has smb shares.

I want my Mac to mount that smb share so that /Volumes/<smb share name> is always always always available as soon as possible during the macOS startup process, and never times out or unmounts for any reason, even in the case of disk failure or network failure.

I do not want this mount to lazily require a keychain UI interaction, I do not want this mount to lazily time out and is be unmounted after some time.

I want this smb share to be seen as the same thing as a local disk and cause errors in the same scenario that a local disk would.

Is there a way to do this?

There is no /etc/fstab in macOS, or similar config file that I can create.

I can write some apple script to "open" the smb share in Finder upon login, but this is after other stuff has run and is too late.

On macOS (Montery and later) how do I automount an smb volume that is on my network at boot time and keep it mounted forever?

4
  • Some use cases: Store Adobe CC library on an smb mount: All Adobe apps I have fail on start up with "Volume/Path" not found" Store Plex media library on an smb volume: Plex on startup finds no media making Plex useless. Dec 12, 2021 at 8:40
  • correction: Adobe CC reports /Volumes/<smb share> is disconnected. Please reconnect to finish. Dec 12, 2021 at 8:45
  • 1
    macOS uses fstab - you just have to create it yourself. idk how to make it force early mount, though; I only ever use it to prevent auto-mount.
    – Tetsujin
    Dec 12, 2021 at 9:17
  • See the comments in this Apple Discussions page.
    – IconDaemon
    Mar 3, 2022 at 20:23

1 Answer 1

1

As you mentioned /etc/fstab, I'm going to guess that you have some familiarity with Linux and therefore systemd. The MacOS equivalent (and inspiration for systemd) is launchd and the units you set up are called Launch Agents or Launch Daemons.

Agents are triggered when someone logs in; Daemons run at boot before anyone logs in.

The only difference is where you put the .plist file that describes them (and that Daemons are managed with root/sudo permissions).

Unless you absolutely require this remote directory to be mounted when nobody is logged in to the machine, I recommend an Agent, as it's much easier to set up.

There's an excellent tutorial on both here: https://www.launchd.info

However, as links are not forever, let me describe how I set up a Launch Agent to do this, and then tell you what modifications you should make to run as a Launch Daemon

I first created a directory under my home directory to mount the remote folder.

I then checked I could mount this at the command line as follows:

mount -t smbfs smb://myuser:mypassword@DS920/RetroArch_Shared /Users/me/RetroArch_Shared

("DS920" is the hostname of my Synology DiskStation 920+).

I then created ~/Library/LaunchAgents/retroarch.shared.plist

<?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>retroarch.shared</string>
        <key>ProgramArguments</key>
        <array>
            <string>/sbin/mount</string>
            <string>-t</string>
            <string>smbfs</string>
            <string>smb://myuser:mypassword@DS920/RetroArch_Shared</string>
            <string>/Users/me/RetroArch_Shared</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
    </dict>
</plist>

I then loaded that Agent with:

launchctl load ~/Library/LaunchAgents/retroarch.shared.plist

and confirmed the mounted resource showed on my Desktop.

I finally confirmed it runs at login by ejecting the disk, logging out and back in again.

If you want to run the same as a Launch Daemon:

  • The plist file needs to go in /Library/LaunchDaemons (note this is not under your home directory).
  • You plist will need to include the name of the user that should perform the action (ideally, your own user account).
  • You will need to load/unload with sudo while testing.
  • You'll obviously need to reboot to test it out, rather than just logging out/in.
  • Making a permanent mountpoint (directory) under /Volumes is not recommended, as that is where mountpoints are automatically generated for thumb drives, downloaded .dmg files, etc.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .