2013-09-03 18:08:28 +00:00
---
2016-01-19 18:08:53 +00:00
layout: "docs"
2013-09-06 16:50:43 +00:00
page_title: "NFS - Synced Folders"
2013-09-03 18:08:28 +00:00
sidebar_current: "syncedfolder-nfs"
2016-01-19 18:08:53 +00:00
description: |-
2016-01-19 19:54:13 +00:00
In some cases the default shared folder implementations such as VirtualBox
shared folders have high performance penalties. If you are seeing less than
ideal performance with synced folders, NFS can offer a solution. Vagrant has
built-in support to orchestrate the configuration of the NFS server on the host
and guest for you.
2013-09-03 18:08:28 +00:00
---
# NFS
In some cases the default shared folder implementations (such as VirtualBox
2016-01-19 18:08:53 +00:00
shared folders) have high performance penalties. If you are seeing less
than ideal performance with synced folders, [NFS ](https://en.wikipedia.org/wiki/Network_File_System_%28protocol%29 )
2013-09-03 18:08:28 +00:00
can offer a solution. Vagrant has built-in support to orchestrate the
configuration of the NFS server on the host and guest for you.
< div class = "alert alert-info" >
2016-01-19 19:54:13 +00:00
< strong > Windows users:< / strong > NFS folders do not work on Windows
hosts. Vagrant will ignore your request for NFS synced folders on
Windows.
2013-09-03 18:08:28 +00:00
< / div >
## Prerequisites
Before using synced folders backed by NFS, the host machine must have
`nfsd` installed, the NFS server daemon. This comes pre-installed on Mac
OS X, and is typically a simple package install on Linux.
Additionally, the guest machine must have NFS support installed. This is
also usually a simple package installation away.
2016-01-19 18:08:53 +00:00
If you are using the VirtualBox provider, you will also need to make sure you
2013-11-23 22:07:46 +00:00
have a
2016-01-19 18:08:53 +00:00
[private network set up ](/docs/networking/private_network.html ). This is due to a limitation of VirtualBox's built-in networking. With
2013-11-23 22:07:46 +00:00
VMware, you do not need this.
2013-09-03 18:08:28 +00:00
## Enabling NFS Synced Folders
2013-11-23 21:43:48 +00:00
To enable NFS, just add the `type: "nfs"` flag onto your synced folder:
2013-09-03 18:08:28 +00:00
```ruby
Vagrant.configure("2") do |config|
# ...
2013-11-23 21:43:48 +00:00
config.vm.synced_folder ".", "/vagrant", type: "nfs"
2013-09-03 18:08:28 +00:00
end
```
If you add this to an existing Vagrantfile that has a running guest machine,
be sure to `vagrant reload` to see your changes.
2013-11-23 21:43:48 +00:00
## NFS Synced Folder Options
NFS synced folders have a set of options that can be specified that are
unique to NFS. These are listed below. These options can be specified in
the final part of the `config.vm.synced_folder` definition, along with the
`type` option.
2016-01-19 18:08:53 +00:00
* `nfs_export` (boolean) - If this is false, then Vagrant will not modify
2014-05-09 00:10:38 +00:00
your `/etc/exports` automatically and assumes you've done so already.
2013-11-23 21:43:48 +00:00
* `nfs_udp` (boolean) - Whether or not to use UDP as the transport. UDP
is faster but has some limitations (see the NFS documentation for more
details). This defaults to true.
* `nfs_version` (string | integer) - The NFS protocol version to use when
mounting the folder on the guest. This defaults to 3.
2014-05-06 15:47:11 +00:00
2015-07-09 16:39:33 +00:00
## NFS Global Options
There are also more global NFS options you can set with `config.nfs` in
the Vagrantfile. These are documented below:
2016-01-19 18:08:53 +00:00
* `functional` (bool) - Defaults to true. If false, then NFS will not be used
2015-07-09 16:39:33 +00:00
as a synced folder type. If a synced folder specifically requests NFS,
it will error.
* `map_uid` and `map_gid` (int) - The UID/GID, respectively, to map all
read/write requests too. This will not affect the owner/group within the
guest machine itself, but any writes will behave as if they were written
as this UID/GID on the host. This defaults to the current user running
Vagrant.
* `verify_installed` (bool) - Defaults to true. If this is false, then
Vagrant will skip checking if NFS is installed.
2015-04-21 14:11:18 +00:00
## Specifying NFS Arguments
In addition to the options specified above, it is possible for Vagrant to
2015-07-09 15:51:46 +00:00
specify alternate NFS arguments when mounting the NFS share by using the
`mount_options` key. For example, to use the `actimeo=2` client mount option:
2015-04-21 14:11:18 +00:00
```
config.vm.synced_folder ".", "/vagrant",
:nfs => true,
:mount_options => ['actimeo=2']
```
This would result in the following `mount` command being executed on the guest:
2015-07-07 05:19:18 +00:00
2015-04-21 14:11:18 +00:00
```
mount -o 'actimeo=2' 172.28.128.1:'/path/to/vagrantfile' /vagrant
```
You can also tweak the arguments specified in the `/etc/exports` template
when the mount is added, by using the OS-specific `linux__nfs_options` or
`bsd__nfs_options` keys. Note that these options completely override the default
arguments that are added by Vagrant automatically. For example, to make the
NFS share asynchronous:
```
config.vm.synced_folder ".", "/vagrant",
:nfs => true,
:linux__nfs_options => ['rw','no_subtree_check','all_squash','async']
```
This would result in the following content in `/etc/exports` on the host (note
the added `async` flag):
```
# VAGRANT-BEGIN: 21171 5b8f0135-9e73-4166-9bfd-ac43d5f14261
"/path/to/vagrantfile" 172.28.128.5(rw,no_subtree_check,all_squash,async,anonuid=21171,anongid=660,fsid=3382034405)
# VAGRANT-END: 21171 5b8f0135-9e73-4166-9bfd-ac43d5f14261
```
2014-05-06 15:47:11 +00:00
## Root Privilege Requirement
To configure NFS, Vagrant must modify system files on the host. Therefore,
at some point during the `vagrant up` sequence, you may be prompted for
administrative privileges (via the typical `sudo` program). These
privileges are used to modify `/etc/exports` as well as to start and
stop the NFS server daemon.
2016-01-19 18:08:53 +00:00
If you do not want to type your password on every `vagrant up` , Vagrant
2014-05-06 15:47:11 +00:00
uses thoughtfully crafted commands to make fine-grained sudoers modifications
possible to avoid entering your password.
Below, we have a couple example sudoers entries. Note that you may
have to modify them _slightly_ on certain hosts because the way Vagrant
2016-05-29 05:13:13 +00:00
modifies `/etc/exports` changes a bit from OS to OS. If the commands below
are located in non-standard paths, modify them as appropriate.
2014-05-06 15:47:11 +00:00
2016-01-14 21:14:39 +00:00
For \*nix users, make sure to edit your `/etc/sudoers` file with `visudo` . It protects you against syntax errors which could leave you without the ability to gain elevated privileges.
2016-01-14 21:09:43 +00:00
2015-07-13 15:42:35 +00:00
All of the snippets below require Vagrant version 1.7.3 or higher.
2014-05-06 15:47:11 +00:00
For OS X, sudoers should have this entry:
```
Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
Cmnd_Alias VAGRANT_NFSD = /sbin/nfsd restart
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /usr/bin/sed -E -e /*/ d -ibak /etc/exports
%admin ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD, VAGRANT_EXPORTS_REMOVE
```
2014-12-10 11:19:09 +00:00
For Ubuntu Linux , sudoers should look like this:
2014-05-06 15:47:11 +00:00
```
2015-12-29 07:44:56 +00:00
Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
2015-11-24 01:37:47 +00:00
Cmnd_Alias VAGRANT_EXPORTS_COPY = /bin/cp /tmp/exports /etc/exports
2014-05-06 15:47:11 +00:00
Cmnd_Alias VAGRANT_NFSD_CHECK = /etc/init.d/nfs-kernel-server status
Cmnd_Alias VAGRANT_NFSD_START = /etc/init.d/nfs-kernel-server start
Cmnd_Alias VAGRANT_NFSD_APPLY = /usr/sbin/exportfs -ar
2015-11-24 01:37:47 +00:00
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /bin/sed -r -e * d -ibak /tmp/exports
%sudo ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD_CHECK, VAGRANT_NFSD_START, VAGRANT_NFSD_APPLY, VAGRANT_EXPORTS_REMOVE, VAGRANT_EXPORTS_COPY
2014-05-06 15:47:11 +00:00
```
2014-12-10 11:19:09 +00:00
For Fedora Linux, sudoers might look like this (given your user
belongs to the vagrant group):
```
Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
Cmnd_Alias VAGRANT_NFSD_CHECK = /usr/bin/systemctl status nfs-server.service
Cmnd_Alias VAGRANT_NFSD_START = /usr/bin/systemctl start nfs-server.service
Cmnd_Alias VAGRANT_NFSD_APPLY = /usr/sbin/exportfs -ar
2016-01-29 18:20:24 +00:00
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /bin/sed -r -e * d -ibak /tmp/exports
2014-12-10 11:19:09 +00:00
%vagrant ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD_CHECK, VAGRANT_NFSD_START, VAGRANT_NFSD_APPLY, VAGRANT_EXPORTS_REMOVE
```
2015-07-07 05:19:18 +00:00
## Other Notes
**Encrypted folders:** If you have an encrypted disk, then NFS very often
will refuse to export the filesystem. The error message given by NFS is
often not clear. One error message seen is `<path> does not support NFS` .
2016-01-19 18:08:53 +00:00
There is no workaround for this other than sharing a directory which is not
2015-07-07 05:19:18 +00:00
encrypted.