Macs at home; Part 2: NFSHomeDirectory
See the introduction to this post.
Since I sometimes take my MacBookPro out with me it makes sense that I have a local user account to log on. Rebecca’s Mac Mini, on the other hand, never leaves the house. It’s a prime candidate for mounting user home directories over NFS.
To do this we need our friend the automounter. Automounts can be configured in old-skool flat files. They can be imported from LDAP or NIS with the DirectoryService. Or they can be taken direct from NetInfo. That’s what we’ll use here.
Automounts go into NetInfo (under /mounts) as a record whose name is the path to the export, in the form server:/path. You can create them with /Applications/Utilities/Directory Access.app (I believe this is due to be renamed in OS X 10.5) and there are several documents floating around the internet describing how to use that tool. If you understood Macs at home; Part 1 you will probably have guessed that it’s pretty simple to use nicl to set up an automount.
The homedirectories on files are exported as /home so our automount is created like so:
# nicl -create . /mounts/files:\\\\/home
Note the double backslash between files: and /home. This is to escape the / lest nicl interpret it as a separator in the NetInfo hierarchy. The second backslash protects the first from being eaten by the shell.
# nicl . -append /mounts/files:\\\\/home vfstype nfs
This defines the mount as an NFS share.
# nicl . -append /mounts/files:\\\\/home opts -P
This line instructs automount to add the -Poption to mount calls when trying to mount the share. The -P option specifies that a privileged local port should be used. This is required by the NFS daemon on files. It might not be needed on your network. Try it if your NFS server gives a permission denied error when you try to mount the share.
# nicl . -append /mounts/files:\\\\/home opts net
The net option instructs automount to mount the share under /Network/Servers. Since the share is files:/home it will be mounted at /Network/Servers/files/home.
Without the net option you would need to add a dir option with the key being the local mountpoint where the share should be mounted. The problem in this situation is that you then have to choose between mounting /home over /Users – thus trashing local home directories – or adding one automount for each user.
The only remaining step is to restart automount.
# killall -HUP automount
The contents of /home on files will now be available at /Network/Servers/files/home and in particular Rebecca’s home directory is at /Network/Servers/files/home/maling.
There is one sticking point, however. The system expects Rebecca’s home directory to be at /Users/maling. This can be fixed with our old friend dscl.
# dscl localhost -create /NetInfo/Users/maling NFSHomeDirectory /Network/Servers/files/home/maling
Update 2007-10-31: On Leopard the syntax is:
# dscl localhost -create /Local/Default/Users/maling NFSHomeDirectory /Network/Servers/files/home/maling
Auto login
I did have Rebecca’s Mac Mini set up to automatically log on her user account without requiring a password. This won’t work with an NFS home directory, presumably because the LoginWindow races with automount and starts the window manager before the NFS share is mounted. The Mini now boots up to a username and password prompt.
This isn’t a massive issue. After all we now have a machine that is only a few steps away from being usable by multiple users so it makes sense that you’d have to specify which user was at the console. Speaking of which, my next post will discuss LDAP authentication.