Search code examples
vagrantvirtualboxshared-directory

How can I retain shared folders when cloning VMs using virtualbox and vagrant


First, I am on a Mac. Second, I have a virtualbox VM which was created using vagrant and which uses a shared folder to easily pass files back and forth, etc.

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. The issue is that the only way I know of to use shared folders here is to start the box using vagrant up (this makes sense as vagrant mounts the folders as part of its boot process); however, using vagrant up always triggers the original VM.

Is there a way to create a clone of a VM using Virtual Box and then to be able to use shared folders so I can easily copy files to and from the host and guest via ssh?


Solution

  • Did some more researching and found that I can mount a shared folder in a clone in the same way I can with the original virtualbox VM using:

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

    Note that the uid and gid specified here relate only to Debian-based systems. CentOS IDs are different.

    For more on the technique and for solutions for CentOS boxes, see here: http://jimmybonney.com/articles/configure_virtualbox_shared_folder_apache_virtual_host/

    I've tried the steps in the above article to allow for auto mounting the shared folder when the VM boots, but I've had no success. As a work-around (which I find acceptable for now), I created an alias in my .bashrc file which seems to work fine.