V
V
vsbeats2017-03-21 19:25:27
linux
vsbeats, 2017-03-21 19:25:27

How to set up Vagrant shared folders correctly?

I have a host machine: macOS Sierra 10.12.3
I have a vagrant box: debian 8
I'm trying to set up NFS shared folders between them. Rsync is not suitable, because two-way synchronization is needed, vboxfs is also not suitable, since the project is large, there are a lot of files - this file system works, but is catastrophically slow.
NFS mounts and syncs perfectly, and the project itself runs very fast. But the essence of the problem is that the mounted folder is given owner:group - 501:dialout. I understand that nfs is trying to take my user and my group from the host machine (macOS) and set the same user and group for the mounted folder. But - from the guest of the machine I can neither create a file, nor edit, nor delete (even under root). What kind of crutches did not try, the whole Internet rustled, even put a happy tambourine next to the laptop. To no avail.
How can I mount a folder using NFS via vagrant so that I can edit the files in it directly in the virtual machine itself?
Vagrant 1.9.2
VirtualBox 5.1.18

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vsbeats, 2017-03-22
@vsbeats

In general, the solution turned out to be quite banal and simple.
Specify the nfs type in the Vagrantfile.
We also specify the id of the user and group on behalf of which manipulations will take place in the mounted folder.

config.vm.synced_folder "/host/projects/mount-from-folder", "/guest/mount-to-folder", type: "nfs"

# Все действия с файлами в примонтированной папке будут производиться от лица текущего пользователя хост-машины
  config.nfs.map_uid = Process.uid 
  config.nfs.map_gid = Process.gid

 # Можно так же указать цифрами id любого юзера/группы
 # Узнать их можно посмотрев файлы /etc/passwd и /etc/group
  config.nfs.map_uid = 501
  config.nfs.map_gid = 20

Next, be sure to reboot the virtual machine with the --provision key. Nothing worked without him.
In my case, the problem was solved.
I also forgot to mention that the vagrant-vbguest plugin was used.

M
Max, 2017-03-22
@7workers

NFS will slow down anyway, it's better to use virtualbox guest additions + synced_folder (without parameters, i.e. vboxfs). But you can also set both the group and the user_id there:
https://www.vagrantup.com/docs/synced-folders/nfs.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question