如何将 Vagrant 项目目录与现有的 VirtualBox VM 相关联? [英] How do I associate a Vagrant project directory with an existing VirtualBox VM?

查看:18
本文介绍了如何将 Vagrant 项目目录与现有的 VirtualBox VM 相关联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知何故,我的 Vagrant 项目已经与其 VirtualBox VM 分离,因此当我 vagrant up Vagrant 将导入基础框并创建一个新的虚拟机.

有没有办法将 Vagrant 项目与现有 VM 重新关联?Vagrant 如何在内部将 Vagrantfile 与 VirtualBox VM 目录关联起来?

解决方案

警告:以下解决方案适用于 Vagrant 1.0.x 但不适用于 Vagrant 1.1+.

Vagrant 使用与Vagrantfile"相同目录中的.vagrant"文件来跟踪 VM 的 UUID.如果 VM 不存在,则此文件将不存在.该文件的格式为 JSON.如果存在单个 VM,则如下所示:

<代码>{积极的":{默认":02f8b71c-75c6-4f33-a161-0f46a0665ab6"}}

default 是默认虚拟机的名称(如果您不使用多 VM 设置).

如果您的 VM 以某种方式解除关联,您可以做的是 VBoxManage list vms 这将列出 VirtualBox 通过其名称和 UUID 知道的每个 VM.然后在你的Vagrantfile所在的目录下手动创建一个.vagrant文件并正确填写内容.

运行 vagrant status 以确保 Vagrant 选择正确的更改.

注意: Vagrant 并未正式支持此功能,Vagrant 可能会随时更改 .vagrant 的格式.但这从 Vagrant 0.9.7 开始有效,并将对 Vagrant 1.0 有效.

Somehow my Vagrant project has disassociated itself from its VirtualBox VM, so that when I vagrant up Vagrant will import the base-box and create a new virtual machine.

Is there a way to re-associate the Vagrant project with the existing VM? How does Vagrant internally associate a Vagrantfile with a VirtualBox VM directory?

解决方案

WARNING: The solution below works for Vagrant 1.0.x but not Vagrant 1.1+.

Vagrant uses the ".vagrant" file in the same directory as your "Vagrantfile" to track the UUID of your VM. This file will not exist if a VM does not exist. The format of the file is JSON. It looks like this if a single VM exists:

{
   "active":{
      "default":"02f8b71c-75c6-4f33-a161-0f46a0665ab6"
   }
}

default is the name of the default virtual machine (if you're not using multi-VM setups).

If your VM has somehow become disassociated, what you can do is do VBoxManage list vms which will list every VM that VirtualBox knows about by its name and UUID. Then manually create a .vagrant file in the same directory as your Vagrantfile and fill in the contents properly.

Run vagrant status to ensure that Vagrant picked up the proper changes.

Note: This is not officially supported by Vagrant and Vagrant may change the format of .vagrant at any time. But this is valid as of Vagrant 0.9.7 and will be valid for Vagrant 1.0.

这篇关于如何将 Vagrant 项目目录与现有的 VirtualBox VM 相关联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆