Generally, if you want to mount a network disk when booting a Linux system, you can do so by adding a startup item in /etc/fstab, but the implementation of macOS is slightly different. macOS does this by editing /etc/auto_master, as follows:
# # 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
The /- indicates that the configuration files auto_smb and auto_master are located in the same folder. Then edit the configuration file /etc/auto_smb:
vim /etc/auto_smb
# content is as follows/System/Volumes/Data/samba_mount/share -fstype=smbfs,soft,noowners,nosuid,rw ://username:password@ip-address:/share
://username:password@ip-address:/share is the shared folder content shared by samba on the mount target ip-address. Username and password can be modified according to the 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 just need to prefix the existing automount path with /System/Volumes/Data. This is because macOS will create a second APFS volume for user data, thus moving the existing system installation to the read-only APFS volume.
Also, be careful not to mount directly to /Users/xxx (xxx is the user name), nor to the user's home directory. It is recommended to mount directly to the /Users/xxx/shared directory, so the completed path should be: /System/Volumes/Data/Users/xxx/shared
After configuration, execute the automount command
automount -vc
In Docker Desktop for Mac, the directories that Docker can mount by default include /Users, so you can create mount folders for the corresponding folders in the shared directory under Users, for example: /System/Volumes/Data/Users/Shared/nextcloud. If you create them directly in a subfolder of the /Users/#home directory, autofs will have problems. Also note that the smb user password cannot use @, and for security reasons, it is best to create a separate user for the smb directory and only have secure read and write permissions for this mounted directory. Do not use admin directly.
Note: If the system version is upgraded, the auto_master file will be overwritten and auto_smb will need to be added again.