Saturday, May 17, 2008

Automounting Kubuntu NFS Shares in OS X Leopard

I discovered this feature in OS X Leopard by accident. I thought I was sshed into my Kubuntu home server. I was having some problems with my NFS sharing setup across my MacBook Pro and Kubuntu boxes. I resolved the problem very easily by editing the nfs defaults file and making sure stats and idmap2 were enabled.

I was still having problems with a Seagate external USB drive. I had previously dealt with the problem of the drive going to sleep forever by using sdparm to change the sleep timeout to a day and had a cron script tap the drive twice a day. But the drive had been getting noticibly louder from constantly spinning. A little research turned up an elegant fix using udev to set the drive can be restarted /sys filesystem attribute to true on creating the device node for the drive.

Here's the trick for reference:

$ cat /etc/udev/rules.d/local.rules
# Seagate FreeAgent allow_restart fix (i/o errors)
SUBSYSTEMS=="scsi",DRIVERS=="sd",ATTRS{vendor}=="Seagate*", ATTRS{model}=="FreeAgent*",RUN+="/bin/sh -c 'echo 1 > /sys/class/scsi_disk/%k/allow_restart'"

Now back to problem of the drive not mounting on boot. I decided to install the autofsd and automount tools. So that whether or not the drive showed up at at a different SCSI device address it would mount at the same place. I also wanted any access to the Seagate external drive to kick off a mount if the Seagate external USB wasn't already mounted and for the filesystem to be umounted when idle.

Using automount/autofs would kill two problems I was having. The first problem was that the drive wasn't unmounting before it went to sleep. Leaving the filesystem locked and mounted to the ghost device. The second problem was that I couldn't count on the drive being at the same device name. I'm using the drive as the location of my MythTV recording directory and for my shared network file storage.

Enabled auto.misc in /etc/auto.master and added these lines to /etc/auto.misc:

mythtv -fstype=reiserfs :LABEL=500gusb
ubuntu -fstype=iso9660,loop,ro :/mythtv/downloads/ubuntu-8.04-desktop-i386.iso

I tried to get them to mount off the root filesystem but that is apparently a no no for automounting. At least it didn't work for me. A little filesystem linking covered that up. Notice the fine LABEL= device syntax. :) I added the Ubuntu ISO automounting and sharing so my other Kubuntu boxes could upgrade using the CD over NFS. I left the autofs loop in there since it is pretty light weight. It only mounts the image on access and unmounts it while idle. It inspired me to fiddle with the /etc/auto.master on all the Kubuntu boxes and enable Allowing me to access the shared automounted filesystems with a simple reference to /net/<hostname>/<sharename>.

The /etc/exports (I decided to export each automount individually because NFS complained in the logs about exporting /misc even though it worked with the crossmount option.):

/misc/mythtv *.local(rw,async,nohide,no_root_squash,no_subtree_check,insecure)
/misc/ubuntu *.local(rw,async,nohide,no_root_squash,no_subtree_check,insecure)

Which brings me back to my original point of accidentily finding that Mac OS X Leopard is using the proper script and that it is enabled by default. Meaning ls /net/<hostname>/<sharename> automounts NFS shares - no configuration needed. Allowing me to get rid of my netinfo custom automounts located under /mounts in the local netinfo directory. I then turned my /mythtv directory into a link using sudo -s and then ln -s /net/<hostname>/misc/mythtv /mythtv (I don't give my everyday account blanket sudo permissions ergo sudo -s first in order to execute a command without explicit sudo rights being granted).

One final note. Don't let the Finder make your links for you. The aliases Finder creates are not soft links and are invisible to the POSIX subsystem and even some Cocoa apps. Found that out the hard way. Even scared me for a bit after all that fine setup work. Nearly wiped the smug look off my face.


Octopulous said...

Mr. Lawson,
I believe that you have confused facts in the nano-processor that is your brain. Please refer to the T3 Titanium Alloy - "Liquid Metal" user's guide for clarification of the issues specific to registrant's supplemental application manifestation observable influence characteristics for further enlightenment. Regards. Rude.

DanyelLawson said...

Is that you Mr. Pajooh?

Octopulous said...

Perhaps so. For confirmation, please refer to the most recent issue of 'Where ever you go, there you are'.