如何导出流浪者虚拟机进行传输

我有一个流浪箱启动和运行(配置了一个 LAMP 堆栈)。我需要把它转移到另一台电脑上。怎么出口? 我想我可以得到一个文件(或文件) ,可以复制到另一台电脑,所以在那里我可以运行一些命令,以导入流浪箱。

114367 次浏览

You have two ways to do this, I'll call it 肮脏的方式 and 干净利落:

1. 肮脏方式

使用 vagrant package命令从当前虚拟环境创建一个框:

Http://docs.vagrantup.com/v2/cli/package.html

然后将该框复制到另一台电脑上,使用 vagrant box add添加它,并像往常一样使用 vagrant up运行它。

Keep in mind that files in your working directory (the one with the Vagrantfile) are shared when the virtual machine boots, so you need to copy it to the other pc as well.

2. 干净方式

从理论上讲,永远不应该有必要与流浪汉做出口/进口。如果您有先见之明,可以使用供应来配置虚拟环境(主厨、木偶、可视化) ,以及像 git 这样的版本控制系统来配置工作目录,那么此时复制环境就很简单,只需要运行:

git clone <your_repo>
vagrant up

正如

我怎样才能改变流浪汉寻找它的虚拟硬盘驱动器的位置?

虚拟机状态存储在预定义的 VirtualBox 文件夹中。将您的流浪项目之外的相应机器(文件夹)复制到另一个主机应该会保留您的虚拟机状态。

最简单的方法是打包流浪汉盒子,然后复制(例如 scprsync)到另一台 PC 上,添加它和 vagrant up; -)

有关详细步骤,请参阅 => 有没有办法克隆一个已经安装好的流浪汉盒子

我 Mac 里的硬盘在项目进行到一半的时候会发出哔哔的声音,所以我决定安装一个 SSD。我需要将我的项目从一个磁盘转移到另一个磁盘。需要考虑以下几点:

  • 我是 Mac 上的流浪者
  • 我在用 Git

这就是对我有效的方法:

1.) Copy your ~/.vagrant.d directory to your new machine.
2.) Copy your ~/VirtualBox\ VMs directory to your new machine.
3.) In VirtualBox add the machines one by one using **Machine** >> **Add**
4.) Run `vagrant box list` to see if vagrant acknowledges your machines.
5.) `git clone my_project`
6.) `vagrant up`

我在添加 VB 客户端时遇到了一些问题。

enter image description here

我修好了 with this solution

其实很简单

  1. 在远程计算机上安装 虚拟盒子流浪汉
  2. 收拾好你的流浪汉机器

    vagrant package --base [machine name as it shows in virtual box] --output /Users/myuser/Documents/Workspace/my.box

  3. 把盒子复制到你的遥控器上

  4. 在远程计算机上通过运行

    vagrant init [machine name as it shows in virtual box] /Users/myuser/Documents/Workspace/my.box

  5. 运行 vagrant up

以上的答案对我来说都不管用。我已经花了2天的时间来研究如何将一台 Vagrant + VirtualBox 机器从一台计算机迁移到另一台计算机... ... 这是可能的!

首先,您需要了解虚拟机与您的同步/共享文件夹是分开的。所以当你打包你的机器时,你没有打包你的文件,而是打包了数据库。

你需要做的:

1-打开计算机1主机的 CMD (命令行。打开它作为管理员与右键-> “运行作为管理员”) ,并进入您的流浪者安装的文件。在我的情况下: C:/VVV 你会看到你的流浪汉档案,还有这些文件夹:

/config/
/database/
/log/
/provision/
/www/
Vagrantfile
...

在/www/文件夹中有我的同步文件夹和我的开发域。你可能有你的同步文件夹在其他地方,只是一定要了解你在做什么。还有/config 和/database 是同步文件夹。

2-运行这个命令: vagrant package --vagrantfile Vagrantfile

(此命令使用 Vagranfile 配置执行虚拟机的包。)

以下是关于该命令的流浪者文档:

一个常见的错误观念是—— vasrantfile 选项将包含一个 流浪者文件,用于当流浪者初始化时与此框一起使用 实际情况并非如此。相反,Vagrantfile 是作为 当使用该框时,流浪者加载进程, 阅读有关流浪者文件加载顺序。

https://www.vagrantup.com/docs/cli/package.html

完成后,您将得到一个 package.box 文件。

3-复制所有这些文件 (/config,/database,Vagrantfile,package.box 等)并将它们粘贴到计算机2上您想要安装虚拟机的位置(在我的例子 D:/VVV)。

现在您的计算机2主机上有了所需的所有内容的副本。

4-运行 this: vagrant box add package.box --name VVV

(The --name is used to name your virtual machine. On my case it's named VVV) (如果您已经有一个具有此名称的虚拟机,并且希望覆盖它,则可以使用—— force。(小心使用!)

这将解包您的新流浪虚拟机。

完成后,运行: vagrant up

The machine will install and you should see it on the "Oracle virtual machine box manager". If you cannot see the virtual machine, try running the Oracle VM box as administrator (right click -> Run as administrator)

你现在可能一切正常,但是记住要看看你的主机是否如你所期望的那样:

c:/windows/system32/hosts

也许把你的主机文件 从你的计算机1复制到你的计算机2是个好主意。或者抄你需要的台词。 In my case these are the hosts I need:

192.168.50.4 test.dev
192.168.50.4 vvv.dev
...

Where the 192.168.50.4 is the IP of my Virtual machine and test.dev and vvv.dev are developing hosts.

I hope this can help you :) I'll be happy if you feedback your go.

我的案子有一些特别之处:

当我运行流浪者时,mysql 出现了一个问题,它不工作。我必须在 Virtual 服务器上运行(右键单击 Oracle 虚拟机-> Show 控制台) : apt-get install mysql-server

After this, I ran again vagrant up and everything was working but without data on the databases. So I did a mysqldump all-tables from the Computer 1 and upload them to Computer 2.

其他注释: 我的虚拟机不在计算机1和计算机2上。例如,前段时间我进行了使用 NFS 的内部配置(以加速服务器同步文件夹) ,并且需要在 Computer2主机上再次运行这个命令: vagrant plugin install vagrant-winnfsd

As of 2019 there is a subcommand: vagrant box repackage

vagrant box repackage --help
Usage: vagrant box repackage <name> <provider> <version>
-h, --help                       Print this help

通过运行 vagrant box list可以找到 name providerversion

vagrant box list
macinbox (virtualbox, 10.14.5)

vagrant box repackage的输出是一个名为 package.box的文件,它基本上是一个 tgz 文件,其内容可以列出如下:

tar tzf package.box
./metadata.json
./box.ovf
./Vagrantfile
./box-disk001.vmdk

我还必须将 private _ key 文件从. vasrant/ines/default/Virtual box 文件夹中复制出来,以便流浪 ssh 能够工作