一般linux系统要想开机挂载网络磁盘,都是通过在/etc/fstab里添加启动项来实现,但是macos的实现却不太一样。macos是通过编辑/etc/auto_master来实现,如下:
#
# Automounter master map
#
+auto_master # Use directory service
#/net -hosts -nobrowse,hidefromfinder,nosuid
/home auto_home -nobrowse,hidefromfinder
/Network/Servers -fstab
/- -static
# SAMBA AutoFS
/- auto_smb
Where /- indicates that the configuration file auto_smb and the auto_master file are located in the folder of the same path. Then edit the configuration file /etc/auto_smb:
vim /etc/auto_smb
# 內容如下
/System/Volumes/Data/samba_mount/share -fstype=smbfs,soft,noowners,nosuid,rw ://username:password@ip-address:/share
://username:password@ip-address:/share is the content of the share folder shared via Samba on the target ip-address. Modify username and password according to your actual situation.
/System/Volumes/Data/samba_mount is the mount path in macOS, and the mount path must be placed under /System/Volumes/Data
Official statement:
If you are using macOS Catalina 10.15 and macOS Big Sur 11 (and above)
You only need to prepend /System/Volumes/Data to the existing automount path. This is because macOS creates a second APFS volume for user data, thereby moving the existing system installation to a read-only APFS volume
Also, note that you should not mount directly under /Users/xxx (where xxx is the username), meaning do not mount directly under the user's home directory. It is recommended to use the /Users/xxx/shared directory, so the complete path should be: /System/Volumes/Data/Users/xxx/shared
After configuration, execute the automount command
automount -vc
Since in Docker Desktop for Mac, the directories that Docker can mount by default include /Users, you can create corresponding mount folders in the shared directory under Users, for example: /System/Volumes/Data/Users/Shared/nextcloud. If you create it directly in a subfolder of the /Users/#home directory, autofs will have issues. Also note that the SMB user password cannot contain @, and for security reasons, it is best to create a separate user for the SMB directory who only has secure read and write permissions for this mount directory, rather than using admin directly.
Note: If you upgrade the system version, the auto_master file will be overwritten, and you will need to add auto_smb back in.