如何为一个尚未存在的用户安装一个目录

我试图使用共享文件夹机制来安装一个数据磁盘,除了该目录默认为vagrant并且tomcat6不能写入它之外,这个工作很好。 所以我想我可以使用以下命令将磁盘的所有者设置在vagrantfile中:

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

tomcat6用户不存在,因为tomcat配方还没有运行,所以stream浪者失败:

 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 (ie uid==<arg>) 

现在我可以通过挂载/具有世界写入权限的数据来处理这个问题,但对我来说(即使在testing机器上)似乎是“错误的”。

那么有没有什么办法可以让我们在安装磁盘之前为我创build一个新用户,或者让Chef在以后为我提供一个共享磁盘?

您可以切换到nfs同步提供程序,因为它支持具有未知UID的远程文件。 有关详细信息,请参阅https://docs.vagrantup.com/v2/synced-folders/nfs.html

在安装共享文件夹时,您可以保持所有者无法访问,并在顶部添加一个使用chown更改所有权的简短shell配置器。 或者,tomcat的配方可以注意设置正确的所有权本身。