How to NFS mount an Ubuntu Linux drive in Mac OS X Leopard
-- UPDATED for 9.04 support --
One assumption I have made are that both computers are running on the same network, but they don't have to be. Your Mac needs to be able to "see" your Linux box. If they're on separate networks, you will most likely have to deal with portmaping through routers and firewalls which is still fairly straight forward, but beyond the scope of this document.
I reference my Linux box by name because I have its IP address in my Mac's host file. You don't need this however, and can simply use it's IP address instead.
I also assume you have some rudimentary knowledge of your Mac and Linux, specifically, being able to open terminal windows to get a shell and command line as well as having sudo privileges on your Linux box.
- Before we begin we'll need some information for later. From your shell or terminal window in Ubuntu, execute the id command. You should see something similar to:
uid=1000(doej) gid=1000(doej) groups=4(adm),20(dialout),1000(doej)
All we care about are the uid and gid values for your username. In the output above, we see the uid and gid values are 1000 for the user doej (John Doe).
- Now, execute the same command on your Mac from the Terminal program. You'll notice the output is a little different:
uid=501(doej) gid=20(staff) groups=20(staff),98(_lpadmin)
Note that the uid is 501 and the gid is 20. In my examples, my username is the same between my Mac and Linux, but they don't have to be.
- Save these numbers or shell output for later.
- In Ubunutu make sure you have the following packages installed: nfs-user-server and nfs-common. Do this by executing "sudo apt-get install nfs-user-server nfs-common" from
your shell or terminal window.
NB: this will fail in Ubuntu 9.04 because the brilliant folks at Canonical decided to remove it and I don't know why. However, fear not you can still get the package here. Install this file with the command "sudo dpkg -i
[filename]" - this will error out if you somehow already have the nfs-kernel-server package installed.
- Now we need to make a map of our user and group IDs we obtained in #1 and #2 above. This will ensure that when we NFS mount our drive on our Mac, the permissions and file ownership will all be set correctly. A common directory for this file is in /etc/nfs. If this directory doesn't exist for you, go ahead and create it.
Create a file in this directory called foo.map - it can be called anything, but the naming convention is to use the name of the accessing server, in this case the hostname of your Mac. Mine, creatively enough, has a hostname of mac so my file is called mac.map.
Here's what my file looks like:
# mapping for client: mac
# remote local
uid 501 1000
gid 20 1000
The first two lines are just comments. The second two map the uid and gid from steps 1 and 2 above. Here, remote means your Mac, and local means your Linux box.
- NFS gets its export information (the directories that are allowed to be NFS mounted) from the file /etc/exports. If this file does not exist, just create it. Here's what my file looks like:
The first argument is the directory on Linux that you want to be able to NFS mount. In this case, I've chosen to mount my home directory. The second parameter are the mount options. To see a full list of options, execute man exports. I've listed my Mac hostname as the server that is allowed to NFS mount this directory. The options I've chosen are:
rw - read/write
insecure - allow non-root user to NFS mount directory
map_static - the file we created above that maps our user and group IDs from Mac to Linux box. If you want to be able to write to your NFS mount, you MUST have this option set and set correctly.
- Before you can mount anything on your Mac, you'll need to restart NFS on your Linux box (so it picks up the exports) with the following command:
sudo /etc/init.d/nfs-user-server restart
- Finally, on your Mac, you can mount this drive with the following command:
mount -t nfs bajan:/home/doej /Users/doej/foo
- This will mount your home directory on Linux (bajan is the hostname of my linux box) to the foo sub-directory in my home directory on my Mac. To test everything is working correctly, cd into the foo directory in Terminal and try creating a new file. If you can, you're all set. If not, shoot me a message and I'll try and help you out as best I can.