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.