Mounting a BSD home directory on a Mac OS X machine

I just got this working pretty smoothly today, after a bit of struggling. Since I use a Macintosh laptop, but my development machine is a FreeBSD box (the better to match our servers,) I have basically three options:

  1. Use vi on my BSD machine.
  2. Use SCP or SFTP to transfer the files, edit them locally, and then send them back to build and test.
  3. Map the home directory from the BSD box into the OSX environment, and then edit the files locally, and marvel at how everything “just works.”

1 is painful, 2 is slow, and 3 is magic. Is it really any choice at all?

(Note: If you do any of this, and it frazzles your machine, it’s your own damn fault. Proceed at your own risk. No guarantee expressed or implied, blah blah blah.)

Mounting the Volume

The best resource that I found was at the Mac Tech Notes blog. The post covers the basics of using the NetInfo Manager to set up an automount. That means that the share will mount every time you start your Mac, but it won’t actually try to mount until the volume until you access the share. This is especially good for those of us that use a laptop and log in via a VPN, because it won’t time out when you log in.

I added the -w and -i flags to the options. The -w flag mounts the volume in read-write mode. The -i flag tells the system to make an “inconsistent” mount, which will prevent Finder from freezing when you disconnect from the network.

At the end of it all, my mount setup looks like this:

$ nidump -r /mounts .
{
  "name" = ( "mounts" );
  CHILDREN = (
    {
      "type" = ( "nfs" );
      "dir" = ( "/Users/isaacs/DevBox" );
      "opts" = ( "-w,-i" );
      "name" = ( "my.bsd.box.corp.yahoo.com:/home/isaacs" );
    }
  )
}

Of course, this only works if the NFS share is available in the first place. After a bit of poking around and tailing /var/log/messages for errors, I figured out that my machine is in the 10.72.28 network whenever I’m on the LAN, and in the 172.21.163 when I’m logged in through the Santa Monica VPN.

I don’t know if the other VPNs have other network addresses, but they might. To find out these addresses, I ran tail -f /var/log/messages on the BSD box. Then, in another terminal window on the OS X machine, I ran sudo kill -1 `cat /var/run/automount.pid` to reset the automount program, and tried to access the ~/DevBox folder to re-build the mount. You’ll get a permission denied error in the OS X session, and you’ll see the denied IP address in the BSD session.

The exports File

On the BSD machine, I edited /etc/exports to add this:

# when plugged into the LAN, my laptop is in this network:
/home/isaacs -network=10.72.28 -mask=255.255.255.0
# When logged in on the VPN, my laptop looks like one of these
/home/isaacs -network=172.21.163 -mask=255.255.255.0

So, once that was working, I ran these commands on the BSD machine to reset the NFS shares:

kill -s HUP `cat /var/run/mountd.pid`
sudo killall -HUP nfsd
sudo killall -HUP mountd

Then, on the Mac, I ran this to reset the mount:

sudo kill -1 `cat /var/run/automount.pid`

I logged into ~/DevBox, and found all the files there.

User IDs

Unfortunately, the “isaacs” on my Mac is not the same as the “isaacs” in our network. My Mac’s “isaacs” is actually 501, and the isaacs at Yahoo is 24561. (I’m talking about the UID values here.) So, the owner of all the files in ~/DevBox was a mysterious user by the name of “24561″, and I couldn’t edit anything or create any new files without sudo-ing.

The trick was to reset my UID and GID on the Mac to match my identity in the FreeBSD world.

On the BSD machine, I ran id and got this response:

uid=24561(isaacs) gid=100(users) groups=100(users)

On the Mac, I ran the same thing, and got this:

uid=502(isaacs) gid=502(isaacs) groups=502(isaacs), 80(admin)

So, I had to change the UID from 502 to 24561, and the GID from 502 to 100.

First I created another user on my machine with admin privileges. I logged in as that user, and changed isaacs’s UID and GID in the “users” folder of NetInfo Manager. Then, I went into the “groups” folder in NetInfo Manager, and changed the “isaacs” group’s GID to 100. Great, so I changed my UID and GID, but now I don’t have permission to modify any of my files!

On the Mac, I ran this, which I got from a commenter on the Mac Tech Notes blog. His command won’t work, because it’s not formed correctly–the number needs to go BEFORE the {}. This is what you actually have to run. (Replace the numbers with the appropriate values, of course.)

# 502 is the old UID number, and 24561 is the new UID number
sudo find / -user 502 -exec chown 24561 \{} \;
# 502 is the old GID number, and 100 is the new GID number
sudo find / -group 502 -exec chgrp 100 \{} \;

These commands take a while to run, and you’ll get a few “XYZ is not a normal file” and “permission denied” errors as the find command tries to walk over stuff that is not really there. You might want to run them in a subfolder first, just to make sure that they work, before sicking this on /.

Once that was done, everything just worked. Now my home directory on my dev box loads up on demand whenever it can, and I can edit files just as if they were in my local directory structure.

Leave a Reply

Comments are moderated like crazy using a variety of plugins. There is a very high likelihood that your comment won't show up right away, especially if you have never commented here before, but it was not deleted.

Please be patient, and do not post your comment more than once. It will show up once it is approved.

You must be logged in to post a comment.