Share any folder from your host computer on to your FreeBSD guest using the shared folders feature.
- VMWare Workstation or VMWare Fusion.
- FreeBSD as a virtual machine guest.
- VMWare tools installed.
Your FreeBSD guest should have the Open VMWare Tools package installed and running successfully. This will work on both graphical and non-graphical installations. You should select the tools package accordingly.
For the Impatient
This guide is divided into multiple sections. The first few cover some prerequisite and optional configuration. Users who already have a properly configured environment may skip to the part about mounting the shared folder. Just make sure you have the fusefs driver loaded.
- Enable Folder Sharing in VMWare Workstation
- Load the fusefs Kernel module
- Letting non-root users mount filesystems
- Mounting the VMWare shared folder in FreeBSD
Note: Most of the prerequisite configuration will already be done if the FreeBSD MATE desktop installation script was used to setup a graphical desktop environment.
Enable Folder Sharing
The first step is to share at least one folder from your host system to the guest virtual machine. This guide will only cover the steps for VMWare Workstation on Windows. Fusion users will need to refer to the official documentation.
Open the Virtual Machine Settings dialog, then click on the Options tab.
Look for the Shared Folders property in the list and click on it.
Under the Folder Sharing section click the radio button next to Always enabled. This will ensure that the shared folder will always be available each time you boot the virtual machine. If your virtual machine is already running you'll have an additional option available letting you enable the feature temporarily.
Select a folder to share by clicking the Add button.
This brings up the Add Shared Folder Wizard. Click Next to continue.
Type in or browse for the folder you want to share. The name field will be automatically filled using the folder's name. It makes sense to use a simple yet descriptive name, preferably without spaces. The name entered here will be used to reference the share from within your guest OS.
Unless you have a reason to do otherwise, leave the Enable this share box checked. There is also an option to have the shared folder be read-only. Click Finish to continue.
Click OK to close the dialog and save your settings.
If it's not already running, boot up your virtual machine.
Enable fusefs Kernel Module
The fusefs kernel module is required to mount shared folders from within a FreeBSD guest operating system. Any modern supported version of FreeBSD will have it included in the base system, but it may not be enabled by default.
Note: The module will already be enabled if the FreeBSD desktop script was used to setup a graphical environment.
Use the kldstat command to check if the module is loaded.
kldstat -m fusefs
A result that resembles the output below indicates that the module is loaded.
Id Refs Name
46 1 fusefs
If not loaded, you'll receive an error.
kldstat: can't find module fusefs: No such file or directory
To load the module, execute the kldload command followed by the module name as root.
The module can be automatically loaded at boot time by adding it to /boot/loader.conf:
sysrc -f /boot/loader.conf fuse_load="YES"
Let non-root Users Mount Stuff
Mounting is usually restricted to the root user. It is possible to allow non-root users to mount items by setting the vfs.usermount system variable to a non-zero value. This part is optional and can be skipped if you want to restrict the ability to mount filesystems on your system.
Note: If you used the FreeBSD desktop installation script no additional configuration is needed, as this will already be enabled.
Use the sysctl command to change the value of vfs.usermount.
To have this change applied at boot time, add the following to/etc/sysctl.conf. The file won't exist by default, create it if necessary.
Mount Shared Folder
Both emulators/open-vm-tools and emulators/open-vm-tools-nox11 include the mount program vmhgfs-fuse that is used to mount shared folders. It's usage is similar to any other mount program. The main difference is that the share name is used as the device parameter prefixed by ".host:/".
Assuming the /media/Downloads directory already exists, mount the Downloads folder we enabled earlier.
vmhgfs-fuse .host:/Downloads /media/Downloads
For desktop environments that support it, anything mounted under /media automatically shows up on the desktop.
If the share is being mounting as root and you need to grant access to a specific user, pass in the allow_other and uid options.
vmhgfs-fuse -o allow_other -o uid=XXXX .host:/Downloads /media/Downloads
Replace XXXX with the numerical ID of the user you are granting access to. Use the id command to show the ID of a user by it's username.
# id daniel
Use the standard umount program unmount the shared folder before removing it
You may also have the folder mounted automatically at boot time by adding it to your fstab.
Using your favorite editor add this to /etc/fstab
.host:/Downloads /media/Downloads fusefs rw,mountprog=/usr/local/bin/vmhgfs-fuse,allow_other,failok 0 0
When using /etc/fstab be sure to add the allow_other and failok options. The latter is necessary to prevent your system from failing to boot up should the shared folder be unavailable. The allow_other options is to let non-root users access the mount since anything listed in /ets/fstab will always be mounted as the root user.
[source material] The topic at https://forums.freebsd.org/threads/vmware-shared-folders.10318 was used as reference material while writing this post.
[source material] The KB article at https://kb.vmware.com/s/article/60262 was used as reference material while writing this post.