Search code examples
linuxpermissionsvagrantchef-infra

How to mount a directory for a user that doesn't exist yet in vagrant


I'm trying to mount a data disk in vagrant using the shared folder mechanism, which works well except that the directory is owned by vagrant by default and tomcat6 can't write to it. So I thought I could set the owner of the disk in the vagrantfile using:

config.vm.synced_folder "data/", "/data", owner: "tomcat6", group: "tomcat6"

but the tomcat6 user doesn't exist yet as the tomcat recipe hasn't been run yet so vagrant fails with:

Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

mount -t vboxsf -o uid=`id -u tomcat6`,gid=`getent group tomcat6 | cut -d: -f3` data /data
mount -t vboxsf -o uid=`id -u tomcat6`,gid=`id -g tomcat6` data /data

The error output from the last command was:

stdin: is not a tty
id: tomcat6: no such user
id: tomcat6: no such user
uid= requires an argument (i.e. uid==<arg>)

Now I can work round this by mounting /data with world write permission but that seems "wrong" to me (even on a test machine).

So is there any way to make vagrant create a new user for me before I mount the disk or to have Chef provision me a shared disk later?


Solution

  • You could switch to the nfs sync provider as that supports remote files with unknown UIDs. See https://docs.vagrantup.com/v2/synced-folders/nfs.html for details.