使用virtualbox和vagrant克隆VM时,如何保留共享文件夹

时间:2016-08-31 21:37:54

标签: vagrant virtualbox shared-directory

首先,我在Mac上。其次,我有一个虚拟机VM,它是使用vagrant创建的,它使用共享文件夹轻松来回传递文件​​等。

我现在想要从特定状态克隆此VM,以便我可以升级它上面的应用程序并继续前进。问题是我知道在这里使用共享文件夹的唯一方法是使用vagrant up启动框(这是有意义的,因为vagrant将文件夹作为其启动过程的一部分安装);但是,使用vagrant up始终会触发原始VM。

有没有办法使用Virtual Box创建VM的克隆,然后能够使用共享文件夹,这样我就可以通过ssh轻松地将文件复制到主机和来宾之间?

2 个答案:

答案 0 :(得分:0)

进行了一些研究并发现我可以使用原始虚拟机VM以相同的方式在克隆中挂载共享文件夹:

mount -t vboxsf -o rw,uid=33,gid=33 <shared_folder_name> <guest_folder>

请注意,此处指定的uid和gid仅与基于Debian的系统有关。 CentOS ID不同。

有关CentOS盒子的技术和解决方案的更多信息,请参见此处:http://jimmybonney.com/articles/configure_virtualbox_shared_folder_apache_virtual_host/

我已尝试过上述文章中的步骤,以便在VM启动时自动挂载共享文件夹,但我没有成功。作为解决方法(我现在觉得可以接受),我在.bashrc文件中创建了一个别名,似乎工作正常。

答案 1 :(得分:0)

I would now like to clone this VM from a particular state so that I can upgrade an application on it and move forward with it

one thing you can look is vagrant snapshot

Snapshot works with VirtualBox provider to take a snapshot of your VM at the particular point of time when snapshot is taken. You can then continue working on your VM and when needed you can easily recover from a previous snapshot