uaohzg
42.41K
· March 2013 ·
D83b63db79b42978fe35e120550ca180

Use NFS to speed up your Vagrant

If you are using Vagrant and facing performance hits while running web-server or unit tests, the solution can be using NFS. It is used for sharing folders between host and guest machines.

Vagrant uses VirtualBox default sharing mechanism, which is very slow. After you'll switch to NFS, file access speed will increase by ~ 10 - 100 times.

Installation

  • On your local machine do $ sudo apt-get install nfs-kernel-server nfs-common portmap. This comes pre-installed on Mac OS X 10.5+ (Leopard and higher).
  • Inside your Vagrant box (guest machine) do $ sudo apt-get install nfs-common portmap

Configuration

Set :nfs option to true when configuring shared folder(s).

config.vm.synced_folder "v-root", "/vagrant", :nfs => true

NFS requires Private network, so you need to switch to it, in case you are using other network options, like :public_network (i.e. bridged).

config.vm.network :private_network, ip: "10.11.12.13"

Benchmarks

Grabbed from here.

VirtualBox Shared Folders:         5m 14s
Host File System:                     10s
Native VM File System:                13s
NFS Shared Folders:                   22s
NFS Shared Folders (warm cache):      14s
Sign in or sign up to add your response.

19 Responses

7874
Fdeabaecd044c39cb7d75b104b0aff7c

Quite a pity, what Windows 7 doesn't support NFS. Native Virtualbox method of folder sharing is not performant at all.

over 1 year ago ·
8195

Nice tip, thanks, if you use OS X, don't forget to upgrade your vagrant to the latest version (<= 1.2.4 has some bugs with mounting NFS shared folders).

over 1 year ago ·
8207
2c28c25c8a4a035bdda63057d99ff188

You can use freeNFS on win 7: http://freenfs.sourceforge.net

over 1 year ago ·
8216
D83b63db79b42978fe35e120550ca180

@luuf didn't know that. Thanks for mentioning it here!)

over 1 year ago ·
8236
Cbf3a11b96bf337f0a20f6c22dddd085

Just a note about using NFS with Vagrant, since I had great difficulty getting it to work with the correct permissions.

It seems that NFS mounts your shared directory from the host (desktop) on the vagrant VM using the SAME UID/GID found on the host. This means if your UID/GID on the desktop machine is, for example, 500/500, then the NFS share will be mounted on your Vagrant machine with the same UID/GID, which may not correspond to your vagrant user. In my case, my Vagrant user had a UID/GID of 501/501, since another user was already assigned the UID/GID of 500/500. This caused permission problems since the Vagrant user didn't have access to modify the files in the NFS share.

The easiest way to fix this is to reboot the Vagrant virtual machine into single user mode using the Oracle Virtualbox GUI application (enter the Grub boot menu when starting tup the VM, then append a space and the number 1 to the boot parameters), then modify the UID/GID of the vagrant user to match that of your desktop machine.

over 1 year ago ·
8245
Pierrequadrat

@adamcohen If you have different uid/gids between host and client, try this config parameters in your vagrant file. No need to change ids in your vm:

config.nfs.map_uid = Process.uid

config.nfs.map_gid = Process.gid

over 1 year ago ·
9185
Default profile 2 normal

@luuf I've tried to use Vagrant with FreeNFS on Windows, but I can't make it work. On the Vagrant side everything seems to be configured properly, as I've tested it on OSX and NFS works there. On the FreeNFS side there is really not much configuration - you only provide path of a folder to mount and nothing more - so I don't know where I could make a mistake.

Have you managed to succesfully use Vagrant / FreeNFS combo on Windows? If so, please share how to configure it properly. Thanks!

over 1 year ago ·
10134
55c20cf75c7199b6e652014dd5e9d361

I'm curious on two things, first being like @velesin & @luuf not there is FreeNFS on Windows, but does anyone know if it is stable and worked a lot with it? Also, any easy way to test to see if NFS is there to use? Cheers

over 1 year ago ·
10202
2c28c25c8a4a035bdda63057d99ff188

@velesin I only selected a folder to share under the "server" tab on the freenfs app. Works like it should here.

I also have host-only networking (private network) enabled, and use nfs over that network. On Windows I changed the firewall settings to allow any traffic on that network. Vagrant usually handles the network setup, but check that you can ping between host and client. I am unable to test now, as I moved over to LinuxMint and only run virtual Windows.

over 1 year ago ·
10204
2c28c25c8a4a035bdda63057d99ff188

@jeremybass It is stable enough for testing/development, but I would not use it in production. I used it a lot before moving on to LinuxMint.

over 1 year ago ·
10905
D3ab62d0228c6cdcd59d8aa652415898

Thanks! Useful tip!

over 1 year ago ·
11024
0 8geykyddvtg9rqc h52tko7gz rsjlc giy3k0aobnxe6tht2xstoxsrn0k5sg9ot3e8xzkqy4m1

I'm having troubles with running NFS shared directories. The error message is:
"mount.nfs: access denied by server while mounting 192.168.7.1:/home/user/work/my-project"

192.168.7.1 is host machine inside the private network
192.168.7.50 is guest machine inside the private network

Some more specifics on pastebin: http://pastebin.com/Yt5Aj0hE
Host is running Ubuntu 13.10 with Vagrant 1.3.5 and Virtualbox 4.2.16. Any suggestions what I may try next?

over 1 year ago ·
11403
171947dc0336a524dec37bf9ce7335a7

This is also perfect because I had a "need for speed".

over 1 year ago ·
12387
0 zdfer avxx7p5uu3besrr3jnk3rlbdj3carcr3youxf8zsotmf0kvtoxe7u7xapdqodnqqhv5rag

by the way, for those of you new at this (like me)
config.vm.synced_folder "v-root", "/vagrant", :nfs => true
can be found in your Vagrant file

over 1 year ago ·
14111
0 zvjru ruiifa8os8vu7eu3n4d3za82r8crdku31k9xuhxe2hmpdcztbef74fiivuqj0lnqtlpath

@fire thank you, its a pity I had too read the whole post to find your answer...

over 1 year ago ·
15357
Ddba1b9ebef79f1bbfd4d5a4835f93b0

@szoper I had this problem and solved by adding the guesy IP to the host machines /etc/hosts file

over 1 year ago ·
17015
Cbf3a11b96bf337f0a20f6c22dddd085

@elbcoast wow, that's so much easier than my solution! Thanks for the tip!

over 1 year ago ·
18872
4bcecfcba5fbc6c281564f9b62903acd

@markblackmore please elaborate

over 1 year ago ·
21665
None

thx

10 months ago ·
Featured Programming Job

Solutions Architect, Enterprise Informatics
·
Boston, New York, or Portland, OR
·
Full Time
Search all programming jobs