Solved OS X file sharing thru SMB/NFS from VBox guest?

I am running FreeBSD 9.2-RELEASE as a guest OS in VirtualBox 4.3.6 on my MacBook Pro. Since the shared folders features of the virtualbox guest additions is not supported, I was wondering if I could connect to a shared folder by SMB. On my Mac, I have file sharing set to "on" for the folder (freebsd-files) I would like to share, and I have selected the option to share using SMB.

OS X tells me I can connect at smb://my-mbp (that's all the information I can find at the moment).

From FreeBSD, I tried running mount_smbfs using the man page examples to connect, but it doesn't work:

Code:
# mount_smbfs //lionoceros@my-mbp/freebsd-files /mnt
mount_smbfs: can't get server address: syserr = Operation timed out
# mount_smbfs //guest@my-mbp/freebsd-files /mnt
mount_smbfs: empty share name

How do I connect to my Mac folder from virtual FreeBSD?

Also, I have the VirtualBox network attached to NAT. Should this be Bridged Adapter or something different?
 
Re: Connect to OS X file sharing through SMB from Vbox guest

"can't get server address" most likely means DNS is not available. If you don't have working DNS from your local DHCP server, enter the Mac's IP address and name in /etc/hosts.

Bridged networking can be faster than NAT in VirtualBox, but either will work.
 
Re: Connect to OS X file sharing through SMB from Vbox guest

Ok, I found the IP address (on the local network—the 192.168...). I also switched to bridged networking in VirtualBox. Then I entered the following command on my FreeBSD box:

# mount_smbfs -I 192.168.1.82 //guest@my-mbp/freebsd-files /mnt
Code:
smb_co_lock: recursive lock for object 1
mount_smbfs: unable to open connection: syserr = Connection refused

I'm not sure where to go from here. Do I have to install Samba from ports? Is something else going wrong? I also tried with my username and entered the password, but that gave the same error.
 
Re: Connect to OS X file sharing through SMB from Vbox guest

Try again, using just the IP address in both places or leaving out the -I option.
 
Re: Connect to OS X file sharing through SMB from Vbox guest

Sorry, but I'm not sure I understand. I've tried various combinations like
# mount_smbfs 192.168.1.82 //lionoceros@my-mbp/freebsd-files /mnt
# mount_smbfs 192.168.1.82 192.168.1.[freebsd IP address]
etc.

And I just get a usage error.

Also tried this:
# mount_smbfs //192.168.1.82/freebsd-files /mnt
Code:
mount_smbfs: can't get server address: syserr = Operation timed out
 
Re: Connect to OS X file sharing through SMB from Vbox guest

Removing -I means also removing the parameter to it:
Code:
# mount_smbfs //lionoceros@192.168.1.82/freebsd-files /mnt
 
Re: Connect to OS X file sharing through SMB from Vbox guest

wblock@ said:
Removing -I means also removing the parameter to it:
Code:
# mount_smbfs //lionoceros@192.168.1.82/freebsd-files /mnt

Here's the output:
Code:
mount_smbfs: can't get server address: syserr = Operation timed out

I'd also like to thank you for all your help so far, wblock@!
 
Re: Connect to OS X file sharing through SMB from Vbox guest

Maybe there's a way to search for available SMB shares and use that information to connect to it? I've been Googling away trying to find other commands or options. For example this guide http://blog.up-link.ro/freebsd-how-to-m ... r-freebsd/ tells me to enter something like:

# mount_smbfs -I 192.168.1.82 //lionoceros@my-mbp/freebsd-files /mnt

I also tried

# mount_smbfs -I 192.168.1.82 [email=//lionoceros@192.168.1.82]//lionoceros@192.168.1.82[/email]/freebsd-files /mnt

And

# mount_smbfs [email=//lionoceros@192.168.1.82]//lionoceros@192.168.1.82[/email]/freebsd-files /mnt

No luck

EDIT: Currently adding Mac's IP address and hostname to /etc/hosts in FreeBSD
EDIT2: Argh, same problem. Here what I added to my /etc/hosts:

Code:
192.168.1.82        Lions-MacBook-Pro.local

That's is the full hostname that my Mac tells me I have.
 
Re: Connect to OS X file sharing through SMB from Vbox guest

Maybe there's another way to connect to a Mac's shared folders without using Samba. Most of the articles and guides I've found are about using FreeBSD as a server and Mac OS X as a guest, not the other way around. How else could file sharing work between FreeBSD and Mac OS X?
 
Re: Connect to OS X file sharing through SMB from Vbox guest

There's the AFP protocol that is native to OS X and what Apple prefers over other protocols. However, FreeBSD has no AFP client in base. You could try to set up your OS X system to export the directories over NFS and mount them on the VirtualBox guest using the standard mount_nfs(8) utility. Apple seems to have instructions on how to do that (it says OS X server but information seems to apply on the normal version too):

http://support.apple.com/kb/HT4695

There are some obvious problem with this however. The user accounts of your OS X system will not be automatically in sync with the FreeBSD system. For that to work you'd have to set up LDAP in such a way that the FreeBSD system uses the OS X system as the LDAP server for user accounts. I have never done that myself and others who know more might be able to help here.
 
Re: Connect to OS X file sharing through SMB from Vbox guest

Got it working! I used NFS to synchronize a folder between my Mac host and FreeBSD guest. For the benefit of others who want to do the same, here is a guide I wrote:

Folder Sharing Between OS X and FreeBSD on VirtualBox

Objective: Share files between my OS X host and FreeBSD VirtualBox guest. Just for kicks, I wanted to synchronize this folder online, so I added it to my Dropbox as well.

Potential Applications:
  • Backups
  • Transferring config files
  • Quickly sharing files to Dropbox (since Dropbox is not officially supported on FreeBSD)

Note: User @kpa has pointed out that this method should work fine as long as you only have one user account that is common between the OS X host and the FreeBSD client. Having more users would require you to find a way to sync those user accounts, perhaps with LDAP.

Basic information about my setup:
Code:
MacBook Pro 8,2 (Early 2011)
Mac OS 10.9.1 "Mavericks"
VirtualBox 4.3.6
FreeBSD 9.2-RELEASE
OS X username: lion
FreeBSD username: lion
I've provided my sources at the end of this document. They're cited throughout the text with red numbers in brackets like this [source].

First Steps

Folder sharing is currently not supported by the VirtualBox-OSE guest additions, so, with the help of some users here on the forums, I used NFS to get around that limitation. Here's how you can do the same.

First, I created a folder called "BSDfiles" and saved it in my DropBox folder. The path was then /Users/lion/Dropbox/BSDfiles. This is the folder we want to share.

For networking, I used the NAT option for my FreeBSD guest in VirtualBox settings. The reason for this is that the IP for the VirtualBox host is always 10.0.2.2 and the guest is always 10.0.2.15 when they access each other [1], making them easier for me to remember rather than running ifconfig whenever something changes. Also (if I understand this correctly), using NAT instead of Bridged Network will allow me to change Wi-Fi networks without any consequences to the shared folders because all connections remain within the Mac.

Setting up the NFS Server on OS X

On OS X, edit the file /etc/exports and nfsd will start automatically [2]. The file did not already exist on my machine, so I just created it:
# vim /etc/exports
In this file, the syntax is basically:
Code:
<shared folder> <options> <client IP>
For my setup, that translated to the following:
Code:
/Users/lion/Dropbox/BSDfiles -mapall=501:20 -alldirs 127.0.0.1
  • The -mapall=501:20 option means any users in the guest (FreeBSD) that change files in the shared folder will be treated as your normal user on OS X [2]. 501 refers to the UID and 20 refers to the GUID. To find out your user information on OS X, run the id command in your terminal.
  • The -alldirs option allows users in the guest to mount any directory within the shared folder [2]. I added this option just in case I decide to add folders within BSDfiles and mount them directly, so -alldirs might not be necessary.
  • Using 127.0.0.1 instead of the VirtualBox guest IP (10.0.2.15) shares only to the loopback and gives access to all of your VMs with NAT networking [3].

There is one more file to edit on OS X. In /etc/nfs.conf, add the following line:
Code:
nfs.server.mount.require_resv_port = 0
Then let NFS know you've made a change by running
# nfsd update
Otherwise you won't be able to connect. See link [3] below for more information.

Setting up the NFS Client on FreeBSD

FreeBSD is pretty great for this because it's got all you need built in. Here are a few lines to add to your /etc/rc.conf:
Code:
nfs_client_enable="YES"
vboxservice_flags="--disable-timesync"
ntpd_enable="YES"
ntpd_sync_on_start="YES"
  • Code:
    nfs_client_enable="YES"
    will, as you might expect, enable the NFS client [4]
  • The next three lines are there because word on the ArchWiki is that NFS will cause some delays in your system's time [5]. I noticed that my clock was off as soon as I started using NFS, but using NTP fixed it. The
    Code:
    ntpd_sync_on_start="YES"
    line will do exactly that, taking over functionality from ntpdate [6]. Using NTP means you don't need VirtualBox's time syncing feature [7]
  • UPDATE: It turns out this is not the case (anymore?), and the only line you will need to add is
    Code:
    nfs_client_enable="YES"

Then, from your FreeBSD guest, start the nfs_client service with this command [4]:
# service nfsclient restart
I'm not sure why it says restart in the Handbook, so if that doesn't work just try # service nfsclient start.

Decide which folder you'll use as a mount point (/mnt/share in this case), and run the following command to mount your shared folder. Remember to edit the path name for the location of your own shared folder.
# mount 10.0.2.2:/Users/lion/Dropbox/BSDfiles /mnt/share

To see if it worked, put a file (I just used a .txt) in the shared folder from OS X. Then ls from FreeBSD to see if it's there:
# ls /mnt/share
If your text file is there, it worked! Permissions should be alright since we used the option -mapall=501:20 in /etc/exports earlier. Files in your shared folder show up as owned by "staff" in FreeBSD, and editing them will be equivalent to editing them as your normal user on OS X.

Since I like to access my shared folder as a normal user, I logged into my normal user on FreeBSD and made the following symlink for convenience:
% ln -s /mnt/share /usr/home/lion/share

Test it a few times to make sure you can create files from FreeBSD and edit them from OS X and vice versa.

Now, rather than running that long command every time we boot up FreeBSD, we can edit the /etc/fstab file to have our shared folder mount at boot [4]. Add the following line:
Code:
10.0.2.2:/Users/lion/Dropbox/BSDfiles /mnt/share nfs rw 0 0
  • Edit the path name as necessary.

Reboot your FreeBSD guest, and your shared folder should be mounted!

Sources
[1] https://forums.virtualbox.org/viewtopic.php?f=1&t=36592
[2] https://developer.apple.com/library/mac ... rts.5.html
[3] http://www.brianwcook.com/2013/02/servi ... albox.html
[4] http://www.freebsd.org/doc/en_US.ISO885 ... k-nfs.html
[5] https://wiki.archlinux.org/index.php/NFS
[6] viewtopic.php?&t=16295
[7] https://wiki.freebsd.org/VirtualBox

Please let me know if there's anything in this guide that's incorrect or that might cause problems in the future.

Thanks again to the forum users who helped me, the maintainers of FreeBSD documentation, and those who wrote the other articles I cited for providing the information I needed at the right time. I hope my guide helps someone else when they need it!
 
Last edited by a moderator:
That's really neat and the guide you wrote is well written. This will work fine as long as you have only one user account that is common between the OS X machine and the FreeBSD client. If you have more users you'll have to come up with a way to sync those user accounts somehow. Traditionally this was done with NIS, now LDAP as I noted above.
 
I see. I'll add that as a possible caveat to this method. Thanks for letting me know!

Maybe I should submit this guide to Howtos & FAQs as well.
 
Back
Top