我使用以下内容创建了一个Vagrantfile:
Vagrant::Config.run do |config|
config.vm.define :foo do |cfg|
cfg.vm.box = 'foo'
cfg.vm.host_name = "foo.localdomain.local"
cfg.vm.network :hostonly, "192.168.123.10"
end
Vagrant.configure("2") do |cfg|
cfg.vm.customize [ "modifyvm", :id , "--name", "foo" , "--memory", "2048", "--cpus", "1"]
cfg.vm.synced_folder "/tmp/", "/tmp/src/"
end
end
我vagrant up
或vagrant reload
后:
[foo] Attempting graceful shutdown of VM...
[foo] Setting the name of the VM...
[foo] Clearing any previously set forwarded ports...
[foo] Fixed port collision for 22 => 2222. Now on port 2200.
[foo] Creating shared folders metadata...
[foo] Clearing any previously set network interfaces...
[foo] Preparing network interfaces based on configuration...
[foo] Forwarding ports...
[foo] -- 22 => 2200 (adapter 1)
[foo] Booting VM...
[foo] Waiting for VM to boot. This can take a few minutes.
[foo] VM booted and ready for use!
[foo] Setting hostname...
[foo] Configuring and enabling network interfaces...
[foo] Mounting shared folders...
[foo] -- /vagrant
我的问题是:
/vagrant
共享文件夹?我读了共享文件夹,不赞成使用同步文件夹,我从未在Vagrantfile中定义任何共享文件夹。我在MacOX 10.8.4上使用Vagrant版本1.2.7。
答案 0 :(得分:95)
基本上共享文件夹被重命名为从v1到v2(docs)的同步文件夹,在bonnet下它仍然在主机和guest虚拟机之间使用vboxsf
(如果有大量文件/目录,则存在已知的性能问题)。
/vagrant
Vagrant正在将当前工作目录(Vagrantfile
所在的位置)挂载到guest虚拟机中/vagrant
,这是默认行为。
请参阅docs
注意:默认情况下,Vagrant会将您的项目目录(包含Vagrantfile的目录)共享给/ vagrant。
您可以在cfg.vm.synced_folder ".", "/vagrant", disabled: true
中添加Vagrantfile
来停用此行为。
基于主机上的输出/tmp
未在正常运行时安装。
使用VAGRANT_INFO=debug vagrant up
或VAGRANT_INFO=debug vagrant reload
启动VM以获取有关未安装同步文件夹的原因的更多输出。可能是权限问题(主机上/tmp
的模式位应为drwxrwxrwt
)。
我使用以下方法进行了测试快速测试并且有效(我使用了opscode bento raring vagrant base box)
config.vm.synced_folder "/tmp", "/tmp/src"
输出
$ vagrant reload
[default] Attempting graceful shutdown of VM...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Available bridged network interfaces:
1) eth0
2) vmnet8
3) lxcbr0
4) vmnet1
What interface should the network bridge to? 1
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Running 'pre-boot' VM customizations...
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Configuring and enabling network interfaces...
[default] Mounting shared folders...
[default] -- /vagrant
[default] -- /tmp/src
在VM中,您可以看到装载信息/tmp/src on /tmp/src type vboxsf (uid=900,gid=900,rw)
。