I decided to move all my important data to the NAS with Raid 1 protection. I need to mount it on all my desktop/laptop so I can access the files easily. Mount to Windows system is extremely easy. However, it takes me a little while for MAC OS. This article is about how to automatically mount SMB drive to MAC OS.
By saying “automatically”, my goal is to mount a Samba or Windows share on MAC OS to a mount point I desired, have it autoremount whenever it is reachable, and have it automatically reconnect after a reboot, and have the share be accessible by all users(root or non-root).
MAC OS comes with a good feature called “automount”, all we need is to edit “/etc/auto_master” file and add the following line to it:
It tells the system to load /etc/auto_smb automatically.
then, edit auto_smb to include all the mount point you want, the format is:
/Volumes/mount/to/point -fstype=smbfs,soft ://user:password@server_ip/share
if you are using guest without password, use:
/Volumes/mount/to/point -fstype=smbfs,soft ://guest:@server_ip/share
Finally, run the command below to enable it, or simply reboot the computer
when you finish all those steps, whenever you try to access the files, the system automatically try to connect to the server.
It’s not a problem to me, but some users report that they cannot access the mounted files as non-root user, looks like it’s a known bug of MAC OS, here is a workaround:
Add the following codes to a script, run it after each reboot. It unmount the mount point with root privileges and adding back using the non-root user:
sudo umount /Volumes/mount/to/point cd /Volumes/mount/to/point