Settings up NFS from a FreeBSD client to a Linux server
Tagged:  •    •    •    •  

I think it won't ever happen to me that NFS will 'just work'. During the process of getting server and client work together, you'll almost always encounter at least one permission denied, go to hell.

The reason I wanted to set up NFS (Network File System) was because I made my VirtualBox disk image too small, where FreeBSD resides. It became tricky to do a system upgrade with the famous make buildworld command set. So that's why I wanted to reside the /usr/obj directory somewhere else. That means I had to set up a NFS share on my Gentoo Linux host system such that the FreeBSD guest system could connect to it.

It took me a full afternoon to get it right, but it appears to be working now. I wanted to share the steps with you.

Let's do the easiest thing first. Create a folder on the server which you want to be mounted. Let's use /tmp/obj.

Server (Gentoo Linux)

  1. Prepare the kernel, which means at least enabling these options:
    Filesystems --->
      Network File Systems --->
         <*> NFS server support
         [*] Provide NFSv3 server support
  2. Then, make sure you have the nfs-utils package installed:
    emerge nfs-utils
  3. Now, define what you want to share. Open the file /etc/exports in your favorite text editor and add the following line:
    /tmp/obj 192.168.1.0/255.255.255.0(async,rw,no_subtree_check,insecure)

    Make sure to put the options no_subtree_check and insecure in this entry. If you forget the first one, exportfs will complain sooner or later.
    The insecure option is also important. At first I didn't include it, which resulted in errors like:

    [udp] hostos:/tmp/obj: Permission denied

    at mount time. Luckily the server was more descriptive:

    Nov 24 17:01:25 hostname mountd[5239]: refused mount request from 192.168.1.101 for /tmp/obj (/tmp/obj): illegal port 33113

    So that means it expected to be a port in the 'secure' range, i.e. below 1024. The insecure option takes care of that.

  4. Start the services required to do the mounting:
    # /etc/init.d/nfs start

Client (FreeBSD 6.2)

  1. Add the following lines to /etc/rc.conf:
    nfs_client_enable="YES"
    nfs_client_flags="-n 4"
  2. Start the required services for mounting NFS shares:
    # /etc/rc.d/nfsclient start
  3. Now is the magic moment: mount it!
    mount_nfs 192.168.1.101:/tmp/obj /usr/obj

So if all went well, the filesystem is now mounted in /usr/obj such that you can start compiling on that too small disk.