← Go back
macOS mount to openBSD NFS shares

I have been using Vagrant & Virtualbox for a long time but recently I’ve run into something which I believe is a bug somewhere betweek macOS, nfsd, Virtualbox & openBSD.

OpenBSD

The issue started after upgrading OSX to macOS Sierra, Virtualbox to 5.1.8 & Vagrant to 1.6.8. What were the issue and the facts?

  • I was creating shared folders through the Vagrantfile which exported them from macOS to openBSD
  • openBSD was mounting drives from shared directories in macOS
  • After accessing the openBSD “side” of shares, everything worked fine as usual.
  • But when I was trying to do something that made significant access to the share, macOS crashed and rebooted.
  • I must have worked on this for about ~20 hours
  • Macbook must have been restarted about ~40 times

Some of the things I’ve tried:

  • Used the default supported sharing system of virtualbox which is RSync for openBSD. This is one-way sync and very slow so not exactly what I wanted. We got also a strange merge in our git repository because it seemed that things were re-commited and I suspect RSync for this. Virtualbox does not support its 2-way sync in openBSD but even If it could, it’s very slow.
  • Used every setting I could and was supported in Vagrant/Virtualbox/nfsd related to the NFS shares, among them different NFS versions, TCP/UDP etc.
  • Tried to use samba as an alternative. I didn’t think to add the shares to the /etc/fstab file so I was unsuccessfully trying to make them work with sharing-light and usmb packages.
  • I tried almost every Virtualbox and Vagrant versions combination. What finally worked was downgrading to Vagrant 1.7.4 and Virtualbox 5.0.18. But not for quite long, because after 2 days, I tried to untar an 140MB tarball file and then the issue reappeared.
  • Installed the latest Virtualbox test build in case it has been solved. Failed.
  • Installed Virtualbox from the official downloaded packages. Uninstalled and install it again by homebrew. Failed.
  • I installed Vagrant & Virtualbox on my Kali Linux v2.0 laptop. A lot of identical issues on the debian/ubuntu bugtrackers. Finally after 1 hour I was able to make it work. Everything worked fine with all tools and NFS. Apparently this confirmed a compatibility issue of Virtualbox with macOS, running openBSD as a guest.
  • Changed network interfaces from the Virtualbox settings page. Checked virtualisation settings in BIOS.
  • Installed openBSD 5.9 & 6.0. No change.

There are a lot of bugs regarding compatibility of Vagrant and Virtualbox. Among them, Vagrant <1.8.6 seem to support Virtualbox 5.0.18 but it doesn’t. I was getting a message telling me that I need to install a Virtualbox version >4.x when I’ve already had installed 5.0.18.

Then I tried to upgrade Virtualbox to 5.0.20 and the problem came up again in its full extend. It seems that something has changed around 5.0.18 - 5.0.20 that broke the compatibility between Virtualbox, nfsd and macOS. There was no hope. Then a colleague suggested to try something like reversing the NFS shares. This is how I tried that:

  • I used sudo vifs in macOS to change the /etc/fstab file in order to add the mount to the NFS share:
192.168.10.25:/home/vagrant/shared_dir /Users/username/shared_dir nfs resvport
  • I added an export to the /etc/exports file in openBSD:
/home/vagrant/shared_dir/ -network=192.168.10 -mask=255.255.255.0 -alldirs -mapall=<your_username_here>
rcctl enable portmap mountd nfsd
rcctl set nfsd flags -tun 4
# after making changes to the export file
rcctl reload mountd
  • I mounted all the fstab included drives in macOS
mount -a

And finally I was able to share the directory I wanted from openBSD to macOS.

But I had a problem with permissions on macOS which was that I couldn’t read or write to the share. I created a user with the same username in openBSD and assigned him the same uid and gid with macOS. I don’t know If there are arguments to add uid/gid to a user in a simple command (e.g. adduser) but as far as this worked I’m fine:

# to get the id info of the user, do this both in openBSD and macOS.
# in my case they were uid=502, gid=20
id my_username
# create a user in openBSD with the same name as in macOS
useradd my_username
# assign uid and gid
usermod -u 502 my_username
usermod -g 20 my_username

and everything from this point worked perfectly!


References:
http://www.cyberciti.biz/faq/apple-mac-osx-nfs-mount-command-tutorial

Set up Vagrant otherwise re-invent the wheel