In order to keep disk usage to the minimum, I share the project's disk images with the virtual machines by means of NFS. (See Mac OS X as an NFS Server for more details.) But in doing so, a problem appears: the NFS daemon is started as part of the system's boot process, long before I can manually mount the disk images. As a result, the NFS daemon — more specifically, mountd — cannot see the exported directories and assumes that their corresponding export entries are invalid. This effectively means that, after mounting the images, I have to manually send a HUP signal to mountd to refresh its export list.
A little research will tell you that it is trivial to mount disk volumes on login by dragging their icon to the Login items section of the Accounts preference panel:

But... that doesn't solve the problem. If you do that, the images will be mounted when you log in, and that happens long after the system has spawned the NFS daemons.
Ideally, one should be able to list the disk images in /etc/fstab, just as is done with any other file system, but that does not work (or I don't know the appropriate syntax). So how do you resolve the problem? Or better said, how did I resolve it (because I doubt it's the only solution)?
It turns out it was not trivial: you need to manually write a new startup script that mounts the images for you on system startup. In order to do that, start by creating the /Library/StartupItems/DiskImages directory; this will hold the startup script as well as the necessary meta-data to tell the system what to do with it.
Then create the real script within that directory and name it DiskImages:
#! /bin/shDon't forget to grant the executable permission to that script with chmod +x DiskImages.
#
# DiskImages startup script
#
. /etc/rc.common
basePath="/Library/StartupItems/DiskImages"
StartService() {
hdiutil attach -nobrowse \
/Users/jmmv/Projects/NetBSD.dmg
hdiutil attach -nobrowse \
/Users/jmmv/Projects/pkgsrc.dmg
}
StopService() {
true
}
RestartService() {
true
}
RunService "$1"
At last, create the StartupParameters.plist file, also in that directory, and put the following in it:
{
Description = "Automatic attachment of disk images";
OrderPreference = "First";
Uses = ("Disks");
}And that's it! Reboot and those exported directories contained within images will be properly recognized by the NFS daemon.I'm wondering if there is a better way to resolve the issue, but so far this seems to work. Now... mmm... a UI to create and manage this script could be sweet.
7 comments:
You've inspired me to find some round tuits for this. On my host Mac, I've set up a read-only NFS export of pkgsrc without any client access restrictions (!). If I tell Parallels to use "shared networking" (NAT), the NetBSD VM says:
mount_nfs: bad MNT RPC: RPC: Authentication error; why = Client credential too weak
(I don't see anything about this in /var/log/* on the Mac.)
If I instead tell Parallels to use "bridged ethernet", the NFS mount succeeds. But since I'm on a wild and woolly university network, I'd very much prefer to use NAT and then restrict the NFS export to clients on the 10. network. Any ideas why this isn't working?
(Also, "showmount -e" works in both cases.)
I use shared networking and hit that problem too.
It was caused by two different things. The first one was that I was using an incorrect IP address to refer to the host machine (NFS server). I gave the mount command the machine's name as handed out by the DNS server, which resolves to the host's external IP address. You have to give it the internal IP address, which in my case is 196.168.200.2.
Second, the firewall was blocking some requests. I had to enable ports 111 and 2049, both UDP and TCP. (It may be possible to fine-tune this some more though.)
After that, it works fine.
Et voilĂ ! I was making the same mistake. Thanks!
Thanks again for this writeup. Here's a trivial tweak to mount disk images listed in /etc/fstab.dmg:
StartService() {
for dmgfullpath in `cat /etc/fstab.dmg`; do
hdiutil attach -nobrowse ${dmgfullpath}
done
}
I'm having trouble with an internal drive failing to mount before login, and my home folder exists on this drive... uh oh! This problem occurs every other boot...
Anyway how might this diy be modified to use scripting to make sure this drive is mounted BEFORE I go to log in?
Matthew: See http://blog.julipedia.org/2007/01/install-mac-os-x-over-multiple-volumes.html
Post a Comment