Mount network drive to Mac server on boot

launchdmount

Is it possible to mount a network drive to my Mac server on boot, without requiring a login? I have one setup to mount on login via an automator script that I have added to the login items for the user account, which works fine.

The reason is I don't want to have to login to the Mac server, just to mount the network drive.

Best Answer

Simply create a launch daemon with the purpose to mount a remote share:

  1. Create a mountpoint:

    sudo mkdir -p /Shares/mntpoint1
    
  2. Add a launch daemon in /Library/LaunchDaemons:

    sudo nano /Library/LaunchDaemons/local.mount.extvol.plist 
    

    with the content:

    <?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>local.mount.extvol</string>
        <key>ProgramArguments</key>
        <array>
            <string>/sbin/mount_afp</string>
            <string>afp://user:password@remotehost/share/</string>
            <string>/Shares/mntpoint1</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
    </dict>
    </plist>
    
  3. Load the daemon with

    sudo launchctl load /Library/LaunchDaemons/local.mount.extvol.plist 
    

The remotehost and share have to exist and the user has to have permissions to access the share with the password. The user doesn't have to be root!

The share will be loaded with root:wheel 700 permissions.