Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Mounting network volumes at boot time

I found a way to automatically mount network volumes at startup when the machine boots that I thought might be useful to someone else.


I use my Mac Mini as a server for my Apple TV, so I need iTunes to be running when my Mac starts up. I have my Mac setup to auto login as my user account and start iTunes at login time. All my media is stored on a Network Attached Storage (NAS) system.


I found that my Mac slows down after several days of up time, so I added an automatic reboot in the root crontab, to reboot each night. I added auto mounting of these media volumes for my user account in System Preferences:Users and Groups:Login Items. This didn't work. The volumes mounted, alright but they mounted after iTunes started. The result being that iTunes can't find the media library.


I needed a way to have these media volumes mounted before my user login occurred, so that when iTunes loads, the volumes are already mounted. This was my solution.


I created a script with these contents:

#!/bin/bash

cd ~myaccount

echo waiting for nas...

until /sbin/ping -c2 -t5 nas ; do

sleep 5

done

echo mounting home...

su myaccount -c '/bin/mkdir -p /Volumes/home; /sbin/mount -t afp afp://myuser:mypassword@nashost/home /Volumes/home'

<add any other mount statement here>


The ping loop is need to ensure that the NAS server is up before mounting any volumes from it. I found without it, the volumes would not mount. In this example, myaccount is my Mac user account, myuser and mypassword is my authentication for the NAS and nashost is the name of my NAS server, /home is the volume on the NAS server and /Volumes/home is my mount point. In my /Users/myaccount directory, I've created a symbolic link that points to /Volumes/home/Music:

cd ~

ln -s /Volumes/home/Music .


I placed the script in /var/root, then edited the root crontab and added this line:

(you need to do a sudo -i before doing this)

@reboot /var/root/myscript > /tmp/mylog 2>&1

This redirects any output to a file /tmp/mylog which can be used to debug the script, if it fails. You also need to do a chmod u+x myscript to make it executable.


(To edit the root crontab, my favourite method is to create a file called, "crontab", edit this file, then type "crontab crontab".)


The reason for the su myaccount commands, is that if the file system is mounted directly by root, then the volume mount point will be owned by root.


Now when my Mac reboots, it automatically mounts all the volumes I have specified in my script before my user login occurs.


I'm also curious to know if you have another or better way to do this?





Mac mini (Mid 2007), Mac OS X (10.7.5)

Posted on Dec 15, 2013 12:11 PM

Reply

There are no replies.

Mounting network volumes at boot time

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.